From: Jhonata Poma-Hansen via B4 Relay <devnull+jhonata.poma.gmail.com@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Kuniyuki Iwashima <kuniyu@google.com>,
Jhonata Poma-Hansen <jhonata.poma@gmail.com>
Subject: [PATCH net 1/2] netlink: retry a dump skb that does not fit with the minimum size
Date: Fri, 23 Oct 2026 13:26:07 +0200 [thread overview]
Message-ID: <20261023-netlink-dump-livelock-v1-1-478214a635d2@gmail.com> (raw)
In-Reply-To: <20261023-netlink-dump-livelock-v1-0-478214a635d2@gmail.com>
From: Jhonata Poma-Hansen <jhonata.poma@gmail.com>
netlink_dump() sizes the skb after the largest buffer the reader passed
to recvmsg(), up to 32KiB. Since commit ae8f160e7eb2 ("netlink: Fix
wraparounds of sk->sk_rmem_alloc.") the skb is only queued if it fits
in sk_rcvbuf, or if nothing else is charged to the socket.
A reader with a small receive buffer that still has data charged to
its socket when a dump starts gets ENOBUFS, even when a minimum size
skb would fit. The dump stays marked as running and every recvmsg()
retries it, so a reader that peeks before reading, as libnl does,
never consumes the data at the head of the queue and spins forever.
"iw dev wlan0 scan" hits this: its socket has an 8KiB buffer, it joins
the nl80211 multicast groups, and it dumps the scan results as soon as
it has read the NEW_SCAN_RESULTS notification. When it preempts the
sender, the notification is still charged to its socket until
netlink_broadcast() returns, the dump fails to start and iw spins at
100% CPU.
Retry with alloc_min_size before failing the dump.
Fixes: ae8f160e7eb2 ("netlink: Fix wraparounds of sk->sk_rmem_alloc.")
Signed-off-by: Jhonata Poma-Hansen <jhonata.poma@gmail.com>
---
net/netlink/af_netlink.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index a904dc3bc..b750e79fe 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2318,10 +2318,21 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
if (!skb)
goto errout_skb;
+retry:
rcvbuf = READ_ONCE(sk->sk_rcvbuf);
rmem = atomic_add_return(skb->truesize, &sk->sk_rmem_alloc);
if (rmem != skb->truesize && rmem >= rcvbuf) {
atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
+ /* A skb sized after max_recvmsg_len may not fit next to data
+ * still charged to the socket, while a minimum size one does.
+ */
+ if (alloc_size > alloc_min_size) {
+ kfree_skb(skb);
+ alloc_size = alloc_min_size;
+ skb = alloc_skb(alloc_size, GFP_KERNEL);
+ if (skb)
+ goto retry;
+ }
goto errout_skb;
}
--
2.54.0
next prev parent reply other threads:[~2026-10-23 11:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 11:26 [PATCH net 0/2] netlink: fix a dump livelock with a notification queued Jhonata Poma-Hansen via B4 Relay
2026-10-23 11:26 ` Jhonata Poma-Hansen via B4 Relay [this message]
2026-10-23 11:26 ` [PATCH net 2/2] selftests: net: netlink-dumps: start a dump " Jhonata Poma-Hansen via B4 Relay
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=20261023-netlink-dump-livelock-v1-1-478214a635d2@gmail.com \
--to=devnull+jhonata.poma.gmail.com@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jhonata.poma@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®