RE: [PATCH] kobject: Replace strlcpy with strscpy
From: David Laight
Date: Thu Jul 13 2023 - 04:38:28 EST
From: Kees Cook <keescook@xxxxxxxxxxxx>
> Sent: 13 July 2023 00:53
....
> > > pr_warn("init_uevent_argv: buffer size of %d too small for %s, needed
> > > %d\n", buffer_size, subsystem, strlen(subsystem));
> > >
> > > Does that seem better?
>
> Yeah, that'll retain the intention of the warning. It shouldn't really
> even be possible to hit that warning, so I don't think we need to worry
> about the "extra" call to strlen().
>
> > Not with the justification for not using strlcpy() :-)
>
> What?
The commit message says that strlcpy() isn't used because
of possible 'read beyond buffer end' (etc) if it isn't
'\0' terminated.
But here if (extremely unlikely) the source isn't terminated
then the extra reads get done anyway.
So the commit message just doesn't match the change.
I'd guess that it is possible for there to be insufficient space.
Probably because other strings have filled the buffer.
The error message might be better as:
"insufficient buffer space (%u left) for %s\n",
buffer_size, subsystem);
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)