All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 5.15 01/20] string: uninline memcpy_and_pad
Date: Fri, 19 Nov 2021 18:39:19 +0100	[thread overview]
Message-ID: <20211119171444.686925925@linuxfoundation.org> (raw)
In-Reply-To: <20211119171444.640508836@linuxfoundation.org>

From: Guenter Roeck <linux@roeck-us.net>

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 <torvalds@linux-foundation.org>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 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 <linux/fortify-string.h>
 #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);



  reply	other threads:[~2021-11-19 17:40 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 17:39 [PATCH 5.15 00/20] 5.15.4-rc1 review Greg Kroah-Hartman
2021-11-19 17:39 ` Greg Kroah-Hartman [this message]
2021-11-19 17:39 ` [PATCH 5.15 02/20] Revert "drm: fb_helper: improve CONFIG_FB dependency" Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 03/20] Revert "drm: fb_helper: fix " Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 04/20] KVM: Fix steal time asm constraints Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 05/20] btrfs: introduce btrfs_is_data_reloc_root Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 06/20] btrfs: zoned: add a dedicated data relocation block group Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 07/20] btrfs: zoned: only allow one process to add pages to a relocation inode Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 08/20] btrfs: zoned: use regular writes for relocation Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 09/20] btrfs: check for relocation inodes on zoned btrfs in should_nocow Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 10/20] btrfs: zoned: allow preallocation for relocation inodes Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 11/20] fortify: Explicitly disable Clang support Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 12/20] block: Add a helper to validate the block size Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 13/20] loop: Use blk_validate_block_size() to validate " Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 14/20] Bluetooth: btusb: Add support for TP-Link UB500 Adapter Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 15/20] parisc/entry: fix trace test in syscall exit path Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 16/20] PCI/MSI: Deal with devices lying about their MSI mask capability Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 17/20] PCI: Add MSI masking quirk for Nvidia ION AHCI Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 18/20] perf/core: Avoid put_page() when GUP fails Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 19/20] thermal: Fix NULL pointer dereferences in of_thermal_ functions Greg Kroah-Hartman
2021-11-19 17:39 ` [PATCH 5.15 20/20] Revert "ACPI: scan: Release PM resources blocked by unused objects" Greg Kroah-Hartman
2021-11-19 19:15 ` [PATCH 5.15 00/20] 5.15.4-rc1 review Florian Fainelli
2021-11-19 21:53 ` Fox Chen
2021-11-19 23:17 ` Shuah Khan
2021-11-20  4:28 ` Daniel Díaz
2021-11-20  8:16 ` Rudi Heitbaum
2021-11-20 16:53 ` Guenter Roeck
2021-11-20 17:40 ` Scott Bruce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211119171444.686925925@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.