Skip to content

Commit f340858

Browse files
committed
perf lock contention: Add a missing NULL check
I got a report for a failure in BPF verifier on a recent kernel with perf lock contention command. It checks task->sighand->siglock without checking if sighand is NULL or not. Let's add one. ; if (&curr->sighand->siglock == (void *)lock) 265: (79) r1 = *(u64 *)(r0 +2624) ; frame1: R0_w=trusted_ptr_task_struct(off=0,imm=0) ; R1_w=rcu_ptr_or_null_sighand_struct(off=0,imm=0) 266: (b7) r2 = 0 ; frame1: R2_w=0 267: (0f) r1 += r2 R1 pointer arithmetic on rcu_ptr_or_null_ prohibited, null-check it first processed 164 insns (limit 1000000) max_states_per_insn 1 total_states 15 peak_states 15 mark_read 5 -- END PROG LOAD LOG -- libbpf: prog 'contention_end': failed to load: -13 libbpf: failed to load object 'lock_contention_bpf' libbpf: failed to load BPF skeleton 'lock_contention_bpf': -13 Failed to load lock-contention BPF skeleton lock contention BPF setup failed lock contention did not detect any lock contention Fixes: 1811e82 ("perf lock contention: Track and show siglock with address") Reviewed-by: Ian Rogers <[email protected]> Acked-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Song Liu <[email protected]> Cc: [email protected] Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2b8dbf6 commit f340858

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/perf/util/bpf_skel/lock_contention.bpf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ static inline __u32 check_lock_type(__u64 lock, __u32 flags)
284284
struct task_struct *curr;
285285
struct mm_struct___old *mm_old;
286286
struct mm_struct___new *mm_new;
287+
struct sighand_struct *sighand;
287288

288289
switch (flags) {
289290
case LCB_F_READ: /* rwsem */
@@ -305,7 +306,9 @@ static inline __u32 check_lock_type(__u64 lock, __u32 flags)
305306
break;
306307
case LCB_F_SPIN: /* spinlock */
307308
curr = bpf_get_current_task_btf();
308-
if (&curr->sighand->siglock == (void *)lock)
309+
sighand = curr->sighand;
310+
311+
if (sighand && &sighand->siglock == (void *)lock)
309312
return LCD_F_SIGHAND_LOCK;
310313
break;
311314
default:

0 commit comments

Comments
 (0)