Message ID | 20200629061840.4065483-15-keescook@chromium.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Warn on orphan section placement | expand |
On Sun, Jun 28, 2020 at 11:18:37PM -0700, Kees Cook wrote: > We don't want to depend on the linker's orphan section placement > heuristics as these can vary between linkers, and may change between > versions. All sections need to be explicitly named in the linker > script. > > Specifically, this would have made a recently fixed bug very obvious: > > ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' > > Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. > > Add missing text stub sections .vfp11_veneer and .v4_bx. > > Add debug sections explicitly. > > Finally enable orphan section warning. This is unrelated to this patch as such, but I noticed that ARM32/64 places the .got section inside .text -- is that expected on ARM?
On Mon, Jun 29, 2020 at 11:54:01AM -0400, Arvind Sankar wrote: > On Sun, Jun 28, 2020 at 11:18:37PM -0700, Kees Cook wrote: > > We don't want to depend on the linker's orphan section placement > > heuristics as these can vary between linkers, and may change between > > versions. All sections need to be explicitly named in the linker > > script. > > > > Specifically, this would have made a recently fixed bug very obvious: > > > > ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' > > > > Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. > > > > Add missing text stub sections .vfp11_veneer and .v4_bx. > > > > Add debug sections explicitly. > > > > Finally enable orphan section warning. > > This is unrelated to this patch as such, but I noticed that ARM32/64 places > the .got section inside .text -- is that expected on ARM? Do you mean in general, in the kernel vmlinux, in the decompressor vmlinux or ... ?
On Mon, Jun 29, 2020 at 07:07:04PM +0100, Russell King - ARM Linux admin wrote: > On Mon, Jun 29, 2020 at 11:54:01AM -0400, Arvind Sankar wrote: > > On Sun, Jun 28, 2020 at 11:18:37PM -0700, Kees Cook wrote: > > > We don't want to depend on the linker's orphan section placement > > > heuristics as these can vary between linkers, and may change between > > > versions. All sections need to be explicitly named in the linker > > > script. > > > > > > Specifically, this would have made a recently fixed bug very obvious: > > > > > > ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' > > > > > > Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. > > > > > > Add missing text stub sections .vfp11_veneer and .v4_bx. > > > > > > Add debug sections explicitly. > > > > > > Finally enable orphan section warning. > > > > This is unrelated to this patch as such, but I noticed that ARM32/64 places > > the .got section inside .text -- is that expected on ARM? > > Do you mean in general, in the kernel vmlinux, in the decompressor > vmlinux or ... ? > Sorry, in the kernel vmlinux. ARM_TEXT includes *(.got) for 32-bit, and the 64-bit vmlinux.lds.S includes it in .text as well. The decompressor for 32-bit keeps it separate for non-EFI stub kernel and puts it inside .data for EFI stub.
On Mon, Jun 29, 2020 at 02:15:14PM -0400, Arvind Sankar wrote: > On Mon, Jun 29, 2020 at 07:07:04PM +0100, Russell King - ARM Linux admin wrote: > > On Mon, Jun 29, 2020 at 11:54:01AM -0400, Arvind Sankar wrote: > > > On Sun, Jun 28, 2020 at 11:18:37PM -0700, Kees Cook wrote: > > > > We don't want to depend on the linker's orphan section placement > > > > heuristics as these can vary between linkers, and may change between > > > > versions. All sections need to be explicitly named in the linker > > > > script. > > > > > > > > Specifically, this would have made a recently fixed bug very obvious: > > > > > > > > ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' > > > > > > > > Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. > > > > > > > > Add missing text stub sections .vfp11_veneer and .v4_bx. > > > > > > > > Add debug sections explicitly. > > > > > > > > Finally enable orphan section warning. > > > > > > This is unrelated to this patch as such, but I noticed that ARM32/64 places > > > the .got section inside .text -- is that expected on ARM? > > > > Do you mean in general, in the kernel vmlinux, in the decompressor > > vmlinux or ... ? > > > > Sorry, in the kernel vmlinux. ARM_TEXT includes *(.got) for 32-bit, and > the 64-bit vmlinux.lds.S includes it in .text as well. The decompressor > for 32-bit keeps it separate for non-EFI stub kernel and puts it inside > .data for EFI stub. The main 32-bit kernel image doesn't use the .got - I don't think it actually even exists. The decompressor (non-EFI) uses the .got as a way of getting position independence, and that must be part of the binary image at a fixed offset from the .text section. The decompressor self-fixes up the GOT entries. In the case of the decompressor being flashed and executed from NOR flash, the decompressor must be built for the specific address(es) that it will reside (which does away with the .got table.) For EFI, it needs to be in the .data section (which is in that case always a fixed offset from .text) so that it can be written to so the fix-ups work.
On Sun, Jun 28, 2020 at 11:18 PM Kees Cook <keescook@chromium.org> wrote: > > We don't want to depend on the linker's orphan section placement > heuristics as these can vary between linkers, and may change between > versions. All sections need to be explicitly named in the linker > script. > > Specifically, this would have made a recently fixed bug very obvious: > > ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' > > Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. > > Add missing text stub sections .vfp11_veneer and .v4_bx. > > Add debug sections explicitly. > > Finally enable orphan section warning. > > Signed-off-by: Kees Cook <keescook@chromium.org> Thanks for following up on the previous suggestion regarding .glu_7 / .glu_7t ordering. LGTM Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> > --- > arch/arm/include/asm/vmlinux.lds.h | 6 +++++- > arch/arm/kernel/vmlinux-xip.lds.S | 1 + > arch/arm/kernel/vmlinux.lds.S | 1 + > 3 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/include/asm/vmlinux.lds.h b/arch/arm/include/asm/vmlinux.lds.h > index c66b16cd8837..d44fae722e7a 100644 > --- a/arch/arm/include/asm/vmlinux.lds.h > +++ b/arch/arm/include/asm/vmlinux.lds.h > @@ -39,6 +39,8 @@ > __idmap_text_end = .; \ > > #define ARM_COMMON_DISCARD \ > + *(.iplt) *(.rel.iplt) *(.igot.plt) \ > + *(.modinfo) \ > *(.discard) \ > *(.discard.*) > > @@ -63,7 +65,9 @@ > #define ARM_STUBS_TEXT \ > *(.gnu.warning) \ > *(.glue_7) \ > - *(.glue_7t) > + *(.glue_7t) \ > + *(.vfp11_veneer) \ > + *(.v4_bx) > > #define ARM_TEXT \ > IDMAP_TEXT \ > diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S > index 57fcbf55f913..11ffa79751da 100644 > --- a/arch/arm/kernel/vmlinux-xip.lds.S > +++ b/arch/arm/kernel/vmlinux-xip.lds.S > @@ -150,6 +150,7 @@ SECTIONS > _end = .; > > STABS_DEBUG > + DWARF_DEBUG > ARM_DETAILS > } > > diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S > index 1d3d3b599635..dc672fe35de3 100644 > --- a/arch/arm/kernel/vmlinux.lds.S > +++ b/arch/arm/kernel/vmlinux.lds.S > @@ -149,6 +149,7 @@ SECTIONS > _end = .; > > STABS_DEBUG > + DWARF_DEBUG > ARM_DETAILS > } > > -- > 2.25.1 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200629061840.4065483-15-keescook%40chromium.org.
diff --git a/arch/arm/include/asm/vmlinux.lds.h b/arch/arm/include/asm/vmlinux.lds.h index c66b16cd8837..d44fae722e7a 100644 --- a/arch/arm/include/asm/vmlinux.lds.h +++ b/arch/arm/include/asm/vmlinux.lds.h @@ -39,6 +39,8 @@ __idmap_text_end = .; \ #define ARM_COMMON_DISCARD \ + *(.iplt) *(.rel.iplt) *(.igot.plt) \ + *(.modinfo) \ *(.discard) \ *(.discard.*) @@ -63,7 +65,9 @@ #define ARM_STUBS_TEXT \ *(.gnu.warning) \ *(.glue_7) \ - *(.glue_7t) + *(.glue_7t) \ + *(.vfp11_veneer) \ + *(.v4_bx) #define ARM_TEXT \ IDMAP_TEXT \ diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 57fcbf55f913..11ffa79751da 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -150,6 +150,7 @@ SECTIONS _end = .; STABS_DEBUG + DWARF_DEBUG ARM_DETAILS } diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 1d3d3b599635..dc672fe35de3 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -149,6 +149,7 @@ SECTIONS _end = .; STABS_DEBUG + DWARF_DEBUG ARM_DETAILS }
We don't want to depend on the linker's orphan section placement heuristics as these can vary between linkers, and may change between versions. All sections need to be explicitly named in the linker script. Specifically, this would have made a recently fixed bug very obvious: ld: warning: orphan section `.fixup' from `arch/arm/lib/copy_from_user.o' being placed in section `.fixup' Discard unneeded sections .iplt, .rel.iplt, .igot.plt, and .modinfo. Add missing text stub sections .vfp11_veneer and .v4_bx. Add debug sections explicitly. Finally enable orphan section warning. Signed-off-by: Kees Cook <keescook@chromium.org> --- arch/arm/include/asm/vmlinux.lds.h | 6 +++++- arch/arm/kernel/vmlinux-xip.lds.S | 1 + arch/arm/kernel/vmlinux.lds.S | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)