bpf: Fix ref_obj_id for dynptr data slices in verifier
authorJoanne Koong <joannelkoong@gmail.com>
Tue, 9 Aug 2022 21:40:54 +0000 (14:40 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Aug 2022 01:38:12 +0000 (18:38 -0700)
commit883743422ced8c961ab05dc63ec81b75a4e56052
treeee15ff76a8631132a43ed543c75a373e07aa23db
parenta7be0ab1eb1949f3564739784b4360e1233305f6
bpf: Fix ref_obj_id for dynptr data slices in verifier

When a data slice is obtained from a dynptr (through the bpf_dynptr_data API),
the ref obj id of the dynptr must be found and then associated with the data
slice.

The ref obj id of the dynptr must be found *before* the caller saved regs are
reset. Without this fix, the ref obj id tracking is not correct for
dynptrs that are at an offset from the frame pointer.

Please also note that the data slice's ref obj id must be assigned after the
ret types are parsed, since RET_PTR_TO_ALLOC_MEM-type return regs get
zero-marked.

Fixes: 34d4ef5775f7 ("bpf: Add dynptr data slices")
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20220809214055.4050604-1-joannelkoong@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c