]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: Ensure reg is PTR_TO_STACK in process_iter_arg
authorTao Lyu <tao.lyu@epfl.ch>
Tue, 3 Dec 2024 00:02:37 +0000 (16:02 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 14 Dec 2024 19:03:16 +0000 (20:03 +0100)
commitbdbf87486dca2c90f4c85301e859c2987e26c6b0
tree17084f410297cf2a0bc36041688204b77f7d7bc7
parentdd9478d54c738e86692b83cc992dc4fb643bcdbf
bpf: Ensure reg is PTR_TO_STACK in process_iter_arg

[ Upstream commit 12659d28615d606b36e382f4de2dd05550d202af ]

Currently, KF_ARG_PTR_TO_ITER handling missed checking the reg->type and
ensuring it is PTR_TO_STACK. Instead of enforcing this in the caller of
process_iter_arg, move the check into it instead so that all callers
will gain the check by default. This is similar to process_dynptr_func.

An existing selftest in verifier_bits_iter.c fails due to this change,
but it's because it was passing a NULL pointer into iter_next helper and
getting an error further down the checks, but probably meant to pass an
uninitialized iterator on the stack (as is done in the subsequent test
below it). We will gain coverage for non-PTR_TO_STACK arguments in later
patches hence just change the declaration to zero-ed stack object.

Fixes: 06accc8779c1 ("bpf: add support for open-coded iterator loops")
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Tao Lyu <tao.lyu@epfl.ch>
[ Kartikeya: move check into process_iter_arg, rewrite commit log ]
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241203000238.3602922-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/progs/verifier_bits_iter.c