bpf: Simplify alu_limit masking for pointer arithmetic
authorPiotr Krysiuk <piotras@gmail.com>
Tue, 16 Mar 2021 07:26:25 +0000 (08:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Mar 2021 09:43:43 +0000 (10:43 +0100)
commit6a3504bf4006dd903eac93d37cdbad45726272b1
treeef00ef7d3319adf412f12c5a8652a9f37de99b1e
parentac1b87a18c1ffbe3d093000b762121b5aae0a3f9
bpf: Simplify alu_limit masking for pointer arithmetic

commit b5871dca250cd391885218b99cc015aca1a51aea upstream.

Instead of having the mov32 with aux->alu_limit - 1 immediate, move this
operation to retrieve_ptr_limit() instead to simplify the logic and to
allow for subsequent sanity boundary checks inside retrieve_ptr_limit().
This avoids in future that at the time of the verifier masking rewrite
we'd run into an underflow which would not sign extend due to the nature
of mov32 instruction.

Signed-off-by: Piotr Krysiuk <piotras@gmail.com>
Co-developed-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/bpf/verifier.c