This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC/PATCH] memcpy-ssse3: add overlap checks


Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 sysdeps/x86_64/multiarch/memcpy-ssse3-back.S |   12 ++++++++++++
 sysdeps/x86_64/multiarch/memcpy-ssse3.S      |   12 ++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

On 2.13 the behavior of memcpy changed on ssse3 so that it can go backwards and
cause problems on improper applications. On 2.14 memcpy is properly versioned
so that the new behavior is only triggered on newly compiled applications.

However, there are still applications that rely on the old behavior, and it's
not trivial to find them all.

I therefore propose to have a transition period on 2.14 where badly behaved
applications crash. Then, on 2.15, remove these extra checks.

I tried to add this code on memcpy_chk but somehow it doesn't seem to work for
me.

As mentioned in bug #12518, right after booting I've seen issues on pulseaudio
and readahead-collector on my Fedora 14, which suggests there might be many
more.

What do you think?

diff --git a/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S b/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S
index 48c974e..659cdc5 100644
--- a/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S
+++ b/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S
@@ -57,6 +57,18 @@ END (MEMCPY_CHK)
 #endif
 
 ENTRY (MEMCPY)
+#ifndef USE_AS_MEMMOVE
+	/* TODO remove on 2.15 (after some transition period) */
+	lea	(%rsi, %rdx), %r9
+	lea	(%rdi, %rdx), %r11
+	cmp	%r9, %rdi		/* dest start >= source end */
+	jae	L(nonoverlap)		/*  -> nonoverlapping */
+	cmp	%r11, %rsi		/* source start >= destination end */
+	jae	L(nonoverlap)		/*  -> nonoverlapping */
+	jmp     HIDDEN_JUMPTARGET (__chk_fail)
+L(nonoverlap):
+#endif
+
 	mov	%rdi, %rax
 #ifdef USE_AS_MEMPCPY
 	add	%rdx, %rax
diff --git a/sysdeps/x86_64/multiarch/memcpy-ssse3.S b/sysdeps/x86_64/multiarch/memcpy-ssse3.S
index 9a878d3..572f4a7 100644
--- a/sysdeps/x86_64/multiarch/memcpy-ssse3.S
+++ b/sysdeps/x86_64/multiarch/memcpy-ssse3.S
@@ -57,6 +57,18 @@ END (MEMCPY_CHK)
 #endif
 
 ENTRY (MEMCPY)
+#ifndef USE_AS_MEMMOVE
+	/* TODO remove on 2.15 (after some transition period) */
+	lea	(%rsi, %rdx), %r9
+	lea	(%rdi, %rdx), %r11
+	cmp	%r9, %rdi		/* dest start >= source end */
+	jae	L(nonoverlap)		/*  -> nonoverlapping */
+	cmp	%r11, %rsi		/* source start >= destination end */
+	jae	L(nonoverlap)		/*  -> nonoverlapping */
+	jmp     HIDDEN_JUMPTARGET (__chk_fail)
+L(nonoverlap):
+#endif
+
 	mov	%rdi, %rax
 #ifdef USE_AS_MEMPCPY
 	add	%rdx, %rax
-- 
1.7.5.rc1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]