* [PATCH v2 mips-next 0/4] MIPS: vmlinux.lds.S sections fix & cleanup @ 2021-01-06 20:07 Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin 0 siblings, 1 reply; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:07 UTC (permalink / raw) To: Thomas Bogendoerfer Cc: Alexander Lobakin, Nathan Chancellor, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel This series hunts the problems discovered after manual enabling of ARCH_WANT_LD_ORPHAN_WARN, notably the missing PAGE_ALIGNED_DATA() section affecting VDSO placement (marked for stable). Compile and runtime tested on MIPS32R2 CPS board with no issues. Since v1 [0]: - catch .got entries too as LLD may produce it (Nathan); - check for unwanted sections to be zero-sized instead of discarding (Fangrui). [0] https://lore.kernel.org/linux-mips/20210104121729.46981-1-alobakin@pm.me Alexander Lobakin (4): MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time MIPS: select ARCH_WANT_LD_ORPHAN_WARN arch/mips/Kconfig | 1 + arch/mips/kernel/vmlinux.lds.S | 39 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) -- 2.30.0 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section 2021-01-06 20:07 [PATCH v2 mips-next 0/4] MIPS: vmlinux.lds.S sections fix & cleanup Alexander Lobakin @ 2021-01-06 20:08 ` Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin ` (3 more replies) 0 siblings, 4 replies; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:08 UTC (permalink / raw) To: Thomas Bogendoerfer Cc: Alexander Lobakin, Nathan Chancellor, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel MIPS uses its own declaration of rwdata, and thus it should be kept in sync with the asm-generic one. Currently PAGE_ALIGNED_DATA() is missing from the linker script, which emits the following ld warnings: mips-alpine-linux-musl-ld: warning: orphan section `.data..page_aligned' from `arch/mips/kernel/vdso.o' being placed in section `.data..page_aligned' mips-alpine-linux-musl-ld: warning: orphan section `.data..page_aligned' from `arch/mips/vdso/vdso-image.o' being placed in section `.data..page_aligned' Add the necessary declaration, so the mentioned structures will be placed in vmlinux as intended: ffffffff80630580 D __end_once ffffffff80630580 D __start___dyndbg ffffffff80630580 D __start_once ffffffff80630580 D __stop___dyndbg ffffffff80634000 d mips_vdso_data ffffffff80638000 d vdso_data ffffffff80638580 D _gp ffffffff8063c000 T __init_begin ffffffff8063c000 D _edata ffffffff8063c000 T _sinittext -> ffffffff805a4000 D __end_init_task ffffffff805a4000 D __nosave_begin ffffffff805a4000 D __nosave_end ffffffff805a4000 d mips_vdso_data ffffffff805a8000 d vdso_data ffffffff805ac000 D mmlist_lock ffffffff805ac080 D tasklist_lock Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO") Cc: stable@vger.kernel.org # 4.4+ Signed-off-by: Alexander Lobakin <alobakin@pm.me> --- arch/mips/kernel/vmlinux.lds.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 5e97e9d02f98..83e27a181206 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -90,6 +90,7 @@ SECTIONS INIT_TASK_DATA(THREAD_SIZE) NOSAVE_DATA + PAGE_ALIGNED_DATA(PAGE_SIZE) CACHELINE_ALIGNED_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT) READ_MOSTLY_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT) DATA_DATA -- 2.30.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin @ 2021-01-06 20:08 ` Alexander Lobakin 2021-01-06 22:07 ` Kees Cook 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin ` (2 subsequent siblings) 3 siblings, 1 reply; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:08 UTC (permalink / raw) To: Thomas Bogendoerfer Cc: Alexander Lobakin, Nathan Chancellor, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel Discard GNU attributes at link time as kernel doesn't use it at all. Solves a dozen of the following ld warnings (one per every file): mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' from `arch/mips/kernel/head.o' being placed in section `.gnu.attributes' mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' from `init/main.o' being placed in section `.gnu.attributes' Misc: sort DISCARDS section entries alphabetically. Signed-off-by: Alexander Lobakin <alobakin@pm.me> --- arch/mips/kernel/vmlinux.lds.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 83e27a181206..5d6563970ab2 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -221,9 +221,10 @@ SECTIONS /* ABI crap starts here */ *(.MIPS.abiflags) *(.MIPS.options) + *(.eh_frame) + *(.gnu.attributes) *(.options) *(.pdr) *(.reginfo) - *(.eh_frame) } } -- 2.30.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 20:08 ` [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin @ 2021-01-06 22:07 ` Kees Cook 2021-01-06 22:36 ` Alexander Lobakin 2021-01-06 22:43 ` Fāng-ruì Sòng 0 siblings, 2 replies; 15+ messages in thread From: Kees Cook @ 2021-01-06 22:07 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel On Wed, Jan 06, 2021 at 08:08:19PM +0000, Alexander Lobakin wrote: > Discard GNU attributes at link time as kernel doesn't use it at all. > Solves a dozen of the following ld warnings (one per every file): > > mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > from `arch/mips/kernel/head.o' being placed in section > `.gnu.attributes' > mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > from `init/main.o' being placed in section `.gnu.attributes' > > Misc: sort DISCARDS section entries alphabetically. Hmm, I wonder what is causing the appearance of .eh_frame? With help I tracked down all the causes of this on x86, arm, and arm64, so that's why it's not in the asm-generic DISCARDS section. I suspect this could be cleaned up for mips too? Similarly for .gnu.attributes. What is generating that? (Or, more specifically, why is it both being generated AND discarded?) -Kees > > Signed-off-by: Alexander Lobakin <alobakin@pm.me> > --- > arch/mips/kernel/vmlinux.lds.S | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S > index 83e27a181206..5d6563970ab2 100644 > --- a/arch/mips/kernel/vmlinux.lds.S > +++ b/arch/mips/kernel/vmlinux.lds.S > @@ -221,9 +221,10 @@ SECTIONS > /* ABI crap starts here */ > *(.MIPS.abiflags) > *(.MIPS.options) > + *(.eh_frame) > + *(.gnu.attributes) > *(.options) > *(.pdr) > *(.reginfo) > - *(.eh_frame) > } > } > -- > 2.30.0 > > -- Kees Cook ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 22:07 ` Kees Cook @ 2021-01-06 22:36 ` Alexander Lobakin 2021-01-06 23:26 ` Kees Cook 2021-01-06 22:43 ` Fāng-ruì Sòng 1 sibling, 1 reply; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 22:36 UTC (permalink / raw) To: Kees Cook Cc: Alexander Lobakin, Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel From: Kees Cook <keescook@chromium.org> Date: Wed, 6 Jan 2021 14:07:07 -0800 > On Wed, Jan 06, 2021 at 08:08:19PM +0000, Alexander Lobakin wrote: >> Discard GNU attributes at link time as kernel doesn't use it at all. >> Solves a dozen of the following ld warnings (one per every file): >> >> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' >> from `arch/mips/kernel/head.o' being placed in section >> `.gnu.attributes' >> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' >> from `init/main.o' being placed in section `.gnu.attributes' >> >> Misc: sort DISCARDS section entries alphabetically. > > Hmm, I wonder what is causing the appearance of .eh_frame? With help I > tracked down all the causes of this on x86, arm, and arm64, so that's > why it's not in the asm-generic DISCARDS section. I suspect this could > be cleaned up for mips too? I could take a look and hunt it down. Could you please give some refs on what were the causes and solutions for the mentioned architectures? > Similarly for .gnu.attributes. What is generating that? (Or, more > specifically, why is it both being generated AND discarded?) On my setup, GNU Attributes consist of MIPS FP type (soft) and (if I'm correct) MIPS GNU Hash tables. > -Kees By the way. I've built the kernel with LLVM stack (and found several subjects for more patches) and, besides '.got', also got a fistful of '.data..compoundliteral*' symbols (drivers/mtd/nand/spi/, net/ipv6/ etc). Where should they be placed (rodata, rwdata, ...) or they are anomalies of some kind and should be fixed somehow? >> >> Signed-off-by: Alexander Lobakin <alobakin@pm.me> >> --- >> arch/mips/kernel/vmlinux.lds.S | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S >> index 83e27a181206..5d6563970ab2 100644 >> --- a/arch/mips/kernel/vmlinux.lds.S >> +++ b/arch/mips/kernel/vmlinux.lds.S >> @@ -221,9 +221,10 @@ SECTIONS >> /* ABI crap starts here */ >> *(.MIPS.abiflags) >> *(.MIPS.options) >> + *(.eh_frame) >> + *(.gnu.attributes) >> *(.options) >> *(.pdr) >> *(.reginfo) >> - *(.eh_frame) >> } >> } >> -- >> 2.30.0 >> >> > > -- > Kees Cook Thanks, Al ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 22:36 ` Alexander Lobakin @ 2021-01-06 23:26 ` Kees Cook 2021-01-07 11:59 ` Alexander Lobakin 0 siblings, 1 reply; 15+ messages in thread From: Kees Cook @ 2021-01-06 23:26 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel, Sami Tolvanen On Wed, Jan 06, 2021 at 10:36:38PM +0000, Alexander Lobakin wrote: > From: Kees Cook <keescook@chromium.org> > Date: Wed, 6 Jan 2021 14:07:07 -0800 > > > On Wed, Jan 06, 2021 at 08:08:19PM +0000, Alexander Lobakin wrote: > >> Discard GNU attributes at link time as kernel doesn't use it at all. > >> Solves a dozen of the following ld warnings (one per every file): > >> > >> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > >> from `arch/mips/kernel/head.o' being placed in section > >> `.gnu.attributes' > >> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > >> from `init/main.o' being placed in section `.gnu.attributes' > >> > >> Misc: sort DISCARDS section entries alphabetically. > > > > Hmm, I wonder what is causing the appearance of .eh_frame? With help I > > tracked down all the causes of this on x86, arm, and arm64, so that's > > why it's not in the asm-generic DISCARDS section. I suspect this could > > be cleaned up for mips too? > > I could take a look and hunt it down. Could you please give some refs on > what were the causes and solutions for the mentioned architectures? Sure! Here are the ones I could find again: 34b4a5c54c42 ("arm64/kernel: Remove needless Call Frame Information annotations") 6e0a66d10c5b ("arm64/build: Remove .eh_frame* sections due to unwind tables") d1c0272bc1c0 ("x86/boot/compressed: Remove, discard, or assert for unwanted sections") > > Similarly for .gnu.attributes. What is generating that? (Or, more > > specifically, why is it both being generated AND discarded?) > > On my setup, GNU Attributes consist of MIPS FP type (soft) and > (if I'm correct) MIPS GNU Hash tables. Ah, right, the soft-float markings sound correct to discard, IIUC. > By the way. I've built the kernel with LLVM stack (and found several > subjects for more patches) and, besides '.got', also got a fistful > of '.data..compoundliteral*' symbols (drivers/mtd/nand/spi/, > net/ipv6/ etc). Where should they be placed (rodata, rwdata, ...) > or they are anomalies of some kind and should be fixed somehow? Ah yeah, I've seen this before: https://lore.kernel.org/lkml/202010051345.2Q0cvqdM-lkp@intel.com/ https://lore.kernel.org/lkml/CAKwvOd=s53vUELe311VSjxt2_eQd+RGNCf__n+cV+R=PQ_CdXQ@mail.gmail.com/ And it looks like LTO trips over it too: https://lore.kernel.org/lkml/20201211184633.3213045-3-samitolvanen@google.com/ So I think the correct solution is to follow Sami's patch and add it to vmlinux.lds.h: -#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX* +#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* ... -#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* -#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* +#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* +#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral* Can you include a patch for this in your series? Thanks! -- Kees Cook ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 23:26 ` Kees Cook @ 2021-01-07 11:59 ` Alexander Lobakin 0 siblings, 0 replies; 15+ messages in thread From: Alexander Lobakin @ 2021-01-07 11:59 UTC (permalink / raw) To: Kees Cook Cc: Alexander Lobakin, Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel, Sami Tolvanen From: Kees Cook <keescook@chromium.org> Date: Wed, 6 Jan 2021 15:26:18 -0800 > On Wed, Jan 06, 2021 at 10:36:38PM +0000, Alexander Lobakin wrote: >> From: Kees Cook <keescook@chromium.org> >> Date: Wed, 6 Jan 2021 14:07:07 -0800 >> >>> On Wed, Jan 06, 2021 at 08:08:19PM +0000, Alexander Lobakin wrote: >>>> Discard GNU attributes at link time as kernel doesn't use it at all. >>>> Solves a dozen of the following ld warnings (one per every file): >>>> >>>> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' >>>> from `arch/mips/kernel/head.o' being placed in section >>>> `.gnu.attributes' >>>> mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' >>>> from `init/main.o' being placed in section `.gnu.attributes' >>>> >>>> Misc: sort DISCARDS section entries alphabetically. >>> >>> Hmm, I wonder what is causing the appearance of .eh_frame? With help I >>> tracked down all the causes of this on x86, arm, and arm64, so that's >>> why it's not in the asm-generic DISCARDS section. I suspect this could >>> be cleaned up for mips too? >> >> I could take a look and hunt it down. Could you please give some refs on >> what were the causes and solutions for the mentioned architectures? > > Sure! Here are the ones I could find again: > > 34b4a5c54c42 ("arm64/kernel: Remove needless Call Frame Information annotations") > 6e0a66d10c5b ("arm64/build: Remove .eh_frame* sections due to unwind tables") > d1c0272bc1c0 ("x86/boot/compressed: Remove, discard, or assert for unwanted sections") > >>> Similarly for .gnu.attributes. What is generating that? (Or, more >>> specifically, why is it both being generated AND discarded?) >> >> On my setup, GNU Attributes consist of MIPS FP type (soft) and >> (if I'm correct) MIPS GNU Hash tables. > > Ah, right, the soft-float markings sound correct to discard, IIUC. > >> By the way. I've built the kernel with LLVM stack (and found several >> subjects for more patches) and, besides '.got', also got a fistful >> of '.data..compoundliteral*' symbols (drivers/mtd/nand/spi/, >> net/ipv6/ etc). Where should they be placed (rodata, rwdata, ...) >> or they are anomalies of some kind and should be fixed somehow? > > Ah yeah, I've seen this before: > https://lore.kernel.org/lkml/202010051345.2Q0cvqdM-lkp@intel.com/ > https://lore.kernel.org/lkml/CAKwvOd=s53vUELe311VSjxt2_eQd+RGNCf__n+cV+R=PQ_CdXQ@mail.gmail.com/ > > And it looks like LTO trips over it too: > https://lore.kernel.org/lkml/20201211184633.3213045-3-samitolvanen@google.com/ > > So I think the correct solution is to follow Sami's patch and add it to > vmlinux.lds.h: > > -#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX* > +#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* > ... > -#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* > -#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* > +#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* > +#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral* > > Can you include a patch for this in your series? > > Thanks! Thanks for the help! Hope now I caught them all properly in v3. > -- > Kees Cook Al ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS 2021-01-06 22:07 ` Kees Cook 2021-01-06 22:36 ` Alexander Lobakin @ 2021-01-06 22:43 ` Fāng-ruì Sòng 1 sibling, 0 replies; 15+ messages in thread From: Fāng-ruì Sòng @ 2021-01-06 22:43 UTC (permalink / raw) To: Alexander Lobakin Cc: Kees Cook, Thomas Bogendoerfer, Nathan Chancellor, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, # 3.4.x, LKML On Wed, Jan 6, 2021 at 2:07 PM Kees Cook <keescook@chromium.org> wrote: > > On Wed, Jan 06, 2021 at 08:08:19PM +0000, Alexander Lobakin wrote: > > Discard GNU attributes at link time as kernel doesn't use it at all. > > Solves a dozen of the following ld warnings (one per every file): > > > > mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > > from `arch/mips/kernel/head.o' being placed in section > > `.gnu.attributes' > > mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes' > > from `init/main.o' being placed in section `.gnu.attributes' > > > > Misc: sort DISCARDS section entries alphabetically. > > Hmm, I wonder what is causing the appearance of .eh_frame? With help I > tracked down all the causes of this on x86, arm, and arm64, so that's > why it's not in the asm-generic DISCARDS section. I suspect this could > be cleaned up for mips too? On x86, 003602ad5516e59940de42e44c8d8033387bb363 "x86/*/Makefile: Use -fno-asynchronous-unwind-tables to suppress .eh_frame sections" noticed that some Makefiles redefined KBUILD_CFLAGS and dropped -fno-asynchronous-unwind-tables. Maybe mips has similar issues. > Similarly for .gnu.attributes. What is generating that? (Or, more > specifically, why is it both being generated AND discarded?) > > -Kees gcc/config/mips/mips.c https://github.com/gcc-mirror/gcc/blob/master/gcc/config/mips/mips.c#L9965 .gnu_attribute 4, 0 does not produce .gnu.attributes (SHT_GNU_ATTRIBUTES) but there are likely code paths that a non-zero value is used... So .gnu_attributes is likely needed to be excluded. > > > > Signed-off-by: Alexander Lobakin <alobakin@pm.me> > > --- > > arch/mips/kernel/vmlinux.lds.S | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S > > index 83e27a181206..5d6563970ab2 100644 > > --- a/arch/mips/kernel/vmlinux.lds.S > > +++ b/arch/mips/kernel/vmlinux.lds.S > > @@ -221,9 +221,10 @@ SECTIONS > > /* ABI crap starts here */ > > *(.MIPS.abiflags) > > *(.MIPS.options) > > + *(.eh_frame) > > + *(.gnu.attributes) > > *(.options) > > *(.pdr) > > *(.reginfo) > > - *(.eh_frame) > > } > > } > > -- > > 2.30.0 > > > > > > -- > Kees Cook -- 宋方睿 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin @ 2021-01-06 20:08 ` Alexander Lobakin 2021-01-06 20:21 ` Fāng-ruì Sòng ` (2 more replies) 2021-01-06 20:08 ` [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin 2021-01-06 22:07 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Kees Cook 3 siblings, 3 replies; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:08 UTC (permalink / raw) To: Thomas Bogendoerfer Cc: Alexander Lobakin, Nathan Chancellor, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn or .rela.dyn and check for these sections to be zero-sized at link time. At least two of them were noticed in real builds: mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' from `init/main.o' being placed in section `.rel.dyn' ld.lld: warning: <internal>:(.got) is being placed in '.got' Adopted from x86/kernel/vmlinux.lds.S. Reported-by: Nathan Chancellor <natechancellor@gmail.com> # .got Suggested-by: Fangrui Song <maskray@google.com> # .rel.dyn Signed-off-by: Alexander Lobakin <alobakin@pm.me> --- arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 5d6563970ab2..05eda9d9a7d5 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -227,4 +227,39 @@ SECTIONS *(.pdr) *(.reginfo) } + + /* + * Sections that should stay zero sized, which is safer to + * explicitly check instead of blindly discarding. + */ + + .got : { + *(.got) + *(.igot.*) + } + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") + + .got.plt (INFO) : { + *(.got.plt) + } + ASSERT(SIZEOF(.got.plt) == 0, "Unexpected GOT/PLT entries detected!") + + .plt : { + *(.plt) + *(.plt.*) + *(.iplt) + } + ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") + + .rel.dyn : { + *(.rel.*) + *(.rel_*) + } + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") + + .rela.dyn : { + *(.rela.*) + *(.rela_*) + } + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") } -- 2.30.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin @ 2021-01-06 20:21 ` Fāng-ruì Sòng 2021-01-06 20:23 ` Nathan Chancellor 2021-01-06 20:28 ` Alexander Lobakin 2 siblings, 0 replies; 15+ messages in thread From: Fāng-ruì Sòng @ 2021-01-06 20:21 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Nathan Chancellor, Kees Cook, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, # 3.4.x, LKML On Wed, Jan 6, 2021 at 12:08 PM Alexander Lobakin <alobakin@pm.me> wrote: > > Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn > or .rela.dyn and check for these sections to be zero-sized > at link time. > > At least two of them were noticed in real builds: > > mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' > from `init/main.o' being placed in section `.rel.dyn' > > ld.lld: warning: <internal>:(.got) is being placed in '.got' > > Adopted from x86/kernel/vmlinux.lds.S. > > Reported-by: Nathan Chancellor <natechancellor@gmail.com> # .got > Suggested-by: Fangrui Song <maskray@google.com> # .rel.dyn > Signed-off-by: Alexander Lobakin <alobakin@pm.me> > --- > arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S > index 5d6563970ab2..05eda9d9a7d5 100644 > --- a/arch/mips/kernel/vmlinux.lds.S > +++ b/arch/mips/kernel/vmlinux.lds.S > @@ -227,4 +227,39 @@ SECTIONS > *(.pdr) > *(.reginfo) > } > + > + /* > + * Sections that should stay zero sized, which is safer to > + * explicitly check instead of blindly discarding. > + */ > + > + .got : { > + *(.got) > + *(.igot.*) > + } > + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") > + > + .got.plt (INFO) : { > + *(.got.plt) > + } > + ASSERT(SIZEOF(.got.plt) == 0, "Unexpected GOT/PLT entries detected!") (INFO) drops the SHF_ALLOC flag from the output section (It does not mean "informational"). INFO is not need here. The diff from 815d680771ae09080d2da83dac2647c08cdf99ce "x86/build: Enforce an empty .got.plt section" is not needed. > + .plt : { > + *(.plt) > + *(.plt.*) > + *(.iplt) > + } > + ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") > + > + .rel.dyn : { > + *(.rel.*) > + *(.rel_*) > + } > + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") > + > + .rela.dyn : { > + *(.rela.*) > + *(.rela_*) > + } > + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") > } x86 has both .rel.dyn and .rela.dyn because i386 psABI uses REL while x86-64 psABI uses RELA, but mips does not need .rela.dyn > -- > 2.30.0 > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin 2021-01-06 20:21 ` Fāng-ruì Sòng @ 2021-01-06 20:23 ` Nathan Chancellor 2021-01-06 20:28 ` Alexander Lobakin 2 siblings, 0 replies; 15+ messages in thread From: Nathan Chancellor @ 2021-01-06 20:23 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel On Wed, Jan 06, 2021 at 08:08:29PM +0000, Alexander Lobakin wrote: > Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn > or .rela.dyn and check for these sections to be zero-sized > at link time. > > At least two of them were noticed in real builds: > > mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' > from `init/main.o' being placed in section `.rel.dyn' > > ld.lld: warning: <internal>:(.got) is being placed in '.got' > > Adopted from x86/kernel/vmlinux.lds.S. > > Reported-by: Nathan Chancellor <natechancellor@gmail.com> # .got > Suggested-by: Fangrui Song <maskray@google.com> # .rel.dyn > Signed-off-by: Alexander Lobakin <alobakin@pm.me> > --- > arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S > index 5d6563970ab2..05eda9d9a7d5 100644 > --- a/arch/mips/kernel/vmlinux.lds.S > +++ b/arch/mips/kernel/vmlinux.lds.S > @@ -227,4 +227,39 @@ SECTIONS > *(.pdr) > *(.reginfo) > } > + > + /* > + * Sections that should stay zero sized, which is safer to > + * explicitly check instead of blindly discarding. > + */ > + > + .got : { > + *(.got) > + *(.igot.*) > + } > + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") This assertion does trigger now. $ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- LLVM=1 \ O=out/mipsel distclean malta_kvm_guest_defconfig all ... ld.lld: error: Unexpected GOT entries detected! ld.lld: error: Unexpected GOT entries detected! ... > + .got.plt (INFO) : { > + *(.got.plt) > + } > + ASSERT(SIZEOF(.got.plt) == 0, "Unexpected GOT/PLT entries detected!") > + > + .plt : { > + *(.plt) > + *(.plt.*) > + *(.iplt) > + } > + ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") > + > + .rel.dyn : { > + *(.rel.*) > + *(.rel_*) > + } > + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") > + > + .rela.dyn : { > + *(.rela.*) > + *(.rela_*) > + } > + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") > } > -- > 2.30.0 > > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin 2021-01-06 20:21 ` Fāng-ruì Sòng 2021-01-06 20:23 ` Nathan Chancellor @ 2021-01-06 20:28 ` Alexander Lobakin 2 siblings, 0 replies; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:28 UTC (permalink / raw) To: Nathan Chancellor Cc: Alexander Lobakin, Thomas Bogendoerfer, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel From: Nathan Chancellor <natechancellor@gmail.com> Date: Wed, 6 Jan 2021 13:23:24 -0700 On Wed, Jan 06, 2021 at 08:08:29PM +0000, Alexander Lobakin wrote: >> Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn >> or .rela.dyn and check for these sections to be zero-sized >> at link time. >> >> At least two of them were noticed in real builds: >> >> mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' >> from `init/main.o' being placed in section `.rel.dyn' >> >> ld.lld: warning: <internal>:(.got) is being placed in '.got' >> >> Adopted from x86/kernel/vmlinux.lds.S. >> >> Reported-by: Nathan Chancellor <natechancellor@gmail.com> # .got >> Suggested-by: Fangrui Song <maskray@google.com> # .rel.dyn >> Signed-off-by: Alexander Lobakin <alobakin@pm.me> >> --- >> arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ >> 1 file changed, 35 insertions(+) >> >> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S >> index 5d6563970ab2..05eda9d9a7d5 100644 >> --- a/arch/mips/kernel/vmlinux.lds.S >> +++ b/arch/mips/kernel/vmlinux.lds.S >> @@ -227,4 +227,39 @@ SECTIONS >> *(.pdr) >> *(.reginfo) >> } >> + >> + /* >> + * Sections that should stay zero sized, which is safer to >> + * explicitly check instead of blindly discarding. >> + */ >> + >> + .got : { >> + *(.got) >> + *(.igot.*) >> + } >> + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") > > This assertion does trigger now. > > $ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- LLVM=1 \ > O=out/mipsel distclean malta_kvm_guest_defconfig all > ... > ld.lld: error: Unexpected GOT entries detected! > ld.lld: error: Unexpected GOT entries detected! > ... Oops. I'll build my kernel with LLVM stack and dig into it deeper tomorrow. >> + .got.plt (INFO) : { >> + *(.got.plt) >> + } >> + ASSERT(SIZEOF(.got.plt) == 0, "Unexpected GOT/PLT entries detected!") >> + >> + .plt : { >> + *(.plt) >> + *(.plt.*) >> + *(.iplt) >> + } >> + ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") >> + >> + .rel.dyn : { >> + *(.rel.*) >> + *(.rel_*) >> + } >> + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") >> + >> + .rela.dyn : { >> + *(.rela.*) >> + *(.rela_*) >> + } >> + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") >> } >> -- >> 2.30.0 Thanks, Al ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin @ 2021-01-06 20:08 ` Alexander Lobakin 2021-01-06 22:07 ` Kees Cook 2021-01-06 22:07 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Kees Cook 3 siblings, 1 reply; 15+ messages in thread From: Alexander Lobakin @ 2021-01-06 20:08 UTC (permalink / raw) To: Thomas Bogendoerfer Cc: Alexander Lobakin, Nathan Chancellor, Kees Cook, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel Now, after that all the sections are explicitly described and declared in vmlinux.lds.S, we can enable ld orphan warnings to prevent from missing any new sections in future. Signed-off-by: Alexander Lobakin <alobakin@pm.me> --- arch/mips/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index d68df1febd25..d3e64cc0932b 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -18,6 +18,7 @@ config MIPS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_WANT_LD_ORPHAN_WARN select BUILDTIME_TABLE_SORT select CLONE_BACKWARDS select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1) -- 2.30.0 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN 2021-01-06 20:08 ` [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin @ 2021-01-06 22:07 ` Kees Cook 0 siblings, 0 replies; 15+ messages in thread From: Kees Cook @ 2021-01-06 22:07 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel On Wed, Jan 06, 2021 at 08:08:46PM +0000, Alexander Lobakin wrote: > Now, after that all the sections are explicitly described and > declared in vmlinux.lds.S, we can enable ld orphan warnings to > prevent from missing any new sections in future. > > Signed-off-by: Alexander Lobakin <alobakin@pm.me> Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin ` (2 preceding siblings ...) 2021-01-06 20:08 ` [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin @ 2021-01-06 22:07 ` Kees Cook 3 siblings, 0 replies; 15+ messages in thread From: Kees Cook @ 2021-01-06 22:07 UTC (permalink / raw) To: Alexander Lobakin Cc: Thomas Bogendoerfer, Nathan Chancellor, Fangrui Song, Jiaxun Yang, Alex Smith, Ralf Baechle, Markos Chandras, linux-mips, stable, linux-kernel On Wed, Jan 06, 2021 at 08:08:14PM +0000, Alexander Lobakin wrote: > MIPS uses its own declaration of rwdata, and thus it should be kept > in sync with the asm-generic one. Currently PAGE_ALIGNED_DATA() is > missing from the linker script, which emits the following ld > warnings: > > mips-alpine-linux-musl-ld: warning: orphan section > `.data..page_aligned' from `arch/mips/kernel/vdso.o' being placed > in section `.data..page_aligned' > mips-alpine-linux-musl-ld: warning: orphan section > `.data..page_aligned' from `arch/mips/vdso/vdso-image.o' being placed > in section `.data..page_aligned' > > Add the necessary declaration, so the mentioned structures will be > placed in vmlinux as intended: > > ffffffff80630580 D __end_once > ffffffff80630580 D __start___dyndbg > ffffffff80630580 D __start_once > ffffffff80630580 D __stop___dyndbg > ffffffff80634000 d mips_vdso_data > ffffffff80638000 d vdso_data > ffffffff80638580 D _gp > ffffffff8063c000 T __init_begin > ffffffff8063c000 D _edata > ffffffff8063c000 T _sinittext > > -> > > ffffffff805a4000 D __end_init_task > ffffffff805a4000 D __nosave_begin > ffffffff805a4000 D __nosave_end > ffffffff805a4000 d mips_vdso_data > ffffffff805a8000 d vdso_data > ffffffff805ac000 D mmlist_lock > ffffffff805ac080 D tasklist_lock > > Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO") > Cc: stable@vger.kernel.org # 4.4+ > Signed-off-by: Alexander Lobakin <alobakin@pm.me> Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-01-07 12:00 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-06 20:07 [PATCH v2 mips-next 0/4] MIPS: vmlinux.lds.S sections fix & cleanup Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 2/4] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin 2021-01-06 22:07 ` Kees Cook 2021-01-06 22:36 ` Alexander Lobakin 2021-01-06 23:26 ` Kees Cook 2021-01-07 11:59 ` Alexander Lobakin 2021-01-06 22:43 ` Fāng-ruì Sòng 2021-01-06 20:08 ` [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Alexander Lobakin 2021-01-06 20:21 ` Fāng-ruì Sòng 2021-01-06 20:23 ` Nathan Chancellor 2021-01-06 20:28 ` Alexander Lobakin 2021-01-06 20:08 ` [PATCH v2 mips-next 4/4] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin 2021-01-06 22:07 ` Kees Cook 2021-01-06 22:07 ` [PATCH v2 mips-next 1/4] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Kees Cook
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).