[PATCH] lkdtm: support llvm-objcopy

0 views
Skip to first unread message

Nick Desaulniers

unread,
May 13, 2019, 6:21:34 PM5/13/19
to kees...@chromium.org, clang-bu...@googlegroups.com, Nick Desaulniers, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, linux-...@vger.kernel.org
With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
llvm-objcopy: error: --set-section-flags=.text conflicts with
--rename-section=.text=.rodata

Rather than support setting flags then renaming sections vs renaming
then setting flags, it's simpler to just change both at the same time
via --rename-section.

This can be verified with:
$ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
...
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000004 0000000000000000 A 0 0 4
...

Which shows in the Flags field that .text is now renamed .rodata, the
append flag A is set, and the section is not flagged as writeable W.

Link: https://github.com/ClangBuiltLinux/linux/issues/448
Reported-by: Nathan Chancellor <nathan...@gmail.com>
Suggested-by: Jordan Rupprect <rupp...@google.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
drivers/misc/lkdtm/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
index 951c984de61a..89dee2a9d88c 100644
--- a/drivers/misc/lkdtm/Makefile
+++ b/drivers/misc/lkdtm/Makefile
@@ -15,8 +15,7 @@ KCOV_INSTRUMENT_rodata.o := n

OBJCOPYFLAGS :=
OBJCOPYFLAGS_rodata_objcopy.o := \
- --set-section-flags .text=alloc,readonly \
- --rename-section .text=.rodata
+ --rename-section .text=.rodata,alloc,readonly
targets += rodata.o rodata_objcopy.o
$(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE
$(call if_changed,objcopy)
--
2.21.0.1020.gf2820cf01a-goog

Nick Desaulniers

unread,
May 13, 2019, 6:26:19 PM5/13/19
to Kees Cook, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
On Mon, May 13, 2019 at 3:21 PM Nick Desaulniers
<ndesau...@google.com> wrote:
>
> With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
> llvm-objcopy: error: --set-section-flags=.text conflicts with
> --rename-section=.text=.rodata
>
> Rather than support setting flags then renaming sections vs renaming
> then setting flags, it's simpler to just change both at the same time
> via --rename-section.
>
> This can be verified with:
> $ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
> ...
> Section Headers:
> [Nr] Name Type Address Offset
> Size EntSize Flags Link Info Align
> ...
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000004 0000000000000000 A 0 0 4
> ...
>
> Which shows in the Flags field that .text is now renamed .rodata, the
> append flag A is set, and the section is not flagged as writeable W.

Probably should've been:
Which shows that .text is now renamed .rodata, the
append flag A is set, and the section is not flagged as writeable W.

--
Thanks,
~Nick Desaulniers

Kees Cook

unread,
May 13, 2019, 7:04:05 PM5/13/19
to Greg Kroah-Hartman, clang-bu...@googlegroups.com, Nick Desaulniers, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, linux-...@vger.kernel.org
On Mon, May 13, 2019 at 03:21:09PM -0700, Nick Desaulniers wrote:
> With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
> llvm-objcopy: error: --set-section-flags=.text conflicts with
> --rename-section=.text=.rodata
>
> Rather than support setting flags then renaming sections vs renaming
> then setting flags, it's simpler to just change both at the same time
> via --rename-section.
>
> This can be verified with:
> $ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
> ...
> Section Headers:
> [Nr] Name Type Address Offset
> Size EntSize Flags Link Info Align
> ...
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000004 0000000000000000 A 0 0 4
> ...
>
> Which shows in the Flags field that .text is now renamed .rodata, the
> append flag A is set, and the section is not flagged as writeable W.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/448
> Reported-by: Nathan Chancellor <nathan...@gmail.com>
> Suggested-by: Jordan Rupprect <rupp...@google.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Thanks! This looks good. Greg, can you please take this for drivers/misc?

Acked-by: Kees Cook <kees...@chromium.org>

-Kees

> ---
> drivers/misc/lkdtm/Makefile | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
> index 951c984de61a..89dee2a9d88c 100644
> --- a/drivers/misc/lkdtm/Makefile
> +++ b/drivers/misc/lkdtm/Makefile
> @@ -15,8 +15,7 @@ KCOV_INSTRUMENT_rodata.o := n
>
> OBJCOPYFLAGS :=
> OBJCOPYFLAGS_rodata_objcopy.o := \
> - --set-section-flags .text=alloc,readonly \
> - --rename-section .text=.rodata
> + --rename-section .text=.rodata,alloc,readonly
> targets += rodata.o rodata_objcopy.o
> $(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE
> $(call if_changed,objcopy)
> --
> 2.21.0.1020.gf2820cf01a-goog
>

--
Kees Cook

Nathan Chancellor

unread,
May 13, 2019, 7:29:14 PM5/13/19
to Nick Desaulniers, kees...@chromium.org, clang-bu...@googlegroups.com, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, linux-...@vger.kernel.org
On Mon, May 13, 2019 at 03:21:09PM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
> llvm-objcopy: error: --set-section-flags=.text conflicts with
> --rename-section=.text=.rodata
>
> Rather than support setting flags then renaming sections vs renaming
> then setting flags, it's simpler to just change both at the same time
> via --rename-section.
>
> This can be verified with:
> $ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
> ...
> Section Headers:
> [Nr] Name Type Address Offset
> Size EntSize Flags Link Info Align
> ...
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000004 0000000000000000 A 0 0 4
> ...
>
> Which shows in the Flags field that .text is now renamed .rodata, the
> append flag A is set, and the section is not flagged as writeable W.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/448
> Reported-by: Nathan Chancellor <nathan...@gmail.com>

This should be natecha...@gmail.com (although I think I do own that
email, just haven't been into it for 10+ years...)

> Suggested-by: Jordan Rupprect <rupp...@google.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>
> ---
> drivers/misc/lkdtm/Makefile | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
> index 951c984de61a..89dee2a9d88c 100644
> --- a/drivers/misc/lkdtm/Makefile
> +++ b/drivers/misc/lkdtm/Makefile
> @@ -15,8 +15,7 @@ KCOV_INSTRUMENT_rodata.o := n
>
> OBJCOPYFLAGS :=
> OBJCOPYFLAGS_rodata_objcopy.o := \
> - --set-section-flags .text=alloc,readonly \
> - --rename-section .text=.rodata
> + --rename-section .text=.rodata,alloc,readonly
> targets += rodata.o rodata_objcopy.o
> $(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE
> $(call if_changed,objcopy)
> --
> 2.21.0.1020.gf2820cf01a-goog
>

I ran this script to see if there was any change for GNU objcopy and it
looks like .rodata's type gets changed, is this intentional? Otherwise,
this works for llvm-objcopy like you show.

-----------

1c1
< There are 11 section headers, starting at offset 0x240:
---
> There are 11 section headers, starting at offset 0x230:
8c8
< [ 1] .rodata PROGBITS 0000000000000000 00000040
---
> [ 1] .rodata NOBITS 0000000000000000 00000040
10c10

-----------

#!/bin/bash

TMP1=$(mktemp)
TMP2=$(mktemp)

git checkout next-20190513

make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=out mrproper allyesconfig drivers/misc/lkdtm/
readelf -S out/drivers/misc/lkdtm/rodata_objcopy.o > ${TMP1}

curl -LSs https://lore.kernel.org/lkml/20190513222109.110...@google.com/raw | git am -3

make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=out mrproper allyesconfig drivers/misc/lkdtm/
readelf -S out/drivers/misc/lkdtm/rodata_objcopy.o > ${TMP2}

diff ${TMP1} ${TMP2}

Jordan Rupprecht

unread,
May 13, 2019, 7:39:23 PM5/13/19
to Nathan Chancellor, Nick Desaulniers, kees...@chromium.org, clang-bu...@googlegroups.com, Nathan Chancellor, Arnd Bergmann, Greg Kroah-Hartman, LKML
Nathan: is your version of llvm-objcopy later than r359639 (April 30)?

Nathan Chancellor

unread,
May 13, 2019, 7:47:21 PM5/13/19
to Jordan Rupprecht, Nick Desaulniers, kees...@chromium.org, clang-bu...@googlegroups.com, Nathan Chancellor, Arnd Bergmann, Greg Kroah-Hartman, LKML
Hi Jordan,

Yes but that output was purely with GNU objcopy (checking section
headers before and after this patch). This is the section header
for llvm-objcopy after this patch:

[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000004 0000000000000000 A 0 0 4

Cheers,
Nathan

Nick Desaulniers

unread,
May 13, 2019, 7:50:18 PM5/13/19
to Nathan Chancellor, Kees Cook, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
Sorry, I should have looked it up. I'll just fix this, my earlier
mistake, and collect Kee's reviewed by tag in a v2 sent directly to
GKH.
Interesting find. the .rodata of vmlinux itself is marked PROGBITS,
so its curious that GNU binutils changes the "Type" after the rename.
I doubt the code in question relies on NOBITS for this section. Kees,
can you clarify? Jordan, do you know what the differences are between
PROGBITS vs NOBITS?
https://people.redhat.com/mpolacek/src/devconf2012.pdf seems to
suggest NOBITS zero initializes data but I'm not sure that's what this
code wants.

>
> -----------
>
> #!/bin/bash
>
> TMP1=$(mktemp)
> TMP2=$(mktemp)
>
> git checkout next-20190513
>
> make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=out mrproper allyesconfig drivers/misc/lkdtm/
> readelf -S out/drivers/misc/lkdtm/rodata_objcopy.o > ${TMP1}
>
> curl -LSs https://lore.kernel.org/lkml/20190513222109.110...@google.com/raw | git am -3
>
> make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=out mrproper allyesconfig drivers/misc/lkdtm/
> readelf -S out/drivers/misc/lkdtm/rodata_objcopy.o > ${TMP2}
>
> diff ${TMP1} ${TMP2}



--
Thanks,
~Nick Desaulniers

Kees Cook

unread,
May 14, 2019, 2:11:02 PM5/14/19
to Nick Desaulniers, Nathan Chancellor, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
> mistake, and collect Kees's reviewed by tag in a v2 sent directly to
> GKH.

Sounds good.

> > I ran this script to see if there was any change for GNU objcopy and it
> > looks like .rodata's type gets changed, is this intentional? Otherwise,
> > this works for llvm-objcopy like you show.
> >
> > -----------
> >
> > 1c1
> > < There are 11 section headers, starting at offset 0x240:
> > ---
> > > There are 11 section headers, starting at offset 0x230:
> > 8c8
> > < [ 1] .rodata PROGBITS 0000000000000000 00000040
> > ---
> > > [ 1] .rodata NOBITS 0000000000000000 00000040
> > 10c10

Oh, very good catch; thank you!

>
> Interesting find. the .rodata of vmlinux itself is marked PROGBITS,
> so its curious that GNU binutils changes the "Type" after the rename.
> I doubt the code in question relies on NOBITS for this section. Kees,
> can you clarify? Jordan, do you know what the differences are between
> PROGBITS vs NOBITS?
> https://people.redhat.com/mpolacek/src/devconf2012.pdf seems to
> suggest NOBITS zero initializes data but I'm not sure that's what this
> code wants.

Yes, the linker treats this as a zeroed section. My testing only checked that the NX protection check kicked, but in looking at the memory, the failure mode wouldn't have returned, because it got zeroed instead of seeing a "ret":

Before the patch (with a two-byte target dump added):

lkdtm: attempting bad execution at ffffffff986db2b0
lkdtm: f3 c3

After the patch:

lkdtm: attempting bad execution at ffffffff986db2b0
lkdtm: 00 00

So, yes, this breaks the fall-back case and should not be used. It seems
that objcopy BFD breaks the PROGBITS in this case, but llvm-objcopy
does not...

$ objcopy --set-section-flags .text=alloc,readonly --rename-section .text=.rodata rodata.o rodata_objcopy.o
$ readelf -S rodata_objcopy.o | grep -A1 \.rodata
[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000002 0000000000000000 A 0 0 16

$ objcopy --rename-section .text=.rodata,alloc,readonly rodata.o rodata_objcopy.o
$ readelf -S rodata_objcopy.o | grep -A1 \.rodata
[ 1] .rodata NOBITS 0000000000000000 00000040
0000000000000002 0000000000000000 A 0 0 16

$ llvm-objcopy --rename-section .text=.rodata,alloc,readonly rodata.o rodata_objcopy-llvm.o
$ readelf -S rodata_objcopy-llvm.o | grep -A1 \.rodata
[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000002 0000000000000000 A 0 0 16


llvm-objcopy doesn't like doing both arguments at the same time,
and BFD gets it wrong when using the appended flags. How about just a
two-stage copy, like this?

diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
index 951c984de61a..715832c844c8 100644
--- a/drivers/misc/lkdtm/Makefile
+++ b/drivers/misc/lkdtm/Makefile
@@ -14,9 +14,12 @@ KASAN_SANITIZE_stackleak.o := n
KCOV_INSTRUMENT_rodata.o := n

OBJCOPYFLAGS :=
+OBJCOPYFLAGS_rodata_flags.o := \
+ --set-section-flags .text=alloc,readonly
OBJCOPYFLAGS_rodata_objcopy.o := \
- --set-section-flags .text=alloc,readonly \
--rename-section .text=.rodata
-targets += rodata.o rodata_objcopy.o
-$(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE
+targets += rodata.o rodata_flags.o rodata_objcopy.o
+$(obj)/rodata_flags.o: $(obj)/rodata.o FORCE
+ $(call if_changed,objcopy)
+$(obj)/rodata_objcopy.o: $(obj)/rodata_flags.o FORCE
$(call if_changed,objcopy)


--
Kees Cook

Nick Desaulniers

unread,
May 14, 2019, 4:24:50 PM5/14/19
to Kees Cook, Nathan Chancellor, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
I'm not sure I want to call it a bug in the initial implementation. I've filed:
https://sourceware.org/bugzilla/show_bug.cgi?id=24554 for
clarification. Jordan, I hope you can participate in any discussion
there?

>
> $ objcopy --set-section-flags .text=alloc,readonly --rename-section .text=.rodata rodata.o rodata_objcopy.o
> $ readelf -S rodata_objcopy.o | grep -A1 \.rodata
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000002 0000000000000000 A 0 0 16
>
> $ objcopy --rename-section .text=.rodata,alloc,readonly rodata.o rodata_objcopy.o
> $ readelf -S rodata_objcopy.o | grep -A1 \.rodata
> [ 1] .rodata NOBITS 0000000000000000 00000040
> 0000000000000002 0000000000000000 A 0 0 16
>
> $ llvm-objcopy --rename-section .text=.rodata,alloc,readonly rodata.o rodata_objcopy-llvm.o
> $ readelf -S rodata_objcopy-llvm.o | grep -A1 \.rodata
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000002 0000000000000000 A 0 0 16
>
>
> llvm-objcopy doesn't like doing both arguments at the same time,
> and BFD gets it wrong when using the appended flags. How about just a
> two-stage copy, like this?

Yeah, I think this should work. What you wrote above + the link the
bug I just filed would go well in a commit message, along with:
Reviewed-by: Nick Desaulniers <ndesau...@google.com>

>
> diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
> index 951c984de61a..715832c844c8 100644
> --- a/drivers/misc/lkdtm/Makefile
> +++ b/drivers/misc/lkdtm/Makefile
> @@ -14,9 +14,12 @@ KASAN_SANITIZE_stackleak.o := n
> KCOV_INSTRUMENT_rodata.o := n
>
> OBJCOPYFLAGS :=
> +OBJCOPYFLAGS_rodata_flags.o := \
> + --set-section-flags .text=alloc,readonly
> OBJCOPYFLAGS_rodata_objcopy.o := \
> - --set-section-flags .text=alloc,readonly \
> --rename-section .text=.rodata
> -targets += rodata.o rodata_objcopy.o
> -$(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE
> +targets += rodata.o rodata_flags.o rodata_objcopy.o
> +$(obj)/rodata_flags.o: $(obj)/rodata.o FORCE
> + $(call if_changed,objcopy)
> +$(obj)/rodata_objcopy.o: $(obj)/rodata_flags.o FORCE
> $(call if_changed,objcopy)
>
>
> --
> Kees Cook
>
> --
> 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-li...@googlegroups.com.
> To post to this group, send email to clang-bu...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/201905141041.C38DA1B305%40keescook.
> For more options, visit https://groups.google.com/d/optout.



--
Thanks,
~Nick Desaulniers

Kees Cook

unread,
May 15, 2019, 12:42:58 PM5/15/19
to Nick Desaulniers, Nathan Chancellor, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
On Tue, May 14, 2019 at 01:24:37PM -0700, Nick Desaulniers wrote:
> On Tue, May 14, 2019 at 11:11 AM Kees Cook <kees...@chromium.org> wrote:
> >
> > On Mon, May 13, 2019 at 04:50:05PM -0700, Nick Desaulniers wrote:
> > > On Mon, May 13, 2019 at 4:29 PM Nathan Chancellor
> > > <natecha...@gmail.com> wrote:
> > > >
> > > > On Mon, May 13, 2019 at 03:21:09PM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> > > > > With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
> > > > > llvm-objcopy: error: --set-section-flags=.text conflicts with
> > > > > --rename-section=.text=.rodata
> > > > >
> > > > > Rather than support setting flags then renaming sections vs renaming
> > > > > then setting flags, it's simpler to just change both at the same time
> > > > > via --rename-section.
>
> I'm not sure I want to call it a bug in the initial implementation. I've filed:
> https://sourceware.org/bugzilla/show_bug.cgi?id=24554 for
> clarification. Jordan, I hope you can participate in any discussion
> there?

Based on the hint from Alan Modra, it seems PROGBITS/NOBITS can be
controlled with the presence/absence of the "load" section flag. This
appears to work for both BFD and LLVM:

$ objcopy --rename-section .text=.rodata,alloc,readonly,load rodata.o rodata_objcopy.o
$ readelf -WS rodata_objcopy.o | grep \.rodata
[ 1] .rodata PROGBITS 0000000000000000 000040 000002 00 A 0 0 16

$ llvm-objcopy --rename-section .text=.rodata,alloc,readonly,load rodata.o rodata_objcopy.o
$ readelf -WS rodata_objcopy.o | grep \.rodata
[ 1] .rodata PROGBITS 0000000000000000 000040 000002 00 A 0 0 16

So, that's an easy change that could be folded into the original version
of this patch (no need for my two-phase work-around).

--
Kees Cook

Nick Desaulniers

unread,
May 15, 2019, 1:37:45 PM5/15/19
to Kees Cook, Nathan Chancellor, clang-built-linux, Nathan Chancellor, Jordan Rupprect, Arnd Bergmann, Greg Kroah-Hartman, LKML
Ah, yes that's better. I'll fold that into a v2 and resend shortly.
I'm going to carry your Ack from earlier, please let me know offlist
if that's not appropriate.
--
Thanks,
~Nick Desaulniers

Nick Desaulniers

unread,
May 15, 2019, 2:12:09 PM5/15/19
to gre...@linuxfoundation.org, clang-bu...@googlegroups.com, Nick Desaulniers, sta...@vger.kernel.org, Nathan Chancellor, Alan Modra, Jordan Rupprect, Kees Cook, Arnd Bergmann, linux-...@vger.kernel.org
With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
llvm-objcopy: error: --set-section-flags=.text conflicts with
--rename-section=.text=.rodata

Rather than support setting flags then renaming sections vs renaming
then setting flags, it's simpler to just change both at the same time
via --rename-section. Adding the load flag is required for GNU objcopy
to mark .rodata Type as PROGBITS after the rename.

This can be verified with:
$ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
...
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000004 0000000000000000 A 0 0 4
...

Which shows that .text is now renamed .rodata, the alloc flag A is set,
the type is PROGBITS, and the section is not flagged as writeable W.

Cc: sta...@vger.kernel.org
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=24554
Suggested-by: Alan Modra <amo...@gmail.com>
Suggested-by: Jordan Rupprect <rupp...@google.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Acked-by: Kees Cook <kees...@chromium.org>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Changes from v1 -> v2:
* add load flag, as per Kees and Alan.
* update commit message to mention reason for load flag.
* add Kees' and Alan's suggested by.
* carry Kees' Ack.
* cc stable.

drivers/misc/lkdtm/Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
index 951c984de61a..fb10eafe9bde 100644
--- a/drivers/misc/lkdtm/Makefile
+++ b/drivers/misc/lkdtm/Makefile
@@ -15,8 +15,7 @@ KCOV_INSTRUMENT_rodata.o := n

OBJCOPYFLAGS :=
OBJCOPYFLAGS_rodata_objcopy.o := \
- --set-section-flags .text=alloc,readonly \
- --rename-section .text=.rodata
+ --rename-section .text=.rodata,alloc,readonly,load

Nathan Chancellor

unread,
May 15, 2019, 2:19:12 PM5/15/19
to Nick Desaulniers, gre...@linuxfoundation.org, clang-bu...@googlegroups.com, sta...@vger.kernel.org, Nathan Chancellor, Alan Modra, Jordan Rupprect, Kees Cook, Arnd Bergmann, linux-...@vger.kernel.org
On Wed, May 15, 2019 at 11:12:04AM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
> llvm-objcopy: error: --set-section-flags=.text conflicts with
> --rename-section=.text=.rodata
>
> Rather than support setting flags then renaming sections vs renaming
> then setting flags, it's simpler to just change both at the same time
> via --rename-section. Adding the load flag is required for GNU objcopy
> to mark .rodata Type as PROGBITS after the rename.
>
> This can be verified with:
> $ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
> ...
> Section Headers:
> [Nr] Name Type Address Offset
> Size EntSize Flags Link Info Align
> ...
> [ 1] .rodata PROGBITS 0000000000000000 00000040
> 0000000000000004 0000000000000000 A 0 0 4
> ...
>
> Which shows that .text is now renamed .rodata, the alloc flag A is set,
> the type is PROGBITS, and the section is not flagged as writeable W.
>
> Cc: sta...@vger.kernel.org
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=24554
> Link: https://github.com/ClangBuiltLinux/linux/issues/448
> Reported-by: Nathan Chancellor <nathan...@gmail.com>

Doesn't look like this got updated. I don't want to make you send a v3
just for that though since it's purely cosmetic and adding my tag below
will ensure I get copied on any backports and such.

> Suggested-by: Alan Modra <amo...@gmail.com>
> Suggested-by: Jordan Rupprect <rupp...@google.com>
> Suggested-by: Kees Cook <kees...@chromium.org>
> Acked-by: Kees Cook <kees...@chromium.org>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nick Desaulniers

unread,
May 15, 2019, 2:24:50 PM5/15/19
to gre...@linuxfoundation.org, clang-bu...@googlegroups.com, Nick Desaulniers, sta...@vger.kernel.org, Nathan Chancellor, Alan Modra, Jordan Rupprect, Kees Cook, Arnd Bergmann, linux-...@vger.kernel.org
With CONFIG_LKDTM=y and make OBJCOPY=llvm-objcopy, llvm-objcopy errors:
llvm-objcopy: error: --set-section-flags=.text conflicts with
--rename-section=.text=.rodata

Rather than support setting flags then renaming sections vs renaming
then setting flags, it's simpler to just change both at the same time
via --rename-section. Adding the load flag is required for GNU objcopy
to mark .rodata Type as PROGBITS after the rename.

This can be verified with:
$ readelf -S drivers/misc/lkdtm/rodata_objcopy.o
...
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[ 1] .rodata PROGBITS 0000000000000000 00000040
0000000000000004 0000000000000000 A 0 0 4
...

Which shows that .text is now renamed .rodata, the alloc flag A is set,
the type is PROGBITS, and the section is not flagged as writeable W.

Cc: sta...@vger.kernel.org
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=24554
Link: https://github.com/ClangBuiltLinux/linux/issues/448
Reported-by: Nathan Chancellor <natecha...@gmail.com>
Suggested-by: Alan Modra <amo...@gmail.com>
Suggested-by: Jordan Rupprect <rupp...@google.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Acked-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Changes from v2 -> v3:
* correct Nathan's email address and collect his reviewed by.

Sasha Levin

unread,
May 16, 2019, 8:10:03 PM5/16/19
to Sasha Levin, Nick Desaulniers, gre...@linuxfoundation.org, clang-bu...@googlegroups.com, sta...@vger.kernel.org, sta...@vger.kernel.org
Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v5.1.2, v5.0.16, v4.19.43, v4.14.119, v4.9.176, v4.4.179, v3.18.140.

v5.1.2: Build OK!
v5.0.16: Build OK!
v4.19.43: Build OK!
v4.14.119: Failed to apply! Possible dependencies:
039a1c42058d ("lkdtm: Relocate code to subdirectory")
03f51d4efa22 ("Merge tag 'powerpc-4.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux")
c1807e3f8466 ("powerpc/64: Free up CPU_FTR_ICSWX")

v4.9.176: Failed to apply! Possible dependencies:
039a1c42058d ("lkdtm: Relocate code to subdirectory")
0b46fcdb082c ("MAINTAINERS: Move dma-buf to drm-misc git")
376e5f5449d1 ("MAINTAINERS: add dma-fence* files to Sync File maintainership")
3e1aec4e2c41 ("clk: vc5: Add support for IDT VersaClock 5P49V5923 and 5P49V5933")
6593ccd8002c ("MAINTAINERS: Updating maintainers list for Cisco FNI and SNIC drivers")
7d6f728c677e ("IB/opa-vnic: Virtual Network Interface Controller (VNIC) netdev")
82abbea734d6 ("MAINTAINERS: fix alphabetical ordering")
971d33cb422b ("MAINTAINERS: Add Cavium ThunderX2 entry")
a57ce439505d ("MAINTAINERS: add entry for Denali NAND controller driver")
b8aca0c17e11 ("MAINTAINERS: Revise lpfc maintainers to reflect Broadcom")
bf290f8f98b1 ("MAINTAINERS: bfq: Add Paolo as maintainer for the BFQ I/O scheduler")
c4d7e5101085 ("MAINTAINERS: auxdisplay: Added myself as maintainer for ht16k33 driver")
c5ec903d8e8e ("MAINTAINERS: update Sync File Framework files")
ee0db78d62d8 ("MAINTAINERS: add a maintainer for the Inside Secure crypto driver")
f34b87e486c5 ("[media] MAINTAINERS: add st-delta driver")

v4.4.179: Failed to apply! Possible dependencies:
039a1c42058d ("lkdtm: Relocate code to subdirectory")
0b46fcdb082c ("MAINTAINERS: Move dma-buf to drm-misc git")
376e5f5449d1 ("MAINTAINERS: add dma-fence* files to Sync File maintainership")
490b864ba072 ("MAINTAINERS: Add samsung bus frequency driver entry")
4a66d3fecf65 ("ARC: [plat-eznps] Add eznps platform")
588deb614a0d ("MAINTAINERS: Add ARM ARCHITECTED TIMER entry")
6593ccd8002c ("MAINTAINERS: Updating maintainers list for Cisco FNI and SNIC drivers")
71d298ceff37 ("MAINTAINERS: Add maintainer for ARC PGU display controller")
82abbea734d6 ("MAINTAINERS: fix alphabetical ordering")
91979b9db863 ("stmmac: update MAINTAINERS")
971d33cb422b ("MAINTAINERS: Add Cavium ThunderX2 entry")
a57ce439505d ("MAINTAINERS: add entry for Denali NAND controller driver")
a825eaec8d62 ("MAINTAINERS: use https://linuxtv.org for LinuxTV URLs")
b8aca0c17e11 ("MAINTAINERS: Revise lpfc maintainers to reflect Broadcom")
bf290f8f98b1 ("MAINTAINERS: bfq: Add Paolo as maintainer for the BFQ I/O scheduler")
c483e06506b8 ("MAINTAINERS: add entry for the Sync File Framework")
c4d7e5101085 ("MAINTAINERS: auxdisplay: Added myself as maintainer for ht16k33 driver")
c5a906a56590 ("MAINTAINERS: Add Liviu Dudau as maintainer for ARM HDLCD driver.")
c5ec903d8e8e ("MAINTAINERS: update Sync File Framework files")
f34b87e486c5 ("[media] MAINTAINERS: add st-delta driver")
f94848525679 ("i2c: octeon: thunderx: Add MAINTAINERS entry")

v3.18.140: Failed to apply! Possible dependencies:
039a1c42058d ("lkdtm: Relocate code to subdirectory")
04bd844a03b2 ("[media] bdisp: update MAINTAINERS")
04df25d12394 ("MAINTAINERS: Update amdkfd files")
16423d67936f ("Update MAINTAINERS and CREDITS files with amdkfd info")
220706344373 ("advansys: Check for DMA mapping errors")
23ba8a662349 ("MAINTAINERS: wil6210: new maintainer - Maya Erez")
35ef4a9ebfe3 ("MAINTAINERS: update usnic maintainer contacts")
4863dea3fab0 ("net: Adding support for Cavium ThunderX network controller")
49e7d9df9046 ("MAINTAINERS: Use tabs consistently")
588deb614a0d ("MAINTAINERS: Add ARM ARCHITECTED TIMER entry")
5e9615bfb958 ("net: thunderx: add 64-bit dependency")
6571fb3f8b7f ("advansys: Update to version 3.5 and remove compilation warning")
6593ccd8002c ("MAINTAINERS: Updating maintainers list for Cisco FNI and SNIC drivers")
71d298ceff37 ("MAINTAINERS: Add maintainer for ARC PGU display controller")
82abbea734d6 ("MAINTAINERS: fix alphabetical ordering")
971d33cb422b ("MAINTAINERS: Add Cavium ThunderX2 entry")
b84894c7f088 ("iio: Added Capella cm3232 ambient light sensor driver.")
bc31ec4df58d ("advansys: Remove call to dma_cache_sync()")
bf290f8f98b1 ("MAINTAINERS: bfq: Add Paolo as maintainer for the BFQ I/O scheduler")
c38f6ac74c99 ("MAINTAINERS: add arcnet and take maintainership")
c4d7e5101085 ("MAINTAINERS: auxdisplay: Added myself as maintainer for ht16k33 driver")
c5a906a56590 ("MAINTAINERS: Add Liviu Dudau as maintainer for ARM HDLCD driver.")
c8806b6c9e82 ("snic: driver for Cisco SCSI HBA")
d8130624b06e ("MAINTAINERS: switch to suse.com many-in-one (fwd)")
ef0bbac33dc0 ("MAINTAINERS: add cc2520 driver maintainer")
f21fb3ed364b ("Add support of Cavium Liquidio ethernet adapters")
f34b87e486c5 ("[media] MAINTAINERS: add st-delta driver")
f94848525679 ("i2c: octeon: thunderx: Add MAINTAINERS entry")


How should we proceed with this patch?

--
Thanks,
Sasha

Nathan Chancellor

unread,
May 17, 2019, 12:06:16 AM5/17/19
to Sasha Levin, Nick Desaulniers, gre...@linuxfoundation.org, clang-bu...@googlegroups.com, sta...@vger.kernel.org
On Fri, May 17, 2019 at 12:10:02AM +0000, Sasha Levin wrote:
> Hi,
>
> [This is an automated email]
>
> This commit has been processed because it contains a -stable tag.
> The stable tag indicates that it's relevant for the following trees: all

Nick, the stable tag should probably specify 4.8+ since the commit it
fixes came in during 4.8-rc1.

Cc: sta...@vger.kernel.org # 4.8+

Might also help to add:

Fixes: 9a49a528dcf3 ("lkdtm: add function for testing .rodata section")

>
> The bot has tested the following trees: v5.1.2, v5.0.16, v4.19.43, v4.14.119, v4.9.176, v4.4.179, v3.18.140.
>
> v5.1.2: Build OK!
> v5.0.16: Build OK!
> v4.19.43: Build OK!
> v4.14.119: Failed to apply! Possible dependencies:
> 039a1c42058d ("lkdtm: Relocate code to subdirectory")

However, it will still need a manual backport because of the lack of
this commit. I've attached the current patch backported for reference,
the git am flags '-3 -p4 --directory=drivers/misc' help get it proper
then the conflict is rather easy to resolve.

Thanks,
Nathan

Nathan Chancellor

unread,
May 17, 2019, 12:09:08 AM5/17/19
to Sasha Levin, Nick Desaulniers, gre...@linuxfoundation.org, clang-bu...@googlegroups.com, sta...@vger.kernel.org
On Thu, May 16, 2019 at 09:06:13PM -0700, Nathan Chancellor wrote:
> On Fri, May 17, 2019 at 12:10:02AM +0000, Sasha Levin wrote:
> > Hi,
> >
> > [This is an automated email]
> >
> > This commit has been processed because it contains a -stable tag.
> > The stable tag indicates that it's relevant for the following trees: all
>
> Nick, the stable tag should probably specify 4.8+ since the commit it
> fixes came in during 4.8-rc1.
>
> Cc: sta...@vger.kernel.org # 4.8+
>
> Might also help to add:
>
> Fixes: 9a49a528dcf3 ("lkdtm: add function for testing .rodata section")
>
> >
> > The bot has tested the following trees: v5.1.2, v5.0.16, v4.19.43, v4.14.119, v4.9.176, v4.4.179, v3.18.140.
> >
> > v5.1.2: Build OK!
> > v5.0.16: Build OK!
> > v4.19.43: Build OK!
> > v4.14.119: Failed to apply! Possible dependencies:
> > 039a1c42058d ("lkdtm: Relocate code to subdirectory")
>
> However, it will still need a manual backport because of the lack of
> this commit. I've attached the current patch backported for reference,

Would help if I actually did this... :^)
0001-lkdtm-support-llvm-objcopy.patch
Reply all
Reply to author
Forward
0 new messages