Skip to content

Commit d60edd2

Browse files
biger410brenns10
authored andcommitted
percpu_ref: not crash with uninitialized refcount
Orabug: 37968883 Signed-off-by: Junxiao Bi <[email protected]>
1 parent 965198c commit d60edd2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drgn_tools/util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,20 @@ def percpu_ref_sum(prog: Program, ref: Object) -> int:
201201
:param ref: ``struct percpu_ref``
202202
:returns: sum of the percpu reference count
203203
"""
204-
ptr = ref.percpu_count_ptr
205-
atomic_count = ref.count if has_member(ref, "count") else ref.data.count
204+
if has_member(ref, "data"):
205+
if ref.data.value_() != 0:
206+
atomic_count = ref.data.count
207+
else:
208+
return 0
209+
else:
210+
atomic_count = ref.count
206211
# Last two bits of ptr is uses as flags, not in percpu mode if any bit set.
207212
# PERCPU_COUNT_BIAS = (1LU << (BITS_PER_LONG - 1)) was set to counter
208213
# in percpu mode.
209214
bits_per_long = prog.type("long").size * 8
210215
PERCPU_COUNT_BIAS = 1 << (bits_per_long - 1)
211216
counter = atomic_count.counter & ~PERCPU_COUNT_BIAS
217+
ptr = ref.percpu_count_ptr
212218
if ptr & 0x3 != 0 or ptr == 0:
213219
return int(counter)
214220
percpu = Object(prog, "unsigned long", address=ptr)

0 commit comments

Comments
 (0)