提交 f4e335f3 编写于 作者: K Kees Cook 提交者: Greg Kroah-Hartman

lkdtm/fortify: Swap memcpy() for strncpy()

The memcpy() runtime defenses are still not landed, so test with
strncpy() for now.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: NMuhammad Usama Anjum <usama.anjum@collabora.com>
Reviewed-by: NMuhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: NKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220216202548.2093883-1-keescook@chromium.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 2c9ae453
......@@ -44,14 +44,14 @@ void lkdtm_FORTIFIED_SUBOBJECT(void)
strscpy(src, "over ten bytes", size);
size = strlen(src) + 1;
pr_info("trying to strcpy past the end of a member of a struct\n");
pr_info("trying to strncpy past the end of a member of a struct\n");
/*
* memcpy(target.a, src, 20); will hit a compile error because the
* strncpy(target.a, src, 20); will hit a compile error because the
* compiler knows at build time that target.a < 20 bytes. Use a
* volatile to force a runtime error.
*/
memcpy(target.a, src, size);
strncpy(target.a, src, size);
/* Store result to global to prevent the code from being eliminated */
fortify_scratch_space = target.a[3];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册