mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/vdso: Error out if the vDSO isn't a valid DSO
@ 2016-07-18 21:46 Andy Lutomirski
  2016-07-19  7:33 ` [tip:x86/asm] " tip-bot for Andy Lutomirski
  2016-07-19 14:26 ` [PATCH] " Dmitry Safonov
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Lutomirski @ 2016-07-18 21:46 UTC (permalink / raw)
  To: x86; +Cc: Borislav Petkov, linux-kernel, Andy Lutomirski

Some distros has been playing with toolchain changes that can affect
the type of ELF objects built.  Occasionally, this goes wrong and
the vDSO ends up not being a DSO at all.  This causes the kernel to
end up broken in a surprisingly subtle way -- glibc apparently
silently ignores a vDSO that isn't a DSO, so everything works,
albeit slowly, until users try a different libc implementation.

Make the kernel build process a bit more robust: fail outright if
the vDSO isn't ET_DYN or is missing its PT_DYNAMIC segment.  I've
never seen this in an unmodified kernel.

See https://github.com/docker/docker/issues/23378

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/entry/vdso/vdso2c.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 63a03bb91497..4f741192846d 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -22,6 +22,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 
 	ELF(Phdr) *pt = (ELF(Phdr) *)(raw_addr + GET_LE(&hdr->e_phoff));
 
+	if (hdr->e_type != ET_DYN)
+		fail("input is not a shared object\n");
+
 	/* Walk the segment table. */
 	for (i = 0; i < GET_LE(&hdr->e_phnum); i++) {
 		if (GET_LE(&pt[i].p_type) == PT_LOAD) {
@@ -49,6 +52,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 	if (stripped_len < load_size)
 		fail("stripped input is too short\n");
 
+	if (!dyn)
+		fail("input has no PT_DYNAMIC section -- your toolchain is buggy\n");
+
 	/* Walk the dynamic table */
 	for (i = 0; dyn + i < dyn_end &&
 		     GET_LE(&dyn[i].d_tag) != DT_NULL; i++) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:x86/asm] x86/vdso: Error out if the vDSO isn't a valid DSO
  2016-07-18 21:46 [PATCH] x86/vdso: Error out if the vDSO isn't a valid DSO Andy Lutomirski
@ 2016-07-19  7:33 ` tip-bot for Andy Lutomirski
  2016-07-19 14:26 ` [PATCH] " Dmitry Safonov
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Andy Lutomirski @ 2016-07-19  7:33 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, luto, tglx, peterz, mingo, brgerst, bp, hpa,
	torvalds, dvlasenk, jpoimboe

Commit-ID:  57f90c3dfc75da89358735c06bf9bc9815b4183e
Gitweb:     http://git.kernel.org/tip/57f90c3dfc75da89358735c06bf9bc9815b4183e
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Mon, 18 Jul 2016 14:46:35 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 19 Jul 2016 08:50:24 +0200

x86/vdso: Error out if the vDSO isn't a valid DSO

Some distros has been playing with toolchain changes that can affect
the type of ELF objects built.  Occasionally, this goes wrong and
the vDSO ends up not being a DSO at all.  This causes the kernel to
end up broken in a surprisingly subtle way -- glibc apparently
silently ignores a vDSO that isn't a DSO, so everything works,
albeit slowly, until users try a different libc implementation.

Make the kernel build process a bit more robust: fail outright if
the vDSO isn't ET_DYN or is missing its PT_DYNAMIC segment.  I've
never seen this in an unmodified kernel.

See: https://github.com/docker/docker/issues/23378

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/8a30e0a07c3b47ff917a8daa2df5e407cc0c6698.1468878336.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/entry/vdso/vdso2c.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 63a03bb..4f74119 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -22,6 +22,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 
 	ELF(Phdr) *pt = (ELF(Phdr) *)(raw_addr + GET_LE(&hdr->e_phoff));
 
+	if (hdr->e_type != ET_DYN)
+		fail("input is not a shared object\n");
+
 	/* Walk the segment table. */
 	for (i = 0; i < GET_LE(&hdr->e_phnum); i++) {
 		if (GET_LE(&pt[i].p_type) == PT_LOAD) {
@@ -49,6 +52,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 	if (stripped_len < load_size)
 		fail("stripped input is too short\n");
 
+	if (!dyn)
+		fail("input has no PT_DYNAMIC section -- your toolchain is buggy\n");
+
 	/* Walk the dynamic table */
 	for (i = 0; dyn + i < dyn_end &&
 		     GET_LE(&dyn[i].d_tag) != DT_NULL; i++) {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/vdso: Error out if the vDSO isn't a valid DSO
  2016-07-18 21:46 [PATCH] x86/vdso: Error out if the vDSO isn't a valid DSO Andy Lutomirski
  2016-07-19  7:33 ` [tip:x86/asm] " tip-bot for Andy Lutomirski
@ 2016-07-19 14:26 ` Dmitry Safonov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Safonov @ 2016-07-19 14:26 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: X86 ML, Borislav Petkov, linux-kernel

2016-07-19 0:46 GMT+03:00 Andy Lutomirski <luto@kernel.org>:
> Some distros has been playing with toolchain changes that can affect
> the type of ELF objects built.  Occasionally, this goes wrong and
> the vDSO ends up not being a DSO at all.  This causes the kernel to
> end up broken in a surprisingly subtle way -- glibc apparently
> silently ignores a vDSO that isn't a DSO, so everything works,
> albeit slowly, until users try a different libc implementation.
>
> Make the kernel build process a bit more robust: fail outright if
> the vDSO isn't ET_DYN or is missing its PT_DYNAMIC segment.  I've
> never seen this in an unmodified kernel.
>
> See https://github.com/docker/docker/issues/23378

Heh, that's good, I've also saw the same kind of bug:
https://lists.openvz.org/pipermail/criu/2016-June/029153.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-19 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18 21:46 [PATCH] x86/vdso: Error out if the vDSO isn't a valid DSO Andy Lutomirski
2016-07-19  7:33 ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2016-07-19 14:26 ` [PATCH] " Dmitry Safonov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome