[PATCH v7 5/8] mm/util: Fix possible race condition in kstrdup()
Linus Torvalds
torvalds at linux-foundation.org
Sat Aug 17 16:26:21 UTC 2024
On Sat, 17 Aug 2024 at 01:48, Alejandro Colomar <alx at kernel.org> 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
More information about the Linux-security-module-archive
mailing list