From: Luis Gerhorst <luis.gerhorst@fau.de>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: 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@fomichev.me>,
Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>,
Puranjay Mohan <puranjay@kernel.org>,
Xu Kuohai <xukuohai@huaweicloud.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Hari Bathini <hbathini@linux.ibm.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Naveen N Rao <naveen@kernel.org>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Mykola Lysenko <mykolal@fb.com>, Shuah Khan <shuah@kernel.org>,
Henriette Herzog <henriette.herzog@rub.de>,
Saket Kumar Bhaskar <skb99@linux.ibm.com>,
Cupertino Miranda <cupertino.miranda@oracle.com>,
Jiayuan Chen <mrpre@163.com>,
Matan Shachnai <m.shachnai@gmail.com>,
Dimitar Kanaliev <dimitar.kanaliev@siteground.com>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>, Daniel Xu <dxu@dxuuu.xyz>,
bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-kselftest@vger.kernel.org, Maximilian Ott <ott@cs.fau.de>,
Milan Stephan <milan.stephan@fau.de>
Subject: Re: [PATCH bpf-next v3 11/11] bpf: Fall back to nospec for sanitization-failures
Date: Wed, 14 May 2025 19:30:50 +0200 [thread overview]
Message-ID: <87ecwr14mt.fsf@fau.de> (raw)
In-Reply-To: <CAP01T76jeSg3W-OyfBfSbAjpEhBr_h8rbS-Hubk6gDdrkeEj_Q@mail.gmail.com> (Kumar Kartikeya Dwivedi's message of "Wed, 14 May 2025 02:47:44 -0400")
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
(including relevant part from other message)
> On Thu, 1 May 2025 at 04:00, Luis Gerhorst <luis.gerhorst@fau.de> wrote:
>
>> +static bool error_recoverable_with_nospec(int err)
>> +{
>> + /* Should only return true for non-fatal errors that are allowed to
>> + * occur during speculative verification. For these we can insert a
>> + * nospec and the program might still be accepted. Do not include
>> + * something like ENOMEM because it is likely to re-occur for the next
>> + * architectural path once it has been recovered-from in all speculative
>> + * paths.
>> + */
>> + return err == -EPERM || err == -EACCES || err == -EINVAL;
>> +}
>
> Why can't we unconditionally do this? So the path with speculation
> that encounters an error (even if EFAULT) is not explored for the
> remaining pushed speculative states. If the error remains regardless
> of speculation normal symbolic execution will encounter it. The
> instructions only explored as part of speculative execution are not
> marked as seen (see: sanitize_mark_insn_seen), so they'll be dead code
> eliminated and the code doesn't reach the JIT, so no "unsafe gadget"
> remains in the program where execution can be steered.
>
> So the simplest thing (without having to reason about these three
> error codes, I'm sure things will get out of sync or we'll miss
> potential candidates) is probably to just unconditionally mark
> cur_aux(env)->nospec.
[...]
> Hm, now looking at this and thinking more about this, I think
> recoverable error logic is probably ok as is.
> Scratch my earlier suggestion about unconditional handling. I guess
> what would be better would be
> handling everything except fatal ones. In case of fatal ones we should
> really quit verification and return.
> We may make partial changes to verifier state / env and try to bail
> out using -ENOMEM and -EFAULT.
> So unconditional continuation would be problematic as we'd act in a
> partial state never meant to be seen.
>
> The logic otherwise looks ok, so:
>
> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Thank you very much for having a look, so then I will leave it as is if
I understand you correctly.
Please let me know if "what would be better would be handling everything
except fatal ones" was meant literally. Such a deny-list approach would
likely be:
return err != -ENOMEM && err != -EFAULT;
I initially decided to limit it to -EPERM, -EACCES, and -EINVAL as I was
relatively confident all their cases were safe to "catch" and because it
already had the desired effect for most real-world programs. However, if
you find the deny-list approach easier to reason about, I can also do
that. In that case, I will review the remaining errors (besides -EPERM,
-EACCES, and -EINVAL) and make sure they can be caught.
Also, thanks for the pointer regarding sanitize_check_bounds() (sorry
for the delay; the message is still on my to-do list). I will address it
in v4 if it is safe or send a separate fix if it is indeed a bug.
next prev parent reply other threads:[~2025-05-14 17:40 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-01 7:35 [PATCH bpf-next v3 00/11] bpf: Mitigate Spectre v1 using barriers Luis Gerhorst
2025-05-01 7:35 ` [PATCH bpf-next v3 01/11] selftests/bpf: Fix caps for __xlated/jited_unpriv Luis Gerhorst
2025-05-01 16:56 ` Kumar Kartikeya Dwivedi
2025-05-01 17:45 ` Eduard Zingerman
2025-05-01 7:35 ` [PATCH bpf-next v3 02/11] bpf: Move insn if/else into do_check_insn() Luis Gerhorst
2025-05-01 18:22 ` Eduard Zingerman
2025-05-05 18:31 ` Luis Gerhorst
2025-05-01 22:06 ` Kumar Kartikeya Dwivedi
2025-05-01 7:35 ` [PATCH bpf-next v3 03/11] bpf: Return -EFAULT on misconfigurations Luis Gerhorst
2025-05-01 22:06 ` Kumar Kartikeya Dwivedi
2025-05-01 7:35 ` [PATCH bpf-next v3 04/11] bpf: Return -EFAULT on internal errors Luis Gerhorst
2025-05-01 22:07 ` Kumar Kartikeya Dwivedi
2025-05-01 7:35 ` [PATCH bpf-next v3 05/11] bpf, arm64, powerpc: Add bpf_jit_bypass_spec_v1/v4() Luis Gerhorst
2025-05-01 22:14 ` Kumar Kartikeya Dwivedi
2025-05-18 10:38 ` Hari Bathini
2025-05-01 7:35 ` [PATCH bpf-next v3 06/11] bpf, arm64, powerpc: Change nospec to include v1 barrier Luis Gerhorst
2025-05-19 7:01 ` Hari Bathini
2025-05-01 7:35 ` [PATCH bpf-next v3 07/11] bpf: Rename sanitize_stack_spill to nospec_result Luis Gerhorst
2025-05-01 22:30 ` Kumar Kartikeya Dwivedi
2025-05-01 7:35 ` [PATCH bpf-next v3 08/11] bpf: Fall back to nospec for Spectre v1 Luis Gerhorst
2025-05-01 23:55 ` Kumar Kartikeya Dwivedi
2025-05-02 18:57 ` Luis Gerhorst
2025-05-14 5:38 ` Kumar Kartikeya Dwivedi
2025-05-01 7:36 ` [PATCH bpf-next v3 09/11] selftests/bpf: Add test for Spectre v1 mitigation Luis Gerhorst
2025-05-14 6:24 ` Kumar Kartikeya Dwivedi
2025-05-01 7:36 ` [PATCH bpf-next v3 10/11] bpf: Allow nospec-protected var-offset stack access Luis Gerhorst
2025-05-02 0:03 ` Kumar Kartikeya Dwivedi
2025-06-03 21:07 ` Luis Gerhorst
2025-05-14 6:28 ` Kumar Kartikeya Dwivedi
2025-05-01 7:36 ` [PATCH bpf-next v3 11/11] bpf: Fall back to nospec for sanitization-failures Luis Gerhorst
2025-05-14 6:47 ` Kumar Kartikeya Dwivedi
2025-05-14 17:30 ` Luis Gerhorst [this message]
2025-05-14 17:34 ` Kumar Kartikeya Dwivedi
2025-05-09 18:40 ` [PATCH bpf-next v3 00/11] bpf: Mitigate Spectre v1 using barriers patchwork-bot+netdevbpf
2025-05-09 18:43 ` Alexei Starovoitov
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=87ecwr14mt.fsf@fau.de \
--to=luis.gerhorst@fau.de \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=cupertino.miranda@oracle.com \
--cc=daniel@iogearbox.net \
--cc=dimitar.kanaliev@siteground.com \
--cc=dxu@dxuuu.xyz \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hbathini@linux.ibm.com \
--cc=henriette.herzog@rub.de \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=m.shachnai@gmail.com \
--cc=maddy@linux.ibm.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=milan.stephan@fau.de \
--cc=mpe@ellerman.id.au \
--cc=mrpre@163.com \
--cc=mykolal@fb.com \
--cc=naveen@kernel.org \
--cc=npiggin@gmail.com \
--cc=ott@cs.fau.de \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=shung-hsi.yu@suse.com \
--cc=skb99@linux.ibm.com \
--cc=song@kernel.org \
--cc=will@kernel.org \
--cc=xukuohai@huaweicloud.com \
--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.