Thread (27 messages) 27 messages, 6 authors, 2024-09-29

Re: [PATCH v7 5/8] mm/util: Fix possible race condition in kstrdup()

From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2024-08-17 16:26:42
Also in: bpf, dri-devel, linux-fsdevel, linux-mm, linux-security-module, netdev, selinux

On Sat, 17 Aug 2024 at 01:48, Alejandro Colomar [off-list ref] wrote:
I would compact the above to:

        len = strlen(s);
        buf = kmalloc_track_caller(len + 1, gfp);
        if (buf)
                strcpy(mempcpy(buf, s, len), "");
No, we're not doing this kind of horror.

If _FORTIFY_SOURCE has problems with a simple "memcpy and add NUL",
then _FORTIFY_SOURCE needs to be fixed.

We don't replace a "buf[len] = 0" with strcpy(,""). Yes, compilers may
simplify it, but dammit, it's an unreadable incomprehensible mess to
humans, and humans still matter a LOT more.

                Linus
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help