[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230818183712.123455-1-xqjcool@gmail.com>
Date: Fri, 18 Aug 2023 11:37:11 -0700
From: Qingjie Xing <xqjcool@...il.com>
To: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, keescook@...omium.org,
johannes@...solutions.net, pctammela@...atatu.com,
dhowells@...hat.com, fw@...len.de, kuniyu@...zon.com
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
xqjcool@...il.com
Subject: [PATCH] netlink: Fix the netlink socket malfunction due to concurrency
The concurrent Invocation of netlink_attachskb() and netlink_recvmsg()
on different CPUs causes malfunction of netlink socket.
The concurrent scenario of netlink_recvmsg() and netlink_attachskb()
as following:
CPU A CPU B
======== ========
netlink_recvmsg() netlink_attachskb()
[1]bit NETLINK_S_CONGESTED is set
netlink_overrun()
netlink_rcv_wake()
[2]sk_receive_queue is empty
clear bit NETLINK_S_CONGESTED
[3]NETLINK_F_RECV_NO_ENOBUFS not set
set bit NETLINK_S_CONGESTED
In this scenario, the socket's receive queue is empty. Additionally,
due to the NETLINK_S_CONGESTED flag being set, all packets sent to
this socket are discarded.
To prevent this situation, we need to introduce a check for whether
the socket receive buffer is full before setting the NETLINK_S_CONGESTED
flag.
Signed-off-by: Qingjie Xing <xqjcool@...il.com>
---
net/netlink/af_netlink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 383631873748..80bcce9acbfc 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -352,7 +352,8 @@ static void netlink_overrun(struct sock *sk)
struct netlink_sock *nlk = nlk_sk(sk);
if (!(nlk->flags & NETLINK_F_RECV_NO_ENOBUFS)) {
- if (!test_and_set_bit(NETLINK_S_CONGESTED,
+ if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf
+ && !test_and_set_bit(NETLINK_S_CONGESTED,
&nlk_sk(sk)->state)) {
sk->sk_err = ENOBUFS;
sk_error_report(sk);
--
2.41.0
Powered by blists - more mailing lists