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 for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20070421232600.GA5844@martell.zuzino.mipt.ru>
Date:	Sun, 22 Apr 2007 03:26:00 +0400
From:	Alexey Dobriyan <adobriyan@...il.com>
To:	linux-kernel@...r.kernel.org
Subject: [RFCPT] CONFIG_DEBUG_MEMCPY: memcpy() and overlapping areas

Overlapping areas are subject to memmove() not memcpy().

CONFIG_DEBUG_MEMCPY will print pointers and length in question as well as
backtrace to logs. Also, it should help if one of 3 variables got
corrupted somehow and you were lucky enough.

So far it was booted successfully on one x86_64 box and spit a couple of test
overlapping memcpy() becktraces, which means it's ready.
---

 arch/x86_64/lib/memmove.c   |    8 ++++++++
 include/asm-x86_64/string.h |    9 +++++++++
 lib/Kconfig.debug           |    6 ++++++
 3 files changed, 23 insertions(+)

--- a/arch/x86_64/lib/memmove.c
+++ b/arch/x86_64/lib/memmove.c
@@ -9,7 +9,15 @@
 void *memmove(void * dest,const void *src,size_t count)
 {
 	if (dest < src) { 
+#ifdef CONFIG_DEBUG_MEMCPY
+		char *d = dest;
+		const char *s = src;
+		while (count--)
+			*d++ = *s++;
+		return dest;
+#else
 		return memcpy(dest,src,count);
+#endif
 	} else {
 		char *p = (char *) dest + count;
 		char *s = (char *) src + count;
--- a/include/asm-x86_64/string.h
+++ b/include/asm-x86_64/string.h
@@ -3,6 +3,8 @@
 
 #ifdef __KERNEL__
 
+#include <linux/kernel.h>
+
 /* Written 2002 by Andi Kleen */ 
 
 /* Only used for special circumstances. Stolen from i386/string.h */ 
@@ -32,6 +34,13 @@ return (to);
 extern void *__memcpy(void *to, const void *from, size_t len); 
 static inline void *memcpy(void *dst, const void *src, size_t len)
 {
+#ifdef CONFIG_DEBUG_MEMCPY
+	if ((src < dst && src + len > dst) ||
+	    (src > dst && dst + len > src)) {
+		printk("memcpy(0x%p, 0x%p, %zu);\n", dst, src, len);
+		WARN_ON(1);
+	}
+#endif
 	if (__builtin_constant_p(len) && len >= 64)
 		return __memcpy(dst, src, len);
 	else
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -355,6 +355,12 @@ config DEBUG_LIST
 
 	  If unsure, say N.
 
+config DEBUG_MEMCPY
+	bool "Debug memcpy() function calls"
+	depends on DEBUG_KERNEL
+	help
+	  Enable checking for memcpy() on overlapping areas.
+
 config FRAME_POINTER
 	bool "Compile the kernel with frame pointers"
 	depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || AVR32 || SUPERH)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ