Skip to content

Commit 84ad7a7

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
bpf: Allow BTF ctx access for string pointers
When accessing the context we allow access to arguments with scalar type and pointer to struct. But we deny access for pointer to scalar type, which is the case for many functions. Alexei suggested to take conservative approach and allow currently only string pointer access, which is the case for most functions now: Adding check if the pointer is to string type and allow access to it. Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 35b9211 commit 84ad7a7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

kernel/bpf/btf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,6 +3669,19 @@ struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog)
36693669
}
36703670
}
36713671

3672+
static bool is_string_ptr(struct btf *btf, const struct btf_type *t)
3673+
{
3674+
/* t comes in already as a pointer */
3675+
t = btf_type_by_id(btf, t->type);
3676+
3677+
/* allow const */
3678+
if (BTF_INFO_KIND(t->info) == BTF_KIND_CONST)
3679+
t = btf_type_by_id(btf, t->type);
3680+
3681+
/* char, signed char, unsigned char */
3682+
return btf_type_is_int(t) && t->size == 1;
3683+
}
3684+
36723685
bool btf_ctx_access(int off, int size, enum bpf_access_type type,
36733686
const struct bpf_prog *prog,
36743687
struct bpf_insn_access_aux *info)
@@ -3735,6 +3748,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
37353748
*/
37363749
return true;
37373750

3751+
if (is_string_ptr(btf, t))
3752+
return true;
3753+
37383754
/* this is a pointer to another type */
37393755
info->reg_type = PTR_TO_BTF_ID;
37403756

0 commit comments

Comments
 (0)