Patch "inetpeer: fix data-race in inet_putpeer / inet_putpeer" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    inetpeer: fix data-race in inet_putpeer / inet_putpeer

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     inetpeer-fix-data-race-in-inet_putpeer-inet_putpeer.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 1f07ee43f7bcaadce17dcb240d1f2520bcc00deb
Author: Eric Dumazet <edumazet@xxxxxxxxxx>
Date:   Thu Nov 7 10:30:42 2019 -0800

    inetpeer: fix data-race in inet_putpeer / inet_putpeer
    
    [ Upstream commit 71685eb4ce80ae9c49eff82ca4dd15acab215de9 ]
    
    We need to explicitely forbid read/store tearing in inet_peer_gc()
    and inet_putpeer().
    
    The following syzbot report reminds us about inet_putpeer()
    running without a lock held.
    
    BUG: KCSAN: data-race in inet_putpeer / inet_putpeer
    
    write to 0xffff888121fb2ed0 of 4 bytes by interrupt on cpu 0:
     inet_putpeer+0x37/0xa0 net/ipv4/inetpeer.c:240
     ip4_frag_free+0x3d/0x50 net/ipv4/ip_fragment.c:102
     inet_frag_destroy_rcu+0x58/0x80 net/ipv4/inet_fragment.c:228
     __rcu_reclaim kernel/rcu/rcu.h:222 [inline]
     rcu_do_batch+0x256/0x5b0 kernel/rcu/tree.c:2157
     rcu_core+0x369/0x4d0 kernel/rcu/tree.c:2377
     rcu_core_si+0x12/0x20 kernel/rcu/tree.c:2386
     __do_softirq+0x115/0x33f kernel/softirq.c:292
     invoke_softirq kernel/softirq.c:373 [inline]
     irq_exit+0xbb/0xe0 kernel/softirq.c:413
     exiting_irq arch/x86/include/asm/apic.h:536 [inline]
     smp_apic_timer_interrupt+0xe6/0x280 arch/x86/kernel/apic/apic.c:1137
     apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:830
     native_safe_halt+0xe/0x10 arch/x86/kernel/paravirt.c:71
     arch_cpu_idle+0x1f/0x30 arch/x86/kernel/process.c:571
     default_idle_call+0x1e/0x40 kernel/sched/idle.c:94
     cpuidle_idle_call kernel/sched/idle.c:154 [inline]
     do_idle+0x1af/0x280 kernel/sched/idle.c:263
    
    write to 0xffff888121fb2ed0 of 4 bytes by interrupt on cpu 1:
     inet_putpeer+0x37/0xa0 net/ipv4/inetpeer.c:240
     ip4_frag_free+0x3d/0x50 net/ipv4/ip_fragment.c:102
     inet_frag_destroy_rcu+0x58/0x80 net/ipv4/inet_fragment.c:228
     __rcu_reclaim kernel/rcu/rcu.h:222 [inline]
     rcu_do_batch+0x256/0x5b0 kernel/rcu/tree.c:2157
     rcu_core+0x369/0x4d0 kernel/rcu/tree.c:2377
     rcu_core_si+0x12/0x20 kernel/rcu/tree.c:2386
     __do_softirq+0x115/0x33f kernel/softirq.c:292
     run_ksoftirqd+0x46/0x60 kernel/softirq.c:603
     smpboot_thread_fn+0x37d/0x4a0 kernel/smpboot.c:165
     kthread+0x1d4/0x200 drivers/block/aoe/aoecmd.c:1253
     ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:352
    
    Reported by Kernel Concurrency Sanitizer on:
    CPU: 1 PID: 16 Comm: ksoftirqd/1 Not tainted 5.4.0-rc3+ #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    
    Fixes: 4b9d9be839fd ("inetpeer: remove unused list")
    Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
    Reported-by: syzbot <syzkaller@xxxxxxxxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index be778599bfed..ff327a62c9ce 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -160,7 +160,12 @@ static void inet_peer_gc(struct inet_peer_base *base,
 					base->total / inet_peer_threshold * HZ;
 	for (i = 0; i < gc_cnt; i++) {
 		p = gc_stack[i];
-		delta = (__u32)jiffies - p->dtime;
+
+		/* The READ_ONCE() pairs with the WRITE_ONCE()
+		 * in inet_putpeer()
+		 */
+		delta = (__u32)jiffies - READ_ONCE(p->dtime);
+
 		if (delta < ttl || !refcount_dec_if_one(&p->refcnt))
 			gc_stack[i] = NULL;
 	}
@@ -237,7 +242,10 @@ EXPORT_SYMBOL_GPL(inet_getpeer);
 
 void inet_putpeer(struct inet_peer *p)
 {
-	p->dtime = (__u32)jiffies;
+	/* The WRITE_ONCE() pairs with itself (we run lockless)
+	 * and the READ_ONCE() in inet_peer_gc()
+	 */
+	WRITE_ONCE(p->dtime, (__u32)jiffies);
 
 	if (refcount_dec_and_test(&p->refcnt))
 		call_rcu(&p->rcu, inetpeer_free_rcu);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux