lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 23 Jan 2022 10:58:07 +0900
From:   Kuniyuki Iwashima <kuniyu@...zon.co.jp>
To:     Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>
CC:     Benjamin Herrenschmidt <benh@...zon.com>,
        Kuniyuki Iwashima <kuniyu@...zon.co.jp>,
        Kuniyuki Iwashima <kuni1840@...il.com>, <x86@...nel.org>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH] x86/boot: Avoid redundant address overlap tests in memcpy().

When 'dest' and 'src' overlap, the boot time memcpy() calls memmove(),
which tests the same condition again.  GCC does not optimise it for now.
Let's split the copy part of memmove() as ____memmove() and call it from
memcpy().

Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.co.jp>
---
 arch/x86/boot/compressed/string.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c
index 81fc1eaa3..4c0edb5d6 100644
--- a/arch/x86/boot/compressed/string.c
+++ b/arch/x86/boot/compressed/string.c
@@ -50,26 +50,31 @@ void *memset(void *s, int c, size_t n)
 	return s;
 }
 
-void *memmove(void *dest, const void *src, size_t n)
+void *____memmove(void *dest, const void *src, size_t n)
 {
 	unsigned char *d = dest;
 	const unsigned char *s = src;
 
-	if (d <= s || d - s >= n)
-		return ____memcpy(dest, src, n);
-
 	while (n-- > 0)
 		d[n] = s[n];
 
 	return dest;
 }
 
-/* Detect and warn about potential overlaps, but handle them with memmove. */
+void *memmove(void *dest, const void *src, size_t n)
+{
+	if (dest <= src || dest - src >= n)
+		return ____memcpy(dest, src, n);
+
+	return ____memmove(dest, src, n);
+}
+
+/* Detect and warn about potential overlaps, but handle them with ____memmove(). */
 void *memcpy(void *dest, const void *src, size_t n)
 {
 	if (dest > src && dest - src < n) {
 		warn("Avoiding potentially unsafe overlapping memcpy()!");
-		return memmove(dest, src, n);
+		return ____memmove(dest, src, n);
 	}
 	return ____memcpy(dest, src, n);
 }
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ