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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241123094729.1099378-3-mjguzik@gmail.com>
Date: Sat, 23 Nov 2024 10:47:29 +0100
From: Mateusz Guzik <mjguzik@...il.com>
To: tglx@...utronix.de,
	bp@...en8.de,
	andy@...nel.org,
	akpm@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org,
	x86@...nel.org,
	Mateusz Guzik <mjguzik@...il.com>
Subject: [PATCH 2/2] string: retire bcmp()

While architectures could override it thanks to __HAVE_ARCH_BCMP, none
of them did. Instead it was implemented as a call to memcmp().

These routines differ in the API contract: memcmp()'s result indicates
which way the difference goes (making it usable for sorting), whereas
bcmp()'s result merely states whether the buffers differ in any way.

This means that a dedicated optimized bcmp() is cheaper to execute than
memcmp() for differing buffers as there is no need to compute the return
value.

However, per the above nobody bothered to write one and it is unclear if
it makes sense to do it.

Users which really want to compare stuff may want to handle it
differently (like e.g., the path lookup).

As there are no users and the code is merely a wrapper around memcmp(),
just whack it.

Signed-off-by: Mateusz Guzik <mjguzik@...il.com>
---
 arch/x86/boot/string.c |  8 --------
 arch/x86/boot/string.h |  1 -
 include/linux/string.h |  3 ---
 lib/Makefile           |  3 +--
 lib/string.c           | 19 -------------------
 5 files changed, 1 insertion(+), 33 deletions(-)

diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index c23f3b9c84fe..e8095abf03df 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -37,14 +37,6 @@ int memcmp(const void *s1, const void *s2, size_t len)
 	return diff;
 }
 
-/*
- * Clang may lower `memcmp == 0` to `bcmp == 0`.
- */
-int bcmp(const void *s1, const void *s2, size_t len)
-{
-	return memcmp(s1, s2, len);
-}
-
 int strcmp(const char *str1, const char *str2)
 {
 	const unsigned char *s1 = (const unsigned char *)str1;
diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h
index e5d2c6b8c2f1..cf83faee78cc 100644
--- a/arch/x86/boot/string.h
+++ b/arch/x86/boot/string.h
@@ -11,7 +11,6 @@ void *memcpy(void *dst, const void *src, size_t len);
 void *memmove(void *dst, const void *src, size_t len);
 void *memset(void *dst, int c, size_t len);
 int memcmp(const void *s1, const void *s2, size_t len);
-int bcmp(const void *s1, const void *s2, size_t len);
 
 /* Access builtin version by default. */
 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
diff --git a/include/linux/string.h b/include/linux/string.h
index 0dd27afcfaf7..d4904951b627 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -267,9 +267,6 @@ extern void * memscan(void *,int,__kernel_size_t);
 #ifndef __HAVE_ARCH_MEMCMP
 extern int memcmp(const void *,const void *,__kernel_size_t);
 #endif
-#ifndef __HAVE_ARCH_BCMP
-extern int bcmp(const void *,const void *,__kernel_size_t);
-#endif
 #ifndef __HAVE_ARCH_MEMCHR
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
diff --git a/lib/Makefile b/lib/Makefile
index 773adf88af41..c382b43fe37e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -265,8 +265,7 @@ obj-$(CONFIG_IRQ_POLL) += irq_poll.o
 obj-$(CONFIG_POLYNOMIAL) += polynomial.o
 
 # stackdepot.c should not be instrumented or call instrumented functions.
-# Prevent the compiler from calling builtins like memcmp() or bcmp() from this
-# file.
+# Prevent the compiler from calling builtins like memcmp() from this file.
 CFLAGS_stackdepot.o += -fno-builtin
 obj-$(CONFIG_STACKDEPOT) += stackdepot.o
 KASAN_SANITIZE_stackdepot.o := n
diff --git a/lib/string.c b/lib/string.c
index 76327b51e36f..3a319d1c5aae 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -680,25 +680,6 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
 EXPORT_SYMBOL(memcmp);
 #endif
 
-#ifndef __HAVE_ARCH_BCMP
-/**
- * bcmp - returns 0 if and only if the buffers have identical contents.
- * @a: pointer to first buffer.
- * @b: pointer to second buffer.
- * @len: size of buffers.
- *
- * The sign or magnitude of a non-zero return value has no particular
- * meaning, and architectures may implement their own more efficient bcmp(). So
- * while this particular implementation is a simple (tail) call to memcmp, do
- * not rely on anything but whether the return value is zero or non-zero.
- */
-int bcmp(const void *a, const void *b, size_t len)
-{
-	return memcmp(a, b, len);
-}
-EXPORT_SYMBOL(bcmp);
-#endif
-
 #ifndef __HAVE_ARCH_MEMSCAN
 /**
  * memscan - Find a character in an area of memory.
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ