All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org,
	ryabinin.a.a@gmail.com
Cc: kasan-dev@googlegroups.com, glider@google.com,
	Dmitry Vyukov <dvyukov@google.com>
Subject: [PATCH] kasan: account for new sections when instrumenting globals
Date: Wed, 22 Jun 2016 19:07:18 +0200	[thread overview]
Message-ID: <1466615238-57411-1-git-send-email-dvyukov@google.com> (raw)

When I build kernel with CONFIG_KASAN and gcc6 (which instruments globals
and inserts global constructors and destructors), vmlinux contains some
new unaccounted sections: .text.exit .text.startup .dtors.
This messes vvar/percpu layout. Want:

ffffffff822bfd80 D _edata
ffffffff822c0000 D __vvar_beginning_hack
ffffffff822c0000 A __vvar_page
ffffffff822c0080 0000000000000098 D vsyscall_gtod_data
ffffffff822c1000 A __init_begin
ffffffff822c1000 D init_per_cpu__irq_stack_union
ffffffff822c1000 A __per_cpu_load
ffffffff822d3000 D init_per_cpu__gdt_page

Got:

ffffffff8279a600 D _edata
ffffffff8279b000 A __vvar_page
ffffffff8279c000 A __init_begin
ffffffff8279c000 D init_per_cpu__irq_stack_union
ffffffff8279c000 A __per_cpu_load
ffffffff8279e000 D __vvar_beginning_hack
ffffffff8279e080 0000000000000098 D vsyscall_gtod_data
ffffffff827ae000 D init_per_cpu__gdt_page

If my reading of the linker script is correct, this happens because
__vvar_page and .vvar get different addresses here:
//arch/x86/kernel/vmlinux.lds.S

	. = ALIGN(PAGE_SIZE);
	__vvar_page = .;

	.vvar : AT(ADDR(.vvar) - LOAD_OFFSET) {
		/* work around gold bug 13023 */
		__vvar_beginning_hack = .;

Merge .text.exit into EXIT_TEXT, .text.startup into INIT_TEXT and
.dtors into INIT_DATA.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>

---

I can't say I fully understand what happens here, but it fixes my
build and boot. I think we need something along these lines,
but I am not sure about details.
---
 include/asm-generic/vmlinux.lds.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 6a67ab9..6067d01 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -510,6 +510,7 @@
 #define KERNEL_CTORS()	. = ALIGN(8);			   \
 			VMLINUX_SYMBOL(__ctors_start) = .; \
 			*(.ctors)			   \
+			*(.dtors)			   \
 			*(SORT(.init_array.*))		   \
 			*(.init_array)			   \
 			VMLINUX_SYMBOL(__ctors_end) = .;
@@ -542,7 +543,9 @@
 
 #define INIT_TEXT							\
 	*(.init.text)							\
-	MEM_DISCARD(init.text)
+	*(.text.startup)						\
+	MEM_DISCARD(init.text)						\
+	MEM_DISCARD(text.startup)
 
 #define EXIT_DATA							\
 	*(.exit.data)							\
@@ -551,7 +554,9 @@
 
 #define EXIT_TEXT							\
 	*(.exit.text)							\
-	MEM_DISCARD(exit.text)
+	*(.text.exit)							\
+	MEM_DISCARD(exit.text)						\
+	MEM_DISCARD(text.exit)
 
 #define EXIT_CALL							\
 	*(.exitcall.exit)
-- 
2.8.0.rc3.226.g39d4020

             reply	other threads:[~2016-06-22 17:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-22 17:07 Dmitry Vyukov [this message]
2016-06-23 11:49 ` [PATCH] kasan: account for new sections when instrumenting globals Andrey Ryabinin
2016-06-23 11:50   ` Andrey Ryabinin
2016-06-23 12:40     ` Dmitry Vyukov
2016-06-23 13:06       ` Andrey Ryabinin
2016-06-23 13:19         ` Dmitry Vyukov
2016-06-23 13:21           ` Dmitry Vyukov
2016-06-23 14:00             ` Andrey Ryabinin
2016-06-23 14:38               ` Dmitry Vyukov
2016-06-23 14:58                 ` Andrey Ryabinin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466615238-57411-1-git-send-email-dvyukov@google.com \
    --to=dvyukov@google.com \
    --cc=arnd@arndb.de \
    --cc=glider@google.com \
    --cc=hpa@zytor.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=ryabinin.a.a@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.