mm/kmemleak: annotate a data race in checksum
Subsystems (2)
PATCH 1/1 mm/kmemleak: annotate a data race in checksum
The value of object->pointer could be accessed concurrently as noticed by KCSAN,
BUG: KCSAN: data-race in crc32_le_base / do_raw_spin_lock
write to 0xffffb0ea683a7d50 of 4 bytes by task 23575 on cpu 12:
do_raw_spin_lock+0x114/0x200 debug_spin_lock_after at kernel/locking/spinlock_debug.c:91 (inlined by) do_raw_spin_lock at kernel/locking/spinlock_debug.c:115 _raw_spin_lock+0x40/0x50 __handle_mm_fault+0xa9e/0xd00 handle_mm_fault+0xfc/0x2f0 do_page_fault+0x263/0x6f9 page_fault+0x34/0x40
read to 0xffffb0ea683a7d50 of 4 bytes by task 839 on cpu 60:
crc32_le_base+0x67/0x350 crc32_le_base+0x67/0x350: crc32_body at lib/crc32.c:106 (inlined by) crc32_le_generic at lib/crc32.c:179 (inlined by) crc32_le at lib/crc32.c:197 kmemleak_scan+0x528/0xd90 update_checksum at mm/kmemleak.c:1172 (inlined by) kmemleak_scan at mm/kmemleak.c:1497 kmemleak_scan_thread+0xcc/0xfa kthread+0x1e0/0x200 ret_from_fork+0x27/0x50
Reported by Kernel Concurrency Sanitizer on:
CPU: 60 PID: 839 Comm: kmemleak Tainted: G W L 5.5.0-next-20200210+ #3 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019
crc32() will dereference object->pointer. If a shattered value was returned due to a data race, it will be corrected in the next scan. Thus, annotate it as an intentional data race using the data_race() macro.
--- mm/kmemleak.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/kmemleak.c +6 -1
@@ -1169,7 +1169,12 @@ static bool update_checksum(struct kmemleak_object *object)u32 old_csum = object->checksum;kasan_disable_current (); - object->checksum =crc32 (0 , (void *)object->pointer, object->size); +/* +* crc32() will dereference object->pointer. If an unstable value was +* returned due to a data race, it will be corrected in the next scan. +*/ + object->checksum =data_race (crc32 (0 , (void *)object->pointer, + object->size));kasan_enable_current ();return object->checksum != old_csum;
Signature · 1 line
1.8.3.1
Quoted 32 lines · Qian Cai
The value of
object->pointercould be accessed concurrently as noticed by KCSAN,BUG: KCSAN: data-race in crc32_le_base / do_raw_spin_lockwrite to
0xffffb0ea683a7d50of 4 bytes by task 23575 on cpu 12:do_raw_spin_lock+0x114/0x200 debug_spin_lock_after at kernel/locking/spinlock_debug.c:91 (inlined by) do_raw_spin_lock at kernel/locking/spinlock_debug.c:115 _raw_spin_lock+0x40/0x50 __handle_mm_fault+0xa9e/0xd00 handle_mm_fault+0xfc/0x2f0 do_page_fault+0x263/0x6f9 page_fault+0x34/0x40read to
0xffffb0ea683a7d50of 4 bytes by task 839 on cpu 60:crc32_le_base+0x67/0x350 crc32_le_base+0x67/0x350: crc32_body at lib/crc32.c:106 (inlined by) crc32_le_generic at lib/crc32.c:179 (inlined by) crc32_le at lib/crc32.c:197 kmemleak_scan+0x528/0xd90 update_checksum at mm/kmemleak.c:1172 (inlined by) kmemleak_scan at mm/kmemleak.c:1497 kmemleak_scan_thread+0xcc/0xfa kthread+0x1e0/0x200 ret_from_fork+0x27/0x50Reported by Kernel Concurrency Sanitizer on:
CPU: 60 PID: 839 Comm: kmemleak Tainted: G W L 5.5.0-next-20200210+ #3 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019
Quoted 6 lines
crc32()will dereferenceobject->pointer. If a shattered value was returned due to a data race, it will be corrected in the next scan. Thus, annotate it as an intentional data race using thedata_race()macro.Signed-off-by Qian Cai <[email protected]>