bpf: Fix slot type check in check_stack_write_var_off
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Thu, 3 Nov 2022 19:09:53 +0000 (00:39 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:14:08 +0000 (13:14 +0100)
commit3c58c83c6fc8a509b34d8b9d87537a4aa83b32e6
tree65e15b7147bb1da5c335d28d6905e050e914a92c
parentcffa75198ca1489e53b229170cc395ee33afad7e
bpf: Fix slot type check in check_stack_write_var_off

[ Upstream commit f5e477a861e4a20d8a1c5f7a245f3a3c3c376b03 ]

For the case where allow_ptr_leaks is false, code is checking whether
slot type is STACK_INVALID and STACK_SPILL and rejecting other cases.
This is a consequence of incorrectly checking for register type instead
of the slot type (NOT_INIT and SCALAR_VALUE respectively). Fix the
check.

Fixes: 01f810ace9ed ("bpf: Allow variable-offset stack access")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20221103191013.1236066-5-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/verifier.c