[PATCH] tomoyo: refactor deprecated strncpy
Tetsuo Handa
penguin-kernel at I-love.SAKURA.ne.jp
Sat Aug 5 12:49:23 UTC 2023
Thank you.
Applied to https://scm.osdn.net/gitroot/tomoyo/tomoyo-test1.git .
On 2023/08/04 16:40, Kees Cook wrote:
> On Thu, Aug 03, 2023 at 09:33:44PM +0000, Justin Stitt wrote:
>> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>>
>> A suitable replacement is `strscpy` [2] due to the fact that it
>> guarantees NUL-termination on its destination buffer argument which is
>> _not_ the case for `strncpy`!
>>
>> It should be noted that the destination buffer is zero-initialized and
>> had a max length of `sizeof(dest) - 1`. There is likely _not_ a bug
>> present in the current implementation. However, by switching to
>> `strscpy` we get the benefit of no longer needing the `- 1`'s from the
>> string copy invocations on top of `strscpy` being a safer interface all
>> together.
>>
>> [1]: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
>> [2]: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
>>
>> Link: https://github.com/KSPP/linux/issues/90
>> Cc: linux-hardening at vger.kernel.org
>> Signed-off-by: Justin Stitt <justinstitt at google.com>
>
> Thanks! This looks correct to me.
>
> Reviewed-by: Kees Cook <keescook at chromium.org>
>
More information about the Linux-security-module-archive
mailing list