net: avoid KCSAN splats
Subsystems (16)
cover net: avoid KCSAN splats
Often times we use skb_queue_empty() without holding a lock, meaning that other cpus (or interrupt) can change the queue under us. This is fine, but we need to properly annotate the lockless intent to make sure the compiler wont over optimize things.
Eric Dumazet (5):
net: add skb_queue_empty_lockless()
udp: use skb_queue_empty_lockless()
net: use skb_queue_empty_lockless() in poll() handlers
net: use skb_queue_empty_lockless() in busy poll contexts
net: add READ_ONCE() annotation in __skb_wait_for_more_packets()
drivers/crypto/chelsio/chtls/chtls_io.c | 2 +- drivers/isdn/capi/capi.c | 2 +- drivers/nvme/host/tcp.c | 2 +- include/linux/skbuff.h | 33 ++++++++++++++++++------- net/atm/common.c | 2 +- net/bluetooth/af_bluetooth.c | 4 +-- net/caif/caif_socket.c | 2 +- net/core/datagram.c | 8 +++--- net/core/sock.c | 2 +- net/decnet/af_decnet.c | 2 +- net/ipv4/tcp.c | 4 +-- net/ipv4/udp.c | 8 +++--- net/nfc/llcp_sock.c | 4 +-- net/phonet/socket.c | 4 +-- net/sctp/socket.c | 6 ++--- net/tipc/socket.c | 4 +-- net/unix/af_unix.c | 6 ++--- net/vmw_vsock/af_vsock.c | 2 +- 18 files changed, 56 insertions(+), 41 deletions(-)
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH 1/5 net: add skb_queue_empty_lockless()
Some paths call skb_queue_empty() without holding the queue lock. We must use a barrier in order to not let the compiler do strange things, and avoid KCSAN splats.
Adding a barrier in skb_queue_empty() might be overkill, I prefer adding a new helper to clearly identify points where the callers might be lockless. This might help us finding real bugs.
The corresponding WRITE_ONCE() should add zero cost for current compilers.
--- include/linux/skbuff.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
include/linux/skbuff.h +24 -9
@@ -1495,6 +1495,19 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)return list->next == (const struct sk_buff *) list; } +/** +* skb_queue_empty_lockless - check if a queue is empty +* @list: queue head +* +* Returns true if the queue is empty, false otherwise. +* This variant can be used in lockless contexts. +*/ +static inline bool skb_queue_empty_lockless (const struct sk_buff_head *list) +{ +return READ_ONCE (list->next) == (const struct sk_buff *) list; +} + +/** * skb_queue_is_last - check if skb is the last entry in the queue * @list: queue head
@@ -1848,9 +1861,11 @@ static inline void __skb_insert(struct sk_buff *newsk, struct sk_buff *prev, struct sk_buff *next, struct sk_buff_head *list) { - newsk->next = next; - newsk->prev = prev; - next->prev = prev->next = newsk; +/* see skb_queue_empty_lockless() for the opposite READ_ONCE() */ + WRITE_ONCE(newsk->next, next); +WRITE_ONCE (newsk->prev, prev); +WRITE_ONCE (next->prev, newsk); +WRITE_ONCE (prev->next, newsk); list->qlen++; }
@@ -1861,11 +1876,11 @@ static inline void __skb_queue_splice(const struct sk_buff_head *list,struct sk_buff *first = list->next;struct sk_buff *last = list->prev; - first->prev = prev; - prev->next = first; +WRITE_ONCE (first->prev, prev); +WRITE_ONCE (prev->next, first); - last->next = next; - next->prev = last; +WRITE_ONCE (last->next, next); +WRITE_ONCE (next->prev, last); }/**
@@ -2006,8 +2021,8 @@ static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list) next = skb->next; prev = skb->prev; skb->next = skb->prev =NULL ; - next->prev = prev; - prev->next = next; +WRITE_ONCE (next->prev, prev); +WRITE_ONCE (prev->next, next); }/**
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH 2/5 udp: use skb_queue_empty_lockless()
In reply to Eric Dumazetsyzbot reported a data-race [1].
We should use skb_queue_empty_lockless() to document that we are not ensuring a mutual exclusion and silence KCSAN.
[1]
BUG: KCSAN: data-race in __skb_recv_udp / __udp_enqueue_schedule_skb
write to 0xffff888122474b50 of 8 bytes by interrupt on cpu 0:
__skb_insert include/linux/skbuff.h:1852 [inline] __skb_queue_before include/linux/skbuff.h:1958 [inline] __skb_queue_tail include/linux/skbuff.h:1991 [inline] __udp_enqueue_schedule_skb+0x2c1/0x410 net/ipv4/udp.c:1470 __udp_queue_rcv_skb net/ipv4/udp.c:1940 [inline] udp_queue_rcv_one_skb+0x7bd/0xc70 net/ipv4/udp.c:2057 udp_queue_rcv_skb+0xb5/0x400 net/ipv4/udp.c:2074 udp_unicast_rcv_skb.isra.0+0x7e/0x1c0 net/ipv4/udp.c:2233 __udp4_lib_rcv+0xa44/0x17c0 net/ipv4/udp.c:2300 udp_rcv+0x2b/0x40 net/ipv4/udp.c:2470 ip_protocol_deliver_rcu+0x4d/0x420 net/ipv4/ip_input.c:204 ip_local_deliver_finish+0x110/0x140 net/ipv4/ip_input.c:231 NF_HOOK include/linux/netfilter.h:305 [inline] NF_HOOK include/linux/netfilter.h:299 [inline] ip_local_deliver+0x133/0x210 net/ipv4/ip_input.c:252 dst_input include/net/dst.h:442 [inline] ip_rcv_finish+0x121/0x160 net/ipv4/ip_input.c:413 NF_HOOK include/linux/netfilter.h:305 [inline] NF_HOOK include/linux/netfilter.h:299 [inline] ip_rcv+0x18f/0x1a0 net/ipv4/ip_input.c:523 __netif_receive_skb_one_core+0xa7/0xe0 net/core/dev.c:5010 __netif_receive_skb+0x37/0xf0 net/core/dev.c:5124 process_backlog+0x1d3/0x420 net/core/dev.c:5955
read to 0xffff888122474b50 of 8 bytes by task 8921 on cpu 1:
skb_queue_empty include/linux/skbuff.h:1494 [inline] __skb_recv_udp+0x18d/0x500 net/ipv4/udp.c:1653 udp_recvmsg+0xe1/0xb10 net/ipv4/udp.c:1712 inet_recvmsg+0xbb/0x250 net/ipv4/af_inet.c:838 sock_recvmsg_nosec+0x5c/0x70 net/socket.c:871 ___sys_recvmsg+0x1a0/0x3e0 net/socket.c:2480 do_recvmmsg+0x19a/0x5c0 net/socket.c:2601 __sys_recvmmsg+0x1ef/0x200 net/socket.c:2680 __do_sys_recvmmsg net/socket.c:2703 [inline] __se_sys_recvmmsg net/socket.c:2696 [inline] __x64_sys_recvmmsg+0x89/0xb0 net/socket.c:2696 do_syscall_64+0xcc/0x370 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 8921 Comm: syz-executor.4 Not tainted 5.4.0-rc3+ #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
--- net/ipv4/udp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv4/udp.c +3 -3
@@ -1577,7 +1577,7 @@ static int first_packet_length(struct sock *sk)spin_lock_bh (&rcvq->lock); skb =__first_packet_length (sk, rcvq, &total); -if (!skb && !skb_queue_empty (sk_queue)) { +if (!skb && !skb_queue_empty_lockless (sk_queue)) {spin_lock (&sk_queue->lock);skb_queue_splice_tail_init (sk_queue, rcvq);spin_unlock (&sk_queue->lock);
@@ -1650,7 +1650,7 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,return skb; } -if (skb_queue_empty (sk_queue)) { +if (skb_queue_empty_lockless (sk_queue)) {spin_unlock_bh (&queue->lock); goto busy_check; }
@@ -1676,7 +1676,7 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,break ;sk_busy_loop (sk, flags &MSG_DONTWAIT ); - }while (!skb_queue_empty (sk_queue)); + }while (!skb_queue_empty_lockless (sk_queue));/* sk_queue is empty, reader_queue may contain peeked packets */ } while (timeo &&
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH 3/5 net: use skb_queue_empty_lockless() in poll() handlers
In reply to Eric DumazetMany poll() handlers are lockless. Using skb_queue_empty_lockless() instead of skb_queue_empty() is more appropriate.
--- drivers/isdn/capi/capi.c | 2 +- net/atm/common.c | 2 +- net/bluetooth/af_bluetooth.c | 4 ++-- net/caif/caif_socket.c | 2 +- net/core/datagram.c | 4 ++-- net/decnet/af_decnet.c | 2 +- net/ipv4/tcp.c | 2 +- net/ipv4/udp.c | 2 +- net/nfc/llcp_sock.c | 4 ++-- net/phonet/socket.c | 4 ++-- net/sctp/socket.c | 4 ++-- net/tipc/socket.c | 4 ++-- net/unix/af_unix.c | 6 +++--- net/vmw_vsock/af_vsock.c | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-)
drivers/isdn/capi/capi.c +1 -1
@@ -744,7 +744,7 @@ capi_poll(struct file *file, poll_table *wait)poll_wait (file, &(cdev->recvwait), wait); mask =EPOLLOUT |EPOLLWRNORM ; -if (!skb_queue_empty (&cdev->recvqueue)) +if (!skb_queue_empty_lockless (&cdev->recvqueue)) mask |=EPOLLIN |EPOLLRDNORM ;return mask; }
net/atm/common.c +1 -1
@@ -668,7 +668,7 @@ __poll_t vcc_poll(struct file *file, struct socket *sock, poll_table *wait) mask |=EPOLLHUP ;/* readable? */ -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* writable? */
net/bluetooth/af_bluetooth.c +2 -2
@@ -460,7 +460,7 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock,if (sk->sk_state ==BT_LISTEN )return bt_accept_poll (sk); -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR | (sock_flag (sk,SOCK_SELECT_ERR_QUEUE ) ?EPOLLPRI :0 );
@@ -470,7 +470,7 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock,if (sk->sk_shutdown ==SHUTDOWN_MASK ) mask |=EPOLLHUP ; -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;if (sk->sk_state ==BT_CLOSED )
net/caif/caif_socket.c +1 -1
@@ -953,7 +953,7 @@ static __poll_t caif_poll(struct file *file, mask |=EPOLLRDHUP ;/* readable? */ -if (!skb_queue_empty (&sk->sk_receive_queue) || +if (!skb_queue_empty_lockless (&sk->sk_receive_queue) || (sk->sk_shutdown &RCV_SHUTDOWN )) mask |=EPOLLIN |EPOLLRDNORM ;
net/core/datagram.c +2 -2
@@ -767,7 +767,7 @@ __poll_t datagram_poll(struct file *file, struct socket *sock, mask =0 ;/* exceptional events? */ -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR | (sock_flag (sk,SOCK_SELECT_ERR_QUEUE ) ?EPOLLPRI :0 );
@@ -777,7 +777,7 @@ __poll_t datagram_poll(struct file *file, struct socket *sock, mask |=EPOLLHUP ;/* readable? */ -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* Connection-based need to check for termination and startup */
net/decnet/af_decnet.c +1 -1
@@ -1205,7 +1205,7 @@ static __poll_t dn_poll(struct file *file, struct socket *sock, poll_table *waistruct dn_scp *scp =DN_SK (sk);__poll_t mask =datagram_poll (file, sock, wait); -if (!skb_queue_empty (&scp->other_receive_queue)) +if (!skb_queue_empty_lockless (&scp->other_receive_queue)) mask |=EPOLLRDBAND ;return mask;
net/ipv4/tcp.c +1 -1
@@ -584,7 +584,7 @@ __poll_t tcp_poll(struct file *file, struct socket *sock, poll_table *wait) }/* This barrier is coupled with smp_wmb() in tcp_reset() */ smp_rmb (); -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR ;return mask;
net/ipv4/udp.c +1 -1
@@ -2712,7 +2712,7 @@ __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait)__poll_t mask =datagram_poll (file, sock, wait);struct sock *sk = sock->sk; -if (!skb_queue_empty (&udp_sk (sk)->reader_queue)) +if (!skb_queue_empty_lockless (&udp_sk (sk)->reader_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* Check for false positives due to checksum errors */
net/nfc/llcp_sock.c +2 -2
@@ -554,11 +554,11 @@ static __poll_t llcp_sock_poll(struct file *file, struct socket *sock,if (sk->sk_state ==LLCP_LISTEN )return llcp_accept_poll (sk); -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR | (sock_flag (sk,SOCK_SELECT_ERR_QUEUE ) ?EPOLLPRI :0 ); -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;if (sk->sk_state ==LLCP_CLOSED )
net/phonet/socket.c +2 -2
@@ -338,9 +338,9 @@ static __poll_t pn_socket_poll(struct file *file, struct socket *sock,if (sk->sk_state ==TCP_CLOSE )return EPOLLERR ; -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ; -if (!skb_queue_empty (&pn->ctrlreq_queue)) +if (!skb_queue_empty_lockless (&pn->ctrlreq_queue)) mask |=EPOLLPRI ;if (!mask && sk->sk_state ==TCP_CLOSE_WAIT )return EPOLLHUP ;
net/sctp/socket.c +2 -2
@@ -8476,7 +8476,7 @@ __poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait) mask =0 ;/* Is there any exceptional events? */ -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR | (sock_flag (sk,SOCK_SELECT_ERR_QUEUE ) ?EPOLLPRI :0 );if (sk->sk_shutdown &RCV_SHUTDOWN )
@@ -8485,7 +8485,7 @@ __poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait) mask |=EPOLLHUP ;/* Is it readable? Reconsider this code with TCP-style support. */ -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* The association is either gone or not ready. */
net/tipc/socket.c +2 -2
@@ -740,7 +740,7 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock,/* fall through */ case TIPC_LISTEN :case TIPC_CONNECTING : -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) revents |=EPOLLIN |EPOLLRDNORM ;break ;case TIPC_OPEN :
@@ -748,7 +748,7 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock, revents |=EPOLLOUT ;if (!tipc_sk_type_connectionless (sk))break ; -if (skb_queue_empty (&sk->sk_receive_queue)) +if (skb_queue_empty_lockless (&sk->sk_receive_queue))break ; revents |=EPOLLIN |EPOLLRDNORM ;break ;
net/unix/af_unix.c +3 -3
@@ -2599,7 +2599,7 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa mask |=EPOLLRDHUP |EPOLLIN |EPOLLRDNORM ;/* readable? */ -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* Connection-based need to check for termination and startup */
@@ -2628,7 +2628,7 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock, mask =0 ;/* exceptional events? */ -if (sk->sk_err || !skb_queue_empty (&sk->sk_error_queue)) +if (sk->sk_err || !skb_queue_empty_lockless (&sk->sk_error_queue)) mask |=EPOLLERR | (sock_flag (sk,SOCK_SELECT_ERR_QUEUE ) ?EPOLLPRI :0 );
@@ -2638,7 +2638,7 @@ static __poll_t unix_dgram_poll(struct file *file, struct socket *sock, mask |=EPOLLHUP ;/* readable? */ -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue)) mask |=EPOLLIN |EPOLLRDNORM ;/* Connection-based need to check for termination and startup */
net/vmw_vsock/af_vsock.c +1 -1
@@ -870,7 +870,7 @@ static __poll_t vsock_poll(struct file *file, struct socket *sock,* the queue and write as long as the socket isn't shutdown for * sending. */ -if (!skb_queue_empty (&sk->sk_receive_queue) || +if (!skb_queue_empty_lockless (&sk->sk_receive_queue) || (sk->sk_shutdown &RCV_SHUTDOWN )) { mask |=EPOLLIN |EPOLLRDNORM ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH 4/5 net: use skb_queue_empty_lockless() in busy poll contexts
In reply to Eric DumazetBusy polling usually runs without locks.
Let's use skb_queue_empty_lockless() instead of skb_queue_empty()
Also uses READ_ONCE() in __skb_try_recv_datagram() to address a similar potential problem.
--- drivers/crypto/chelsio/chtls/chtls_io.c | 2 +- drivers/nvme/host/tcp.c | 2 +- net/core/datagram.c | 2 +- net/core/sock.c | 2 +- net/ipv4/tcp.c | 2 +- net/sctp/socket.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
drivers/crypto/chelsio/chtls/chtls_io.c +1 -1
@@ -1702,7 +1702,7 @@ int chtls_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,return peekmsg (sk, msg, len, nonblock, flags);if (sk_can_busy_loop (sk) && -skb_queue_empty (&sk->sk_receive_queue) && +skb_queue_empty_lockless (&sk->sk_receive_queue) && sk->sk_state ==TCP_ESTABLISHED )sk_busy_loop (sk, nonblock);
drivers/nvme/host/tcp.c +1 -1
@@ -2219,7 +2219,7 @@ static int nvme_tcp_poll(struct blk_mq_hw_ctx *hctx)struct nvme_tcp_queue *queue = hctx->driver_data;struct sock *sk = queue->sock->sk; -if (sk_can_busy_loop (sk) &&skb_queue_empty (&sk->sk_receive_queue)) +if (sk_can_busy_loop (sk) &&skb_queue_empty_lockless (&sk->sk_receive_queue))sk_busy_loop (sk, true);nvme_tcp_try_recv (queue);return queue->nr_cqe;
net/core/datagram.c +1 -1
@@ -278,7 +278,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,break ;sk_busy_loop (sk, flags &MSG_DONTWAIT ); - }while (sk->sk_receive_queue.prev != *last); + }while (READ_ONCE (sk->sk_receive_queue.prev) != *last); error = -EAGAIN ;
net/core/sock.c +1 -1
@@ -3600,7 +3600,7 @@ bool sk_busy_loop_end(void *p, unsigned long start_time) {struct sock *sk = p; -return !skb_queue_empty (&sk->sk_receive_queue) || +return !skb_queue_empty_lockless (&sk->sk_receive_queue) ||sk_busy_loop_timeout (sk, start_time); }EXPORT_SYMBOL (sk_busy_loop_end);
net/ipv4/tcp.c +1 -1
@@ -1964,7 +1964,7 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,if (unlikely (flags &MSG_ERRQUEUE ))return inet_recv_error (sk, msg, len, addr_len); -if (sk_can_busy_loop (sk) &&skb_queue_empty (&sk->sk_receive_queue) && +if (sk_can_busy_loop (sk) &&skb_queue_empty_lockless (&sk->sk_receive_queue) && (sk->sk_state ==TCP_ESTABLISHED ))sk_busy_loop (sk, nonblock);
net/sctp/socket.c +1 -1
@@ -8871,7 +8871,7 @@ struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags,if (sk_can_busy_loop (sk)) {sk_busy_loop (sk, noblock); -if (!skb_queue_empty (&sk->sk_receive_queue)) +if (!skb_queue_empty_lockless (&sk->sk_receive_queue))continue ; }
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
PATCH 5/5 net: add READ_ONCE() annotation in __skb_wait_for_more_packets()
In reply to Eric Dumazet__skb_wait_for_more_packets() can be called while other cpus can feed packets to the socket receive queue.
KCSAN reported :
BUG: KCSAN: data-race in __skb_wait_for_more_packets / __udp_enqueue_schedule_skb
write to 0xffff888102e40b58 of 8 bytes by interrupt on cpu 0:
__skb_insert include/linux/skbuff.h:1852 [inline] __skb_queue_before include/linux/skbuff.h:1958 [inline] __skb_queue_tail include/linux/skbuff.h:1991 [inline] __udp_enqueue_schedule_skb+0x2d7/0x410 net/ipv4/udp.c:1470 __udp_queue_rcv_skb net/ipv4/udp.c:1940 [inline] udp_queue_rcv_one_skb+0x7bd/0xc70 net/ipv4/udp.c:2057 udp_queue_rcv_skb+0xb5/0x400 net/ipv4/udp.c:2074 udp_unicast_rcv_skb.isra.0+0x7e/0x1c0 net/ipv4/udp.c:2233 __udp4_lib_rcv+0xa44/0x17c0 net/ipv4/udp.c:2300 udp_rcv+0x2b/0x40 net/ipv4/udp.c:2470 ip_protocol_deliver_rcu+0x4d/0x420 net/ipv4/ip_input.c:204 ip_local_deliver_finish+0x110/0x140 net/ipv4/ip_input.c:231 NF_HOOK include/linux/netfilter.h:305 [inline] NF_HOOK include/linux/netfilter.h:299 [inline] ip_local_deliver+0x133/0x210 net/ipv4/ip_input.c:252 dst_input include/net/dst.h:442 [inline] ip_rcv_finish+0x121/0x160 net/ipv4/ip_input.c:413 NF_HOOK include/linux/netfilter.h:305 [inline] NF_HOOK include/linux/netfilter.h:299 [inline] ip_rcv+0x18f/0x1a0 net/ipv4/ip_input.c:523 __netif_receive_skb_one_core+0xa7/0xe0 net/core/dev.c:5010 __netif_receive_skb+0x37/0xf0 net/core/dev.c:5124 process_backlog+0x1d3/0x420 net/core/dev.c:5955
read to 0xffff888102e40b58 of 8 bytes by task 13035 on cpu 1:
__skb_wait_for_more_packets+0xfa/0x320 net/core/datagram.c:100 __skb_recv_udp+0x374/0x500 net/ipv4/udp.c:1683 udp_recvmsg+0xe1/0xb10 net/ipv4/udp.c:1712 inet_recvmsg+0xbb/0x250 net/ipv4/af_inet.c:838 sock_recvmsg_nosec+0x5c/0x70 net/socket.c:871 ___sys_recvmsg+0x1a0/0x3e0 net/socket.c:2480 do_recvmmsg+0x19a/0x5c0 net/socket.c:2601 __sys_recvmmsg+0x1ef/0x200 net/socket.c:2680 __do_sys_recvmmsg net/socket.c:2703 [inline] __se_sys_recvmmsg net/socket.c:2696 [inline] __x64_sys_recvmmsg+0x89/0xb0 net/socket.c:2696 do_syscall_64+0xcc/0x370 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x44/0xa9
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 13035 Comm: syz-executor.3 Not tainted 5.4.0-rc3+ #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
--- net/core/datagram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/datagram.c +1 -1
@@ -97,7 +97,7 @@ int __skb_wait_for_more_packets(struct sock *sk, int *err, long *timeo_p,if (error) goto out_err; -if (sk->sk_receive_queue.prev != skb) +if (READ_ONCE (sk->sk_receive_queue.prev) != skb) goto out;/* Socket shut down? */
Signature · 1 line
2.23.0.866.gb869b98d4c-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 23 Oct 2019 22:44:47 -0700
Quoted 5 lines
Often times we use
skb_queue_empty()without holding a lock, meaning that other cpus (or interrupt) can change the queue under us. This is fine, but we need to properly annotate the lockless intent to make sure the compiler wont over optimize things.
Series applied and I'll queue this up for -stable.
Thanks Eric.