Skip to content

Commit 7765914

Browse files
eddyz87jfvogel
authored andcommitted
bpf: fix null dereference when computing changes_pkt_data of prog w/o subprogs
commit ac6542a upstream. 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]> Signed-off-by: Shung-Hsi Yu <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit f0946dcccb3d8d28e4735a93ba54f626273aff3a) Signed-off-by: Jack Vogel <[email protected]>
1 parent 4a0aa8b commit 7765914

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
@@ -21990,6 +21990,7 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
2199021990
}
2199121991
if (tgt_prog) {
2199221992
struct bpf_prog_aux *aux = tgt_prog->aux;
21993+
bool tgt_changes_pkt_data;
2199321994

2199421995
if (bpf_prog_is_dev_bound(prog->aux) &&
2199521996
!bpf_prog_dev_bound_match(prog, tgt_prog)) {
@@ -22024,8 +22025,10 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
2202422025
"Extension programs should be JITed\n");
2202522026
return -EINVAL;
2202622027
}
22027-
if (prog->aux->changes_pkt_data &&
22028-
!aux->func[subprog]->aux->changes_pkt_data) {
22028+
tgt_changes_pkt_data = aux->func
22029+
? aux->func[subprog]->aux->changes_pkt_data
22030+
: aux->changes_pkt_data;
22031+
if (prog->aux->changes_pkt_data && !tgt_changes_pkt_data) {
2202922032
bpf_log(log,
2203022033
"Extension program changes packet data, while original does not\n");
2203122034
return -EINVAL;

0 commit comments

Comments
 (0)