bpf: Fix mask direction swap upon off reg sign change
authorDaniel Borkmann <daniel@iogearbox.net>
Mon, 31 May 2021 18:25:55 +0000 (18:25 +0000)
committerCosmin Tanislav <demonsingur@gmail.com>
Thu, 16 May 2024 07:58:24 +0000 (10:58 +0300)
commita4219df57d07faa102894ca44c2a9d1be15d9829
treef02a9de286bece92ca9e3c673a798307ff804796
parentcdd6c6d61d5d135d9fc087678af2d0408f7733a9
bpf: Fix mask direction swap upon off reg sign change

commit bb01a1bba579b4b1c5566af24d95f1767859771e upstream.

Masking direction as indicated via mask_to_left is considered to be
calculated once and then used to derive pointer limits. Thus, this
needs to be placed into bpf_sanitize_info instead so we can pass it
to sanitize_ptr_alu() call after the pointer move. Piotr noticed a
corner case where the off reg causes masking direction change which
then results in an incorrect final aux->alu_limit.

Fixes: 7fedb63a8307 ("bpf: Tighten speculative pointer arithmetic mask")
Reported-by: Piotr Krysiuk <piotras@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Piotr Krysiuk <piotras@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/bpf/verifier.c