All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
	syzbot <syzkaller@googlegroups.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.4 24/57] net/af_unix: fix a data-race in unix_dgram_sendmsg / unix_release_sock
Date: Mon, 28 Jun 2021 10:42:23 -0400	[thread overview]
Message-ID: <20210628144256.34524-25-sashal@kernel.org> (raw)
In-Reply-To: <20210628144256.34524-1-sashal@kernel.org>

From: Eric Dumazet <edumazet@google.com>

[ Upstream commit a494bd642d9120648b06bb7d28ce6d05f55a7819 ]

While unix_may_send(sk, osk) is called while osk is locked, it appears
unix_release_sock() can overwrite unix_peer() after this lock has been
released, making KCSAN unhappy.

Changing unix_release_sock() to access/change unix_peer()
before lock is released should fix this issue.

BUG: KCSAN: data-race in unix_dgram_sendmsg / unix_release_sock

write to 0xffff88810465a338 of 8 bytes by task 20852 on cpu 1:
 unix_release_sock+0x4ed/0x6e0 net/unix/af_unix.c:558
 unix_release+0x2f/0x50 net/unix/af_unix.c:859
 __sock_release net/socket.c:599 [inline]
 sock_close+0x6c/0x150 net/socket.c:1258
 __fput+0x25b/0x4e0 fs/file_table.c:280
 ____fput+0x11/0x20 fs/file_table.c:313
 task_work_run+0xae/0x130 kernel/task_work.c:164
 tracehook_notify_resume include/linux/tracehook.h:189 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:175 [inline]
 exit_to_user_mode_prepare+0x156/0x190 kernel/entry/common.c:209
 __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
 syscall_exit_to_user_mode+0x20/0x40 kernel/entry/common.c:302
 do_syscall_64+0x56/0x90 arch/x86/entry/common.c:57
 entry_SYSCALL_64_after_hwframe+0x44/0xae

read to 0xffff88810465a338 of 8 bytes by task 20888 on cpu 0:
 unix_may_send net/unix/af_unix.c:189 [inline]
 unix_dgram_sendmsg+0x923/0x1610 net/unix/af_unix.c:1712
 sock_sendmsg_nosec net/socket.c:654 [inline]
 sock_sendmsg net/socket.c:674 [inline]
 ____sys_sendmsg+0x360/0x4d0 net/socket.c:2350
 ___sys_sendmsg net/socket.c:2404 [inline]
 __sys_sendmmsg+0x315/0x4b0 net/socket.c:2490
 __do_sys_sendmmsg net/socket.c:2519 [inline]
 __se_sys_sendmmsg net/socket.c:2516 [inline]
 __x64_sys_sendmmsg+0x53/0x60 net/socket.c:2516
 do_syscall_64+0x4a/0x90 arch/x86/entry/common.c:47
 entry_SYSCALL_64_after_hwframe+0x44/0xae

value changed: 0xffff888167905400 -> 0x0000000000000000

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 20888 Comm: syz-executor.0 Not tainted 5.13.0-rc5-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/unix/af_unix.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ac78c5ac8284..33948cc03ba6 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -534,12 +534,14 @@ static void unix_release_sock(struct sock *sk, int embrion)
 	u->path.mnt = NULL;
 	state = sk->sk_state;
 	sk->sk_state = TCP_CLOSE;
+
+	skpair = unix_peer(sk);
+	unix_peer(sk) = NULL;
+
 	unix_state_unlock(sk);
 
 	wake_up_interruptible_all(&u->peer_wait);
 
-	skpair = unix_peer(sk);
-
 	if (skpair != NULL) {
 		if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
 			unix_state_lock(skpair);
@@ -554,7 +556,6 @@ static void unix_release_sock(struct sock *sk, int embrion)
 
 		unix_dgram_peer_wake_disconnect(sk, skpair);
 		sock_put(skpair); /* It may now die */
-		unix_peer(sk) = NULL;
 	}
 
 	/* Try to flush out this socket. Throw out buffers at least */
-- 
2.30.2


  parent reply	other threads:[~2021-06-28 15:28 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 14:41 [PATCH 4.4 00/57] 4.4.274-rc1 review Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 01/57] HID: hid-sensor-hub: Return error for hid_set_field() failure Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 02/57] HID: Add BUS_VIRTUAL to hid_connect logging Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 03/57] HID: usbhid: fix info leak in hid_submit_ctrl Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 04/57] ARM: OMAP2+: Fix build warning when mmc_omap is not built Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 05/57] HID: gt683r: add missing MODULE_DEVICE_TABLE Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 06/57] gfs2: Fix use-after-free in gfs2_glock_shrink_scan Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 07/57] scsi: target: core: Fix warning on realtime kernels Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 08/57] ethernet: myri10ge: Fix missing error code in myri10ge_probe() Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 09/57] net: ipconfig: Don't override command-line hostnames or domains Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 10/57] rtnetlink: Fix missing error code in rtnl_bridge_notify() Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 11/57] net/x25: Return the correct errno code Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 12/57] net: " Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 13/57] fib: " Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 14/57] dmaengine: stedma40: add missing iounmap() on error in d40_probe() Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 15/57] net: ipv4: fix memory leak in netlbl_cipsov4_add_std Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 16/57] net: rds: fix memory leak in rds_recvmsg Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 17/57] rtnetlink: Fix regression in bridge VLAN configuration Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 18/57] netfilter: synproxy: Fix out of bounds when parsing TCP options Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 19/57] net: stmmac: dwmac1000: Fix extended MAC address registers definition Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 20/57] qlcnic: Fix an error handling path in 'qlcnic_probe()' Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 21/57] netxen_nic: Fix an error handling path in 'netxen_nic_probe()' Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 22/57] net: cdc_ncm: switch to eth%d interface naming Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 23/57] net: usb: fix possible use-after-free in smsc75xx_bind Sasha Levin
2021-06-28 14:42 ` Sasha Levin [this message]
2021-06-28 14:42 ` [PATCH 4.4 25/57] be2net: Fix an error handling path in 'be_probe()' Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 26/57] net: hamradio: fix memory leak in mkiss_close Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 27/57] net: cdc_eem: fix tx fixup skb leak Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 28/57] net: ethernet: fix potential use-after-free in ec_bhf_remove Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 29/57] scsi: core: Put .shost_dev in failure path if host state changes to RUNNING Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 30/57] radeon: use memcpy_to/fromio for UVD fw upload Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 31/57] can: bcm: fix infoleak in struct bcm_msg_head Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 32/57] tracing: Do no increment trace_clock_global() by one Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 33/57] PCI: Mark TI C667X to avoid bus reset Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 34/57] PCI: Mark some NVIDIA GPUs " Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 35/57] ARCv2: save ABI registers across signal handling Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 36/57] dmaengine: pl330: fix wrong usage of spinlock flags in dma_cyclc Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 37/57] net: fec_ptp: add clock rate zero check Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 38/57] can: bcm/raw/isotp: use per module netdevice notifier Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 39/57] tracing: Do not stop recording cmdlines when tracing is off Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 40/57] tracing: Do not stop recording comms if the trace file is being read Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 41/57] x86/fpu: Reset state for all signal restore failures Sasha Levin
2021-07-03 15:22   ` Pavel Machek
2021-06-28 14:42 ` [PATCH 4.4 42/57] inet: use bigger hash table for IP ID generation Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 43/57] ARM: 9081/1: fix gcc-10 thumb2-kernel regression Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 44/57] Makefile: Move -Wno-unused-but-set-variable out of GCC only block Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 45/57] Revert "PCI: PM: Do not read power state in pci_enable_device_flags()" Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 46/57] cfg80211: call cfg80211_leave_ocb when switching away from OCB Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 47/57] mac80211: drop multicast fragments Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 48/57] ping: Check return value of function 'ping_queue_rcv_skb' Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 49/57] inet: annotate date races around sk->sk_txhash Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 50/57] net: caif: fix memory leak in ldisc_open Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 51/57] r8152: Avoid memcpy() over-reading of ETH_SS_STATS Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 52/57] sh_eth: " Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 53/57] r8169: " Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 54/57] net: ll_temac: Avoid ndo_start_xmit returning NETDEV_TX_BUSY Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 55/57] nilfs2: fix memory leak in nilfs_sysfs_delete_device_group Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 56/57] i2c: robotfuzz-osif: fix control-request directions Sasha Levin
2021-06-28 14:42 ` [PATCH 4.4 57/57] Linux 4.4.274-rc1 Sasha Levin
2021-06-29 10:09 ` [PATCH 4.4 00/57] 4.4.274-rc1 review Jon Hunter
2021-06-29 14:09 ` Guenter Roeck
2021-06-29 14:52 ` Naresh Kamboju
2021-06-29 18:18 ` Guenter Roeck
2021-06-29 23:42 ` Guenter Roeck
2021-07-01 10:21 ` Pavel Machek
2021-07-10 14:59 ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628144256.34524-25-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.