Patch "net/af_unix: fix a data-race in unix_dgram_poll" has been added to the 4.14-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

    net/af_unix: fix a data-race in unix_dgram_poll

to the 4.14-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:
     net-af_unix-fix-a-data-race-in-unix_dgram_poll.patch
and it can be found in the queue-4.14 subdirectory.

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



commit 45a833f52b0929eec767093434f0e6d963f91631
Author: Eric Dumazet <edumazet@xxxxxxxxxx>
Date:   Wed Sep 8 17:00:29 2021 -0700

    net/af_unix: fix a data-race in unix_dgram_poll
    
    [ Upstream commit 04f08eb44b5011493d77b602fdec29ff0f5c6cd5 ]
    
    syzbot reported another data-race in af_unix [1]
    
    Lets change __skb_insert() to use WRITE_ONCE() when changing
    skb head qlen.
    
    Also, change unix_dgram_poll() to use lockless version
    of unix_recvq_full()
    
    It is verry possible we can switch all/most unix_recvq_full()
    to the lockless version, this will be done in a future kernel version.
    
    [1] HEAD commit: 8596e589b787732c8346f0482919e83cc9362db1
    
    BUG: KCSAN: data-race in skb_queue_tail / unix_dgram_poll
    
    write to 0xffff88814eeb24e0 of 4 bytes by task 25815 on cpu 0:
     __skb_insert include/linux/skbuff.h:1938 [inline]
     __skb_queue_before include/linux/skbuff.h:2043 [inline]
     __skb_queue_tail include/linux/skbuff.h:2076 [inline]
     skb_queue_tail+0x80/0xa0 net/core/skbuff.c:3264
     unix_dgram_sendmsg+0xff2/0x1600 net/unix/af_unix.c:1850
     sock_sendmsg_nosec net/socket.c:703 [inline]
     sock_sendmsg net/socket.c:723 [inline]
     ____sys_sendmsg+0x360/0x4d0 net/socket.c:2392
     ___sys_sendmsg net/socket.c:2446 [inline]
     __sys_sendmmsg+0x315/0x4b0 net/socket.c:2532
     __do_sys_sendmmsg net/socket.c:2561 [inline]
     __se_sys_sendmmsg net/socket.c:2558 [inline]
     __x64_sys_sendmmsg+0x53/0x60 net/socket.c:2558
     do_syscall_x64 arch/x86/entry/common.c:50 [inline]
     do_syscall_64+0x3d/0x90 arch/x86/entry/common.c:80
     entry_SYSCALL_64_after_hwframe+0x44/0xae
    
    read to 0xffff88814eeb24e0 of 4 bytes by task 25834 on cpu 1:
     skb_queue_len include/linux/skbuff.h:1869 [inline]
     unix_recvq_full net/unix/af_unix.c:194 [inline]
     unix_dgram_poll+0x2bc/0x3e0 net/unix/af_unix.c:2777
     sock_poll+0x23e/0x260 net/socket.c:1288
     vfs_poll include/linux/poll.h:90 [inline]
     ep_item_poll fs/eventpoll.c:846 [inline]
     ep_send_events fs/eventpoll.c:1683 [inline]
     ep_poll fs/eventpoll.c:1798 [inline]
     do_epoll_wait+0x6ad/0xf00 fs/eventpoll.c:2226
     __do_sys_epoll_wait fs/eventpoll.c:2238 [inline]
     __se_sys_epoll_wait fs/eventpoll.c:2233 [inline]
     __x64_sys_epoll_wait+0xf6/0x120 fs/eventpoll.c:2233
     do_syscall_x64 arch/x86/entry/common.c:50 [inline]
     do_syscall_64+0x3d/0x90 arch/x86/entry/common.c:80
     entry_SYSCALL_64_after_hwframe+0x44/0xae
    
    value changed: 0x0000001b -> 0x00000001
    
    Reported by Kernel Concurrency Sanitizer on:
    CPU: 1 PID: 25834 Comm: syz-executor.1 Tainted: G        W         5.14.0-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    
    Fixes: 86b18aaa2b5b ("skbuff: fix a data race in skb_queue_len()")
    Cc: Qian Cai <cai@xxxxxx>
    Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 2f303454a323..33b6d3ba49a7 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1758,7 +1758,7 @@ static inline void __skb_insert(struct sk_buff *newsk,
 	WRITE_ONCE(newsk->prev, prev);
 	WRITE_ONCE(next->prev, newsk);
 	WRITE_ONCE(prev->next, newsk);
-	list->qlen++;
+	WRITE_ONCE(list->qlen, list->qlen + 1);
 }
 
 static inline void __skb_queue_splice(const struct sk_buff_head *list,
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 59009739d324..f30509ff302e 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2742,7 +2742,7 @@ static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
 
 		other = unix_peer(sk);
 		if (other && unix_peer(other) != sk &&
-		    unix_recvq_full(other) &&
+		    unix_recvq_full_lockless(other) &&
 		    unix_dgram_peer_wake_me(sk, other))
 			writable = 0;
 



[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