diff options
author | Kees Cook <keescook@chromium.org> | 2023-09-20 21:38:14 +0200 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2024-02-21 05:47:32 +0100 |
commit | e6584c3964f2ff76a9fb5a701e4a59997b35e547 (patch) | |
tree | 330e893f5b937e2c335c08475a59df545b75f9e7 /arch/um/include | |
parent | string: Redefine strscpy_pad() as a macro (diff) | |
download | linux-e6584c3964f2ff76a9fb5a701e4a59997b35e547.tar.xz linux-e6584c3964f2ff76a9fb5a701e4a59997b35e547.zip |
string: Allow 2-argument strscpy()
Using sizeof(dst) for the "size" argument in strscpy() is the
overwhelmingly common case. Instead of requiring this everywhere, allow a
2-argument version to be used that will use the sizeof() internally. There
are other functions in the kernel with optional arguments[1], so this
isn't unprecedented, and improves readability. Update and relocate the
kern-doc for strscpy() too, and drop __HAVE_ARCH_STRSCPY as it is unused.
Adjust ARCH=um build to notice the changed export name, as it doesn't
do full header includes for the string helpers.
This could additionally let us save a few hundred lines of code:
1177 files changed, 2455 insertions(+), 3026 deletions(-)
with a treewide cleanup using Coccinelle:
@needless_arg@
expression DST, SRC;
@@
strscpy(DST, SRC
-, sizeof(DST)
)
Link: https://elixir.bootlin.com/linux/v6.7/source/include/linux/pci.h#L1517 [1]
Reviewed-by: Justin Stitt <justinstitt@google.com>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'arch/um/include')
-rw-r--r-- | arch/um/include/shared/user.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/um/include/shared/user.h b/arch/um/include/shared/user.h index 981e11d8e025..9568cc04cbb7 100644 --- a/arch/um/include/shared/user.h +++ b/arch/um/include/shared/user.h @@ -51,7 +51,8 @@ static inline int printk(const char *fmt, ...) extern int in_aton(char *str); extern size_t strlcat(char *, const char *, size_t); -extern size_t strscpy(char *, const char *, size_t); +extern size_t sized_strscpy(char *, const char *, size_t); +#define strscpy(dst, src, size) sized_strscpy(dst, src, size) /* Copied from linux/compiler-gcc.h since we can't include it directly */ #define barrier() __asm__ __volatile__("": : :"memory") |