stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	syzbot <syzkaller@googlegroups.com>,
	"David S. Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.4 20/25] ipv4: raw: lock the socket in raw_bind()
Date: Tue,  1 Feb 2022 19:16:44 +0100	[thread overview]
Message-ID: <20220201180822.804384142@linuxfoundation.org> (raw)
In-Reply-To: <20220201180822.148370751@linuxfoundation.org>

From: Eric Dumazet <edumazet@google.com>

[ Upstream commit 153a0d187e767c68733b8e9f46218eb1f41ab902 ]

For some reason, raw_bind() forgot to lock the socket.

BUG: KCSAN: data-race in __ip4_datagram_connect / raw_bind

write to 0xffff8881170d4308 of 4 bytes by task 5466 on cpu 0:
 raw_bind+0x1b0/0x250 net/ipv4/raw.c:739
 inet_bind+0x56/0xa0 net/ipv4/af_inet.c:443
 __sys_bind+0x14b/0x1b0 net/socket.c:1697
 __do_sys_bind net/socket.c:1708 [inline]
 __se_sys_bind net/socket.c:1706 [inline]
 __x64_sys_bind+0x3d/0x50 net/socket.c:1706
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

read to 0xffff8881170d4308 of 4 bytes by task 5468 on cpu 1:
 __ip4_datagram_connect+0xb7/0x7b0 net/ipv4/datagram.c:39
 ip4_datagram_connect+0x2a/0x40 net/ipv4/datagram.c:89
 inet_dgram_connect+0x107/0x190 net/ipv4/af_inet.c:576
 __sys_connect_file net/socket.c:1900 [inline]
 __sys_connect+0x197/0x1b0 net/socket.c:1917
 __do_sys_connect net/socket.c:1927 [inline]
 __se_sys_connect net/socket.c:1924 [inline]
 __x64_sys_connect+0x3d/0x50 net/socket.c:1924
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

value changed: 0x00000000 -> 0x0003007f

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 5468 Comm: syz-executor.5 Not tainted 5.17.0-rc1-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/ipv4/raw.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 24ce13a796654..65dbe1784d021 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -709,6 +709,7 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	int ret = -EINVAL;
 	int chk_addr_ret;
 
+	lock_sock(sk);
 	if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
 		goto out;
 	chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
@@ -721,7 +722,9 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 		inet->inet_saddr = 0;  /* Use device */
 	sk_dst_reset(sk);
 	ret = 0;
-out:	return ret;
+out:
+	release_sock(sk);
+	return ret;
 }
 
 /*
-- 
2.34.1




  parent reply	other threads:[~2022-02-01 18:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 18:16 [PATCH 4.4 00/25] 4.4.302-rc1 review Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 01/25] can: bcm: fix UAF of bcm op Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 02/25] Bluetooth: refactor malicious adv data check Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 03/25] s390/hypfs: include z/VM guests with access control group set Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 04/25] scsi: zfcp: Fix failed recovery on gone remote port with non-NPIV FCP devices Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 05/25] udf: Restore i_lenAlloc when inode expansion fails Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 06/25] udf: Fix NULL ptr deref when converting from inline format Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 07/25] PM: wakeup: simplify the output logic of pm_show_wakelocks() Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 08/25] serial: stm32: fix software flow control transfer Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 09/25] tty: n_gsm: fix SW flow control encoding/handling Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 10/25] tty: Add support for Brainboxes UC cards Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 11/25] usb-storage: Add unusual-devs entry for VL817 USB-SATA bridge Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 12/25] USB: core: Fix hang in usb_kill_urb by adding memory barriers Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 13/25] scsi: bnx2fc: Flush destroy_work queue before calling bnx2fc_interface_put() Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 14/25] ipv6_tunnel: Rate limit warning messages Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 15/25] net: fix information leakage in /proc/net/ptype Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 16/25] ipv4: avoid using shared IP generator for connected sockets Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 17/25] net-procfs: show net devices bound packet types Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 18/25] drm/msm: Fix wrong size calculation Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 19/25] hwmon: (lm90) Reduce maximum conversion rate for G781 Greg Kroah-Hartman
2022-02-01 18:16 ` Greg Kroah-Hartman [this message]
2022-02-01 18:16 ` [PATCH 4.4 21/25] ipv4: tcp: send zero IPID in SYNACK messages Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 22/25] Bluetooth: MGMT: Fix misplaced BT_HS check Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 23/25] Revert "drm/radeon/ci: disable mclk switching for high refresh rates (v2)" Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 24/25] Revert "tc358743: fix register i2c_rd/wr function fix" Greg Kroah-Hartman
2022-02-01 18:16 ` [PATCH 4.4 25/25] KVM: x86: Fix misplaced backport of "work around leak of uninitialized stack contents" Greg Kroah-Hartman
2022-02-01 19:46 ` [PATCH 4.4 00/25] 4.4.302-rc1 review Shuah Khan
2022-02-01 20:51   ` Shuah Khan
2022-02-01 20:54 ` Pavel Machek
2022-02-01 21:24 ` Guenter Roeck
2022-02-01 22:25 ` Shuah Khan
2022-02-02  8:02 ` Naresh Kamboju
2022-02-02 12:18 ` Slade Watkins

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=20220201180822.804384142@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).