* [PATCH v2] selftests: exec: make binaries position independent
@ 2024-04-16 15:28 Muhammad Usama Anjum
2024-04-16 17:28 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-16 15:28 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Shuah Khan, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt,
Muhammad Usama Anjum, Andrew Morton, Yang Yingliang
Cc: kernel, linux-mm, linux-kselftest, linux-kernel, llvm
The -static overrides the -pie and binaries aren't position independent
anymore. Use -static-pie instead which would produce a static and
position independent binary. This has been caught by clang's warnings:
clang: warning: argument unused during compilation: '-pie'
[-Wunused-command-line-argument]
Tested with both gcc and clang after this change.
Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
Changes since v1:
- Remove unneeded comment
---
tools/testing/selftests/exec/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile
index fb4472ddffd81..3c79ec9bf780f 100644
--- a/tools/testing/selftests/exec/Makefile
+++ b/tools/testing/selftests/exec/Makefile
@@ -29,8 +29,8 @@ $(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
cp $< $@
chmod -x $@
$(OUTPUT)/load_address_4096: load_address.c
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000 -pie -static $< -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000 -static-pie $< -o $@
$(OUTPUT)/load_address_2097152: load_address.c
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x200000 -pie -static $< -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x200000 -static-pie $< -o $@
$(OUTPUT)/load_address_16777216: load_address.c
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000000 -pie -static $< -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-z,max-page-size=0x1000000 -static-pie $< -o $@
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] selftests: exec: make binaries position independent
2024-04-16 15:28 [PATCH v2] selftests: exec: make binaries position independent Muhammad Usama Anjum
@ 2024-04-16 17:28 ` Kees Cook
2024-05-06 23:30 ` Fangrui Song
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2024-04-16 17:28 UTC (permalink / raw)
To: Muhammad Usama Anjum
Cc: Eric Biederman, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Andrew Morton, Yang Yingliang,
kernel, linux-mm, linux-kselftest, linux-kernel, llvm
On Tue, Apr 16, 2024 at 08:28:29PM +0500, Muhammad Usama Anjum wrote:
> The -static overrides the -pie and binaries aren't position independent
> anymore. Use -static-pie instead which would produce a static and
> position independent binary. This has been caught by clang's warnings:
>
> clang: warning: argument unused during compilation: '-pie'
> [-Wunused-command-line-argument]
>
> Tested with both gcc and clang after this change.
>
> Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Thanks for this!
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] selftests: exec: make binaries position independent
2024-04-16 17:28 ` Kees Cook
@ 2024-05-06 23:30 ` Fangrui Song
2024-05-07 0:05 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Fangrui Song @ 2024-05-06 23:30 UTC (permalink / raw)
To: Kees Cook, Muhammad Usama Anjum
Cc: Eric Biederman, Shuah Khan, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, Andrew Morton, Yang Yingliang,
kernel, linux-mm, linux-kselftest, linux-kernel, llvm
On Tue, Apr 16, 2024 at 10:28 AM Kees Cook <keescook@chromium.org> wrote:
>
> On Tue, Apr 16, 2024 at 08:28:29PM +0500, Muhammad Usama Anjum wrote:
> > The -static overrides the -pie and binaries aren't position independent
> > anymore. Use -static-pie instead which would produce a static and
> > position independent binary. This has been caught by clang's warnings:
> >
> > clang: warning: argument unused during compilation: '-pie'
> > [-Wunused-command-line-argument]
> >
> > Tested with both gcc and clang after this change.
> >
> > Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
> > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>
> Thanks for this!
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> --
> Kees Cook
GCC versions before 8.1 do not support -static-pie,
while https://www.kernel.org/doc/html/next/process/changes.html says
the minimal version is GCC 5.1.
Is this a problem?
If not, and CFLAGS is guaranteed to include -fpie/-fpic/-fPIE/-fPIC
(PIC), using -static-pie looks good to me.
--
宋方睿
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] selftests: exec: make binaries position independent
2024-05-06 23:30 ` Fangrui Song
@ 2024-05-07 0:05 ` Kees Cook
2024-05-07 0:14 ` Fangrui Song
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2024-05-07 0:05 UTC (permalink / raw)
To: Fangrui Song
Cc: Muhammad Usama Anjum, John Hubbard, Eric Biederman, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Andrew Morton, Yang Yingliang, kernel, linux-mm, linux-kselftest,
linux-kernel, llvm
On Mon, May 06, 2024 at 04:30:27PM -0700, Fangrui Song wrote:
> On Tue, Apr 16, 2024 at 10:28 AM Kees Cook <keescook@chromium.org> wrote:
> >
> > On Tue, Apr 16, 2024 at 08:28:29PM +0500, Muhammad Usama Anjum wrote:
> > > The -static overrides the -pie and binaries aren't position independent
> > > anymore. Use -static-pie instead which would produce a static and
> > > position independent binary. This has been caught by clang's warnings:
> > >
> > > clang: warning: argument unused during compilation: '-pie'
> > > [-Wunused-command-line-argument]
> > >
> > > Tested with both gcc and clang after this change.
> > >
> > > Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
> > > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> >
> > Thanks for this!
> >
> > Reviewed-by: Kees Cook <keescook@chromium.org>
> >
> > --
> > Kees Cook
>
> GCC versions before 8.1 do not support -static-pie,
> while https://www.kernel.org/doc/html/next/process/changes.html says
> the minimal version is GCC 5.1.
> Is this a problem?
>
> If not, and CFLAGS is guaranteed to include -fpie/-fpic/-fPIE/-fPIC
> (PIC), using -static-pie looks good to me.
Should we use this alternative, which may be more portable?
https://lore.kernel.org/all/20240504022301.35250-1-jhubbard@nvidia.com/
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] selftests: exec: make binaries position independent
2024-05-07 0:05 ` Kees Cook
@ 2024-05-07 0:14 ` Fangrui Song
2024-05-07 0:23 ` John Hubbard
0 siblings, 1 reply; 6+ messages in thread
From: Fangrui Song @ 2024-05-07 0:14 UTC (permalink / raw)
To: Kees Cook
Cc: Muhammad Usama Anjum, John Hubbard, Eric Biederman, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Andrew Morton, Yang Yingliang, kernel, linux-mm, linux-kselftest,
linux-kernel, llvm
On Mon, May 6, 2024 at 5:05 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Mon, May 06, 2024 at 04:30:27PM -0700, Fangrui Song wrote:
> > On Tue, Apr 16, 2024 at 10:28 AM Kees Cook <keescook@chromium.org> wrote:
> > >
> > > On Tue, Apr 16, 2024 at 08:28:29PM +0500, Muhammad Usama Anjum wrote:
> > > > The -static overrides the -pie and binaries aren't position independent
> > > > anymore. Use -static-pie instead which would produce a static and
> > > > position independent binary. This has been caught by clang's warnings:
> > > >
> > > > clang: warning: argument unused during compilation: '-pie'
> > > > [-Wunused-command-line-argument]
> > > >
> > > > Tested with both gcc and clang after this change.
> > > >
> > > > Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
> > > > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> > >
> > > Thanks for this!
> > >
> > > Reviewed-by: Kees Cook <keescook@chromium.org>
> > >
> > > --
> > > Kees Cook
> >
> > GCC versions before 8.1 do not support -static-pie,
> > while https://www.kernel.org/doc/html/next/process/changes.html says
> > the minimal version is GCC 5.1.
> > Is this a problem?
> >
> > If not, and CFLAGS is guaranteed to include -fpie/-fpic/-fPIE/-fPIC
> > (PIC), using -static-pie looks good to me.
>
> Should we use this alternative, which may be more portable?
> https://lore.kernel.org/all/20240504022301.35250-1-jhubbard@nvidia.com/
>
> -Kees
s/-fPIE -static/-static/ then it looks good to me:)
-static creates a position-dependent executable.
It doesn't matter whether the compiler uses -fno-pic/-fpie/-fpic
codegen, so -fPIE can be removed.
--
宋方睿
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] selftests: exec: make binaries position independent
2024-05-07 0:14 ` Fangrui Song
@ 2024-05-07 0:23 ` John Hubbard
0 siblings, 0 replies; 6+ messages in thread
From: John Hubbard @ 2024-05-07 0:23 UTC (permalink / raw)
To: Fangrui Song, Kees Cook
Cc: Muhammad Usama Anjum, Eric Biederman, Shuah Khan,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Andrew Morton, Yang Yingliang, kernel, linux-mm, linux-kselftest,
linux-kernel, llvm
On 5/6/24 5:14 PM, Fangrui Song wrote:
> On Mon, May 6, 2024 at 5:05 PM Kees Cook <keescook@chromium.org> wrote:
>>
>> On Mon, May 06, 2024 at 04:30:27PM -0700, Fangrui Song wrote:
>>> On Tue, Apr 16, 2024 at 10:28 AM Kees Cook <keescook@chromium.org> wrote:
>>>>
>>>> On Tue, Apr 16, 2024 at 08:28:29PM +0500, Muhammad Usama Anjum wrote:
>>>>> The -static overrides the -pie and binaries aren't position independent
>>>>> anymore. Use -static-pie instead which would produce a static and
>>>>> position independent binary. This has been caught by clang's warnings:
>>>>>
>>>>> clang: warning: argument unused during compilation: '-pie'
>>>>> [-Wunused-command-line-argument]
>>>>>
>>>>> Tested with both gcc and clang after this change.
>>>>>
>>>>> Fixes: 4d1cd3b2c5c1 ("tools/testing/selftests/exec: fix link error")
>>>>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>>>>
>>>> Thanks for this!
>>>>
>>>> Reviewed-by: Kees Cook <keescook@chromium.org>
>>>>
>>>> --
>>>> Kees Cook
>>>
>>> GCC versions before 8.1 do not support -static-pie,
>>> while https://www.kernel.org/doc/html/next/process/changes.html says
>>> the minimal version is GCC 5.1.
>>> Is this a problem?
>>>
>>> If not, and CFLAGS is guaranteed to include -fpie/-fpic/-fPIE/-fPIC
>>> (PIC), using -static-pie looks good to me.
>>
>> Should we use this alternative, which may be more portable?
>> https://lore.kernel.org/all/20240504022301.35250-1-jhubbard@nvidia.com/
>>
>> -Kees
>
> s/-fPIE -static/-static/ then it looks good to me:)
hmm, maybe that is better, considering that -static-pie is relatively
new (as you pointed out in the other thread), and would break the
minimum kernel gcc version requirements.
>
> -static creates a position-dependent executable.
> It doesn't matter whether the compiler uses -fno-pic/-fpie/-fpic
> codegen, so -fPIE can be removed.
>
This is something I'd have to take your word for. The whole PIE
story not completely clear to me, but if you're sure it is not
required here, then of course leaving it out entirely works nicely...
thanks,
--
John Hubbard
NVIDIA
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-07 0:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16 15:28 [PATCH v2] selftests: exec: make binaries position independent Muhammad Usama Anjum
2024-04-16 17:28 ` Kees Cook
2024-05-06 23:30 ` Fangrui Song
2024-05-07 0:05 ` Kees Cook
2024-05-07 0:14 ` Fangrui Song
2024-05-07 0:23 ` John Hubbard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox