Skip to content

Commit ac6542a

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: fix null dereference when computing changes_pkt_data of prog w/o subprogs
bpf_prog_aux->func field might be NULL if program does not have subprograms except for main sub-program. The fixed commit does bpf_prog_aux->func access unconditionally, which might lead to null pointer dereference. The bug could be triggered by replacing the following BPF program: SEC("tc") int main_changes(struct __sk_buff *sk) { bpf_skb_pull_data(sk, 0); return 0; } With the following BPF program: SEC("freplace") long changes_pkt_data(struct __sk_buff *sk) { return bpf_skb_pull_data(sk, 0); } bpf_prog_aux instance itself represents the main sub-program, use this property to fix the bug. Fixes: 81f6d05 ("bpf: check changes_pkt_data property for extension programs") Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7d0d673 commit ac6542a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22193,6 +22193,7 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
2219322193
}
2219422194
if (tgt_prog) {
2219522195
struct bpf_prog_aux *aux = tgt_prog->aux;
22196+
bool tgt_changes_pkt_data;
2219622197

2219722198
if (bpf_prog_is_dev_bound(prog->aux) &&
2219822199
!bpf_prog_dev_bound_match(prog, tgt_prog)) {
@@ -22227,8 +22228,10 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
2222722228
"Extension programs should be JITed\n");
2222822229
return -EINVAL;
2222922230
}
22230-
if (prog->aux->changes_pkt_data &&
22231-
!aux->func[subprog]->aux->changes_pkt_data) {
22231+
tgt_changes_pkt_data = aux->func
22232+
? aux->func[subprog]->aux->changes_pkt_data
22233+
: aux->changes_pkt_data;
22234+
if (prog->aux->changes_pkt_data && !tgt_changes_pkt_data) {
2223222235
bpf_log(log,
2223322236
"Extension program changes packet data, while original does not\n");
2223422237
return -EINVAL;

0 commit comments

Comments
 (0)