From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: Yonghong Song <yhs@meta.com>
Cc: Peter Foley <pefoley2@pefoley.com>,
Eduard Zingerman <eddyz87@gmail.com>,
Quentin Monnet <quentin@isovalent.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, david.faust@oracle.com,
elena.zannoni@oracle.com
Subject: Re: [PATCH] tools: bpf: Disable stack protector
Date: Tue, 17 Jan 2023 17:31:15 +0100 [thread overview]
Message-ID: <87sfg96s30.fsf@oracle.com> (raw)
In-Reply-To: <87bkmx9tw8.fsf@oracle.com> (Jose E. Marchesi's message of "Tue, 17 Jan 2023 14:23:51 +0100")
>> On 1/16/23 2:49 PM, Peter Foley wrote:
>>> On Mon, Jan 16, 2023 at 4:59 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
>>>>
>>>> A bit tangential, but since BPF LLVM backend does not support the
>>>> stack protector (should it?) there is also an option to adjust LLVM
>>>> to avoid this instrumentation, WDYT?
>>>>
>>> That would probably be worth doing, yes.
>>> But given that won't help already released versions of clang, it
>>> should probably happen in addition to this patch.
>>
>> Peter,
>>
>> If I understand correctly (by inspecting clang code), the stack
>> protector is off by default. Do you have link to Gentoo build
>> page to show how they enable stack protector? cmake config or
>> a private patch?
>>
>> Jose,
>>
>> How gcc-bpf handle stack protector? The compiler just disables
>> stack protector for bpf target?
>
> It doesn't. -fstack-protector is disabled by default in GCC. When you
> use it you get something like:
>
> $ echo 'int foo() { char s[256]; return s[3]; }' | bpf-unknown-none-gcc \
> -fstack-protector -S -o foo.s -O2 -xc -
> $ cat foo.s
> .file "<stdin>"
> .text
> .align 3
> .global foo
> .type foo, @function
> foo:
> lddw %r1,__stack_chk_guard
> ldxdw %r0,[%r1+0]
> stxdw [%fp+-8],%r0
> ldxb %r0,[%fp+-261]
> lsh %r0,56
> arsh %r0,56
> ldxdw %r2,[%fp+-8]
> ldxdw %r3,[%r1+0]
> jne %r2,%r3,.L4
> exit
> .L4:
> call __stack_chk_fail
> .size foo, .-foo
> .ident "GCC: (GNU) 12.0.0 20211206 (experimental)"
>
> i.e. it pushes a stack canary and checks it upon function exit, calling
> __stack_chk_fail.
>
> If clang has -fstack-protector ON by default and you change the BPF
> backend in order to ignore the flag, I think we should do the same in
> GCC.
I went ahead and pushed the patch below to GCC master. If
-fstack-protector is ever considered useful in the architecture, we can
always stop disabling it.
I would recommend to change the default for -fstack-protector in clang
to be off by default when targetting BPF targets, and to emit the same
or similar note to the user when the option is enabled explicitly with
-fstack-protector:
note: ‘-fstack-protector’ does not work on this architecture
WDYT?
From 3b81f5c4d8e0d79cbd6927d004185707c14e54b2 Mon Sep 17 00:00:00 2001
Date: Tue, 17 Jan 2023 17:16:32 +0100
Subject: [COMMITTED] bpf: disable -fstack-protector in BPF
The stack protector is not supported in BPF. This patch disables
-fstack-protector in bpf-* targets, along with the emission of a note
indicating that the feature is not supported in this platform.
Regtested in bpf-unknown-none.
gcc/ChangeLog:
* config/bpf/bpf.cc (bpf_option_override): Disable
-fstack-protector.
---
gcc/config/bpf/bpf.cc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc
index 576a1fe8eab..b268801d00c 100644
--- a/gcc/config/bpf/bpf.cc
+++ b/gcc/config/bpf/bpf.cc
@@ -253,6 +253,14 @@ bpf_option_override (void)
if (bpf_has_jmp32 == -1)
bpf_has_jmp32 = (bpf_isa >= ISA_V3);
+ /* Disable -fstack-protector as it is not supported in BPF. */
+ if (flag_stack_protect)
+ {
+ inform (input_location,
+ "%<-fstack-protector%> does not work "
+ " on this architecture");
+ flag_stack_protect = 0;
+ }
}
#undef TARGET_OPTION_OVERRIDE
--
2.30.2
next prev parent reply other threads:[~2023-01-17 16:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-14 23:00 [PATCH] tools: bpf: Disable stack protector Peter Foley
2023-01-16 10:30 ` Quentin Monnet
2023-01-16 12:59 ` Eduard Zingerman
2023-01-16 22:49 ` Peter Foley
2023-01-16 22:53 ` Eduard Zingerman
2023-01-17 7:05 ` Yonghong Song
2023-01-17 7:09 ` Peter Foley
2023-01-17 16:22 ` Yonghong Song
2023-01-17 13:23 ` Jose E. Marchesi
2023-01-17 16:31 ` Jose E. Marchesi [this message]
2023-01-17 17:14 ` Yonghong Song
2023-01-17 17:11 ` Yonghong Song
2023-01-18 19:28 ` Eduard Zingerman
2023-01-19 7:34 ` Yonghong Song
2023-01-23 4:28 ` Peter Foley
2023-01-23 5:22 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfg96s30.fsf@oracle.com \
--to=jose.marchesi@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=david.faust@oracle.com \
--cc=eddyz87@gmail.com \
--cc=elena.zannoni@oracle.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pefoley2@pefoley.com \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=trix@redhat.com \
--cc=yhs@fb.com \
--cc=yhs@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox