Skip to content

Commit 7b9ef66

Browse files
JustinStittTetsuo Handa
authored andcommitted
tomoyo: refactor deprecated strncpy
`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: KSPP#90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
1 parent a959dbd commit 7b9ef66

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

security/tomoyo/domain.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,13 +784,12 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
784784
if (!strcmp(domainname, "parent")) {
785785
char *cp;
786786

787-
strncpy(ee->tmp, old_domain->domainname->name,
788-
TOMOYO_EXEC_TMPSIZE - 1);
787+
strscpy(ee->tmp, old_domain->domainname->name, TOMOYO_EXEC_TMPSIZE);
789788
cp = strrchr(ee->tmp, ' ');
790789
if (cp)
791790
*cp = '\0';
792791
} else if (*domainname == '<')
793-
strncpy(ee->tmp, domainname, TOMOYO_EXEC_TMPSIZE - 1);
792+
strscpy(ee->tmp, domainname, TOMOYO_EXEC_TMPSIZE);
794793
else
795794
snprintf(ee->tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
796795
old_domain->domainname->name, domainname);

0 commit comments

Comments
 (0)