From: Puranjay Mohan <puranjay12@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Ilya Leoshkevich <iii@linux.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
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>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
X86 ML <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Network Development <netdev@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf v2] bpf: verifier: prevent userspace memory access
Date: Thu, 21 Mar 2024 11:48:52 +0000 [thread overview]
Message-ID: <mb61pwmpvst3v.fsf@gmail.com> (raw)
In-Reply-To: <CAADnVQLHrmkJ5p2gEUJkf_CRxq9gv8rcSuBm5GeZ_nUJxQOE0Q@mail.gmail.com>
Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
> On Thu, Mar 21, 2024 at 4:05 AM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>>
>> On Thu, Mar 21, 2024 at 3:11 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
>> >
>> > diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
>> > index e613eebfd349..e61a51a5b4be 100644
>> > --- a/arch/s390/net/bpf_jit_comp.c
>> > +++ b/arch/s390/net/bpf_jit_comp.c
>> > @@ -2691,3 +2691,8 @@ bool bpf_jit_supports_subprog_tailcalls(void)
>> > {
>> > return true;
>> > }
>> > +
>> > +u64 bpf_arch_uaddress_limit(void)
>> > +{
>> > + return -ENOTSUPP;
>> > +}
>>
>> Looks good and should work, but s390 CI is still not happy.
>> Ideas?
>> sock tests were not failing before. So something is going on.
>
> I think I have an explanation.
> -ENOTSUPP and u64... and later:
> u64 uaddress_limit = bpf_arch_uaddress_limit()
> if (uaddress_limit < 0)
>
> I bet the compiler simply removes this check since unsigned cannot
> be negative.
> Odd that there is no compiler warning.
>
> pw-bot: cr
>
Yes, I verified that the compiler is removing this:
if (BPF_CLASS(insn->code) == BPF_LDX &&
a944: 7100047f cmp w3, #0x1
a948: 540013e1 b.ne abc4 <do_misc_fixups+0x66c> // b.any
a94c: 721a041f tst w0, #0xc0
a950: 54fff4e1 b.ne a7ec <do_misc_fixups+0x294> // b.any
u64 uaddress_limit = bpf_arch_uaddress_limit();
a954: b90003e6 str w6, [sp]
a958: 94000000 bl 0 <bpf_arch_uaddress_limit>
*patch++ = BPF_MOV64_REG(BPF_REG_AX, insn->src_reg);
We should do:
if (!uaddress_limit)
goto next_insn;
and in the disabled case return 0 in place of -ENOSUPP.
Doing this adds the check:
if (BPF_CLASS(insn->code) == BPF_LDX &&
a944: 7100047f cmp w3, #0x1
a948: 54001401 b.ne abc8 <do_misc_fixups+0x670> // b.any
a94c: 721a041f tst w0, #0xc0
a950: 54fff4e1 b.ne a7ec <do_misc_fixups+0x294> // b.any
u64 uaddress_limit = bpf_arch_uaddress_limit();
a954: b90003e6 str w6, [sp]
a958: 94000000 bl 0 <bpf_arch_uaddress_limit>
if (!uaddress_limit)
a95c: b4fff020 cbz x0, a760 <do_misc_fixups+0x208>
*patch++ = BPF_MOV64_REG(BPF_REG_AX, insn->src_reg);
I will send v3 with this approach.
Thanks,
Puranjay
prev parent reply other threads:[~2024-03-21 11:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 10:10 [PATCH bpf v2] bpf: verifier: prevent userspace memory access Puranjay Mohan
2024-03-21 11:05 ` Alexei Starovoitov
2024-03-21 11:31 ` Alexei Starovoitov
2024-03-21 11:48 ` Puranjay Mohan [this message]
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=mb61pwmpvst3v.fsf@gmail.com \
--to=puranjay12@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hpa@zytor.com \
--cc=iii@linux.ibm.com \
--cc=jean-philippe@linaro.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.