Skip to content

Commit d0f9589

Browse files
Eric Dumazetkuba-moo
authored andcommitted
netlink: annotate data-races around sk->sk_err
syzbot caught another data-race in netlink when setting sk->sk_err. Annotate all of them for good measure. BUG: KCSAN: data-race in netlink_recvmsg / netlink_recvmsg write to 0xffff8881613bb220 of 4 bytes by task 28147 on cpu 0: netlink_recvmsg+0x448/0x780 net/netlink/af_netlink.c:1994 sock_recvmsg_nosec net/socket.c:1027 [inline] sock_recvmsg net/socket.c:1049 [inline] __sys_recvfrom+0x1f4/0x2e0 net/socket.c:2229 __do_sys_recvfrom net/socket.c:2247 [inline] __se_sys_recvfrom net/socket.c:2243 [inline] __x64_sys_recvfrom+0x78/0x90 net/socket.c:2243 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd write to 0xffff8881613bb220 of 4 bytes by task 28146 on cpu 1: netlink_recvmsg+0x448/0x780 net/netlink/af_netlink.c:1994 sock_recvmsg_nosec net/socket.c:1027 [inline] sock_recvmsg net/socket.c:1049 [inline] __sys_recvfrom+0x1f4/0x2e0 net/socket.c:2229 __do_sys_recvfrom net/socket.c:2247 [inline] __se_sys_recvfrom net/socket.c:2243 [inline] __x64_sys_recvfrom+0x78/0x90 net/socket.c:2243 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd value changed: 0x00000000 -> 0x00000016 Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 28146 Comm: syz-executor.0 Not tainted 6.6.0-rc3-syzkaller-00055-g9ed22ae6be81 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023 Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: syzbot <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1f4e803 commit d0f9589

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/netlink/af_netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static void netlink_overrun(struct sock *sk)
352352
if (!nlk_test_bit(RECV_NO_ENOBUFS, sk)) {
353353
if (!test_and_set_bit(NETLINK_S_CONGESTED,
354354
&nlk_sk(sk)->state)) {
355-
sk->sk_err = ENOBUFS;
355+
WRITE_ONCE(sk->sk_err, ENOBUFS);
356356
sk_error_report(sk);
357357
}
358358
}
@@ -1605,7 +1605,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
16051605
goto out;
16061606
}
16071607

1608-
sk->sk_err = p->code;
1608+
WRITE_ONCE(sk->sk_err, p->code);
16091609
sk_error_report(sk);
16101610
out:
16111611
return ret;
@@ -1991,7 +1991,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
19911991
atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf / 2) {
19921992
ret = netlink_dump(sk);
19931993
if (ret) {
1994-
sk->sk_err = -ret;
1994+
WRITE_ONCE(sk->sk_err, -ret);
19951995
sk_error_report(sk);
19961996
}
19971997
}
@@ -2511,7 +2511,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err,
25112511
err_bad_put:
25122512
nlmsg_free(skb);
25132513
err_skb:
2514-
NETLINK_CB(in_skb).sk->sk_err = ENOBUFS;
2514+
WRITE_ONCE(NETLINK_CB(in_skb).sk->sk_err, ENOBUFS);
25152515
sk_error_report(NETLINK_CB(in_skb).sk);
25162516
}
25172517
EXPORT_SYMBOL(netlink_ack);

0 commit comments

Comments
 (0)