From: Greg Kroah-Hartman Date: Fri, 19 Nov 2021 11:35:15 +0000 (+0100) Subject: 5.15-stable patches X-Git-Tag: v5.4.161~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df6e2446f179164b6ccb3eec9c6f7bca980be470;p=thirdparty%2Fkernel%2Fstable-queue.git 5.15-stable patches added patches: string-uninline-memcpy_and_pad.patch --- diff --git a/queue-5.15/series b/queue-5.15/series new file mode 100644 index 00000000000..95ce5807698 --- /dev/null +++ b/queue-5.15/series @@ -0,0 +1 @@ +string-uninline-memcpy_and_pad.patch diff --git a/queue-5.15/string-uninline-memcpy_and_pad.patch b/queue-5.15/string-uninline-memcpy_and_pad.patch new file mode 100644 index 00000000000..f7e24533668 --- /dev/null +++ b/queue-5.15/string-uninline-memcpy_and_pad.patch @@ -0,0 +1,93 @@ +From 5c4e0a21fae877a7ef89be6dcc6263ec672372b8 Mon Sep 17 00:00:00 2001 +From: Guenter Roeck +Date: Tue, 2 Nov 2021 07:24:20 -0700 +Subject: string: uninline memcpy_and_pad + +From: Guenter Roeck + +commit 5c4e0a21fae877a7ef89be6dcc6263ec672372b8 upstream. + +When building m68k:allmodconfig, recent versions of gcc generate the +following error if the length of UTS_RELEASE is less than 8 bytes. + + In function 'memcpy_and_pad', + inlined from 'nvmet_execute_disc_identify' at + drivers/nvme/target/discovery.c:268:2: arch/m68k/include/asm/string.h:72:25: error: + '__builtin_memcpy' reading 8 bytes from a region of size 7 + +Discussions around the problem suggest that this only happens if an +architecture does not provide strlen(), if -ffreestanding is provided as +compiler option, and if CONFIG_FORTIFY_SOURCE=n. All of this is the case +for m68k. The exact reasons are unknown, but seem to be related to the +ability of the compiler to evaluate the return value of strlen() and +the resulting execution flow in memcpy_and_pad(). It would be possible +to work around the problem by using sizeof(UTS_RELEASE) instead of +strlen(UTS_RELEASE), but that would only postpone the problem until the +function is called in a similar way. Uninline memcpy_and_pad() instead +to solve the problem for good. + +Suggested-by: Linus Torvalds +Reviewed-by: Geert Uytterhoeven +Acked-by: Andy Shevchenko +Signed-off-by: Guenter Roeck +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/string.h | 19 ++----------------- + lib/string_helpers.c | 20 ++++++++++++++++++++ + 2 files changed, 22 insertions(+), 17 deletions(-) + +--- a/include/linux/string.h ++++ b/include/linux/string.h +@@ -262,23 +262,8 @@ void __write_overflow(void) __compiletim + #include + #endif + +-/** +- * memcpy_and_pad - Copy one buffer to another with padding +- * @dest: Where to copy to +- * @dest_len: The destination buffer size +- * @src: Where to copy from +- * @count: The number of bytes to copy +- * @pad: Character to use for padding if space is left in destination. +- */ +-static inline void memcpy_and_pad(void *dest, size_t dest_len, +- const void *src, size_t count, int pad) +-{ +- if (dest_len > count) { +- memcpy(dest, src, count); +- memset(dest + count, pad, dest_len - count); +- } else +- memcpy(dest, src, dest_len); +-} ++void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count, ++ int pad); + + /** + * str_has_prefix - Test if a string has a given prefix +--- a/lib/string_helpers.c ++++ b/lib/string_helpers.c +@@ -696,3 +696,23 @@ void kfree_strarray(char **array, size_t + kfree(array); + } + EXPORT_SYMBOL_GPL(kfree_strarray); ++ ++/** ++ * memcpy_and_pad - Copy one buffer to another with padding ++ * @dest: Where to copy to ++ * @dest_len: The destination buffer size ++ * @src: Where to copy from ++ * @count: The number of bytes to copy ++ * @pad: Character to use for padding if space is left in destination. ++ */ ++void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count, ++ int pad) ++{ ++ if (dest_len > count) { ++ memcpy(dest, src, count); ++ memset(dest + count, pad, dest_len - count); ++ } else { ++ memcpy(dest, src, dest_len); ++ } ++} ++EXPORT_SYMBOL(memcpy_and_pad);