bpf: Ensure off_reg has no mixed signed bounds for all types
authorDaniel Borkmann <daniel@iogearbox.net>
Tue, 23 Mar 2021 07:51:02 +0000 (08:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Apr 2021 11:00:59 +0000 (13:00 +0200)
commit589fd9684dfafee37c60abde4ca3c0af723be3b3
treed7d50f52fe176dc83fcd19371ef47593e478a6d9
parentb2df20c0f19f9f4f82fa1b1fdd0c8b22c6fc76b5
bpf: Ensure off_reg has no mixed signed bounds for all types

[ Upstream commit 24c109bb1537c12c02aeed2d51a347b4d6a9b76e ]

The mixed signed bounds check really belongs into retrieve_ptr_limit()
instead of outside of it in adjust_ptr_min_max_vals(). The reason is
that this check is not tied to PTR_TO_MAP_VALUE only, but to all pointer
types that we handle in retrieve_ptr_limit() and given errors from the latter
propagate back to adjust_ptr_min_max_vals() and lead to rejection of the
program, it's a better place to reside to avoid anything slipping through
for future types. The reason why we must reject such off_reg is that we
otherwise would not be able to derive a mask, see details in 9d7eceede769
("bpf: restrict unknown scalars of mixed signed bounds for unprivileged").

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/verifier.c