From: Edward Cree <ecree.xilinx@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf v1 0/2] Fix map value pruning check
Date: Fri, 11 Nov 2022 21:17:10 +0000 [thread overview]
Message-ID: <de18246f-3962-3870-1c72-31a4c9bd4a6d@gmail.com> (raw)
In-Reply-To: <20221111202719.982118-1-memxor@gmail.com>
On 11/11/2022 20:27, Kumar Kartikeya Dwivedi wrote:
> However, looking more closely, it seems to me that the logic of
> check_ids is broken as well.
>
> Edward, given you introduced the idmap, can you provide a little more
> historical context on what the idea behind check_ids was, since it seems
> to be doing the wrong thing as far as I understood things. I think we
> need to compare the ids directly everywhere.
reg->id has two different kinds of usage/semantics. One, which was
the only one when idmap was introduced, is pairing with other regs
within state (including stack slots and caller frames); for this,
check_ids() is fine (the comment above it explains why).
The other, added by d83525ca62cf ("bpf: introduce bpf_spin_lock"),
pairs not with other regs' ids but with state->active_spin_lock;
currently states_equal() requires this to be numerically identical
between old and cur, rather than running it through the idmap; this
would appear to be the origin of the bug.
Alexei, is there any valid world in which there's an active_spin_lock
but the corresponding id does not exist anywhere in the state's
regs, stack etc.? If not then I think it suffices to
check_ids(old->active_spin_lock, cur->active_spin_lock,
env->idmap_scratch);
in func_states_equal() of the leaf frame (only leaf frame can be
holding a spinlock), and remove the existing check from
states_equal().
Because what we want to know isn't "Do both of these spinlocks come
from the same original ID derivation", but "do all registers that
hold a value that could be used to unlock the spinlock in the
continuation-to-exit of the old state also hold such a value in the
current state", which means that we want the pair <old_asl, new_asl>
in the idmap when we walk the regs and stack.
While we *could* implement that by requiring IDs to match numerically
as in Kumar's patch, that's needlessly strict and will miss pruning
opportunities.
-ed
prev parent reply other threads:[~2022-11-11 21:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 20:27 [PATCH bpf v1 0/2] Fix map value pruning check Kumar Kartikeya Dwivedi
2022-11-11 20:27 ` [PATCH bpf v1 1/2] bpf: Fix state pruning check for PTR_TO_MAP_VALUE Kumar Kartikeya Dwivedi
2022-11-13 1:58 ` sdf
2022-11-23 21:01 ` Andrii Nakryiko
2022-11-11 20:27 ` [PATCH bpf v1 2/2] selftests/bpf: Add pruning test case for bpf_spin_lock Kumar Kartikeya Dwivedi
2022-11-13 1:59 ` sdf
2022-11-11 21:17 ` Edward Cree [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=de18246f-3962-3870-1c72-31a4c9bd4a6d@gmail.com \
--to=ecree.xilinx@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.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