Skip to content

Commit 9df5fad

Browse files
deepanshu406Alexei Starovoitov
authored andcommitted
bpf: Reject BPF_MAP_TYPE_INSN_ARRAY in check_reg_const_str()
BPF_MAP_TYPE_INSN_ARRAY maps store instruction pointers in their ips array, not string data. The map_direct_value_addr callback for this map type returns the address of the ips array, which is not suitable for use as a constant string argument. When a BPF program passes a pointer to an insn_array map value as ARG_PTR_TO_CONST_STR (e.g., to bpf_snprintf), the verifier's null-termination check in check_reg_const_str() operates on the wrong memory region, and at runtime bpf_bprintf_prepare() can read out of bounds searching for a null terminator. Reject BPF_MAP_TYPE_INSN_ARRAY in check_reg_const_str() since this map type is not designed to hold string data. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2c29addf92581b410079 Tested-by: [email protected] Fixes: 493d9e0 ("bpf, x86: add support for indirect jumps") Signed-off-by: Deepanshu Kartikey <[email protected]> Acked-by: Anton Protopopov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ab86d0b commit 9df5fad

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9609,6 +9609,11 @@ static int check_reg_const_str(struct bpf_verifier_env *env,
96099609
if (reg->type != PTR_TO_MAP_VALUE)
96109610
return -EINVAL;
96119611

9612+
if (map->map_type == BPF_MAP_TYPE_INSN_ARRAY) {
9613+
verbose(env, "R%d points to insn_array map which cannot be used as const string\n", regno);
9614+
return -EACCES;
9615+
}
9616+
96129617
if (!bpf_map_is_rdonly(map)) {
96139618
verbose(env, "R%d does not point to a readonly map'\n", regno);
96149619
return -EACCES;

0 commit comments

Comments
 (0)