[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1786903963.99788.1754916389068.JavaMail.zimbra@nod.at>
Date: Mon, 11 Aug 2025 14:46:29 +0200 (CEST)
From: Richard Weinberger <richard@....at>
To: Miguel García <miguelgarciaroman8@...il.com>
Cc: Miquel Raynal <miquel.raynal@...tlin.com>,
Vignesh Raghavendra <vigneshr@...com>,
chengzhihao1 <chengzhihao1@...wei.com>,
linux-mtd <linux-mtd@...ts.infradead.org>,
linux-kernel <linux-kernel@...r.kernel.org>,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] mtd: ubi: replace strcpy with strscpy in mtd parameter
parser
----- Ursprüngliche Mail -----
> Von: "Miguel García" <miguelgarciaroman8@...il.com>
> An: "richard" <richard@....at>, "Miquel Raynal" <miquel.raynal@...tlin.com>, "Vignesh Raghavendra" <vigneshr@...com>
> CC: "chengzhihao1" <chengzhihao1@...wei.com>, "linux-mtd" <linux-mtd@...ts.infradead.org>, "linux-kernel"
> <linux-kernel@...r.kernel.org>, "Shuah Khan" <skhan@...uxfoundation.org>, "Miguel García"
> <miguelgarciaroman8@...il.com>
> Gesendet: Montag, 11. August 2025 14:09:12
> Betreff: [PATCH] mtd: ubi: replace strcpy with strscpy in mtd parameter parser
> Replace the strcpy() calls used to copy the 'mtd=' parameter into local
> buffers with strscpy() to avoid potential overflow and guarantee NUL
> termination. Destinations are fixed-size arrays (buf and p->name), so
> use sizeof().
>
> While this code is currently safe due to prior length checks
> (strnlen(val, MTD_PARAM_LEN_MAX) and early return on overflow),
> replacing strcpy() with strscpy() follows current kernel best practices
> and makes the code more robust to future changes. The sizeof() calls
> correctly compute the buffer sizes, matching MTD_PARAM_LEN_MAX.
TBH, I'm not convinced. We're talking about kernel module parameters,
not hostile user input, etc...
By adding sizeof() you're replacing one foodgun with another one.
If buf is in future changed to a pointer, sizeof(buf) needs a fixup too.
Thanks,
//richard
Powered by blists - more mailing lists