Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Teach the verifier to recognize rdonly_mem as not null.

Teach the verifier to recognize PTR_TO_MEM | MEM_RDONLY as not NULL
otherwise if (!bpf_ksym_exists(known_kfunc)) doesn't go through
dead code elimination.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/bpf/20230321203854.3035-3-alexei.starovoitov@gmail.com

authored by

Alexei Starovoitov and committed by
Andrii Nakryiko
1057d299 a18f7214

+9 -5
+9 -5
kernel/bpf/verifier.c
··· 486 486 type == PTR_TO_XDP_SOCK; 487 487 } 488 488 489 + static bool type_may_be_null(u32 type) 490 + { 491 + return type & PTR_MAYBE_NULL; 492 + } 493 + 489 494 static bool reg_type_not_null(enum bpf_reg_type type) 490 495 { 496 + if (type_may_be_null(type)) 497 + return false; 498 + 499 + type = base_type(type); 491 500 return type == PTR_TO_SOCKET || 492 501 type == PTR_TO_TCP_SOCK || 493 502 type == PTR_TO_MAP_VALUE || ··· 538 529 static bool type_is_rdonly_mem(u32 type) 539 530 { 540 531 return type & MEM_RDONLY; 541 - } 542 - 543 - static bool type_may_be_null(u32 type) 544 - { 545 - return type & PTR_MAYBE_NULL; 546 532 } 547 533 548 534 static bool is_acquire_function(enum bpf_func_id func_id,