Message ID | 20220127005116.1268532-1-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 153a0d187e767c68733b8e9f46218eb1f41ab902 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] ipv4: raw: lock the socket in raw_bind() | expand |
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Wed, 26 Jan 2022 16:51:16 -0800 you wrote: > From: Eric Dumazet <edumazet@google.com> > > 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 > > [...] Here is the summary with links: - [net] ipv4: raw: lock the socket in raw_bind() https://git.kernel.org/netdev/net/c/153a0d187e76 You are awesome, thank you!
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index a53f256bf9d39157021f84ce395fa1a0b9fb46ab..0505935b6b8c6c66d0df677b1d95c2cbe3ffb12d 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -722,6 +722,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; @@ -741,7 +742,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; } /*