From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C9C22F2362; Tue, 15 Jul 2025 13:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752587892; cv=none; b=GPcEpCuUZYeGcJ6wCGw0AqORbyEQOBC2AsctHhUNIGAE4vnf3gJiMBOHUHjukcZ2Wiw0MJ/3Jcmy4PlAqjKJqN9w7yrcN2HXtub2f1z6nGByu953bwzrA/W1xUnGX3VYJeW8NRl0zP7vqd0f8UgbB3TEWnCNrfsta5W3DtNSSCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752587892; c=relaxed/simple; bh=ReAorltinYD4AqeakqqAEy89Wt9HOf7FhOkZMb0hH4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KNojXkuGIC3y27JVBXf0MoLTf1iUODOxnoLVDgeAsn2W0bttUR5N9oYYDMeIv1x6qN6S2BD4FqF29QwWzods8yPo7qJcxFFY1y+nRZSzGkm+uEujFLxD7hFRloyT0Dqse7wPr74VfCIEUhQzmZApdgAkM81U5ieSKO0lsDOYn3A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hoJXY4XI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hoJXY4XI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EDC4C4CEE3; Tue, 15 Jul 2025 13:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752587892; bh=ReAorltinYD4AqeakqqAEy89Wt9HOf7FhOkZMb0hH4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hoJXY4XIAIlzC+LyF0JNks8wLOnHfVbbc8aEffNW0JpDzTkhldo6QpJjnY6wNuQqS +jkunyXcQiC7HeBkEXLZPGaerHaGWCQoD834GctPi5YYJDed7NbhONFqjEvOuCWYEu uqNsly3PWETVbsgVHlL/gW/d5urX3ZDm7KfY4TFQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marek Szyprowski , Kuniyuki Iwashima , Jakub Kicinski Subject: [PATCH 5.10 182/208] netlink: make sure we allow at least one dump skb Date: Tue, 15 Jul 2025 15:14:51 +0200 Message-ID: <20250715130818.249688569@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250715130810.830580412@linuxfoundation.org> References: <20250715130810.830580412@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jakub Kicinski commit a215b5723922f8099078478122f02100e489cb80 upstream. Commit under Fixes tightened up the memory accounting for Netlink sockets. Looks like the accounting is too strict for some existing use cases, Marek reported issues with nl80211 / WiFi iw CLI. To reduce number of iterations Netlink dumps try to allocate messages based on the size of the buffer passed to previous recvmsg() calls. If user space uses a larger buffer in recvmsg() than sk_rcvbuf we will allocate an skb we won't be able to queue. Make sure we always allow at least one skb to be queued. Same workaround is already present in netlink_attachskb(). Alternative would be to cap the allocation size to rcvbuf - rmem_alloc but as I said, the workaround is already present in other places. Reported-by: Marek Szyprowski Link: https://lore.kernel.org/9794af18-4905-46c6-b12c-365ea2f05858@samsung.com Fixes: ae8f160e7eb2 ("netlink: Fix wraparounds of sk->sk_rmem_alloc.") Tested-by: Marek Szyprowski Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20250711001121.3649033-1-kuba@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/netlink/af_netlink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2211,11 +2211,11 @@ static int netlink_dump(struct sock *sk, struct netlink_ext_ack extack = {}; struct netlink_callback *cb; struct sk_buff *skb = NULL; + unsigned int rmem, rcvbuf; size_t max_recvmsg_len; struct module *module; int err = -ENOBUFS; int alloc_min_size; - unsigned int rmem; int alloc_size; if (!lock_taken) @@ -2247,8 +2247,9 @@ static int netlink_dump(struct sock *sk, if (!skb) goto errout_skb; + rcvbuf = READ_ONCE(sk->sk_rcvbuf); rmem = atomic_add_return(skb->truesize, &sk->sk_rmem_alloc); - if (rmem >= READ_ONCE(sk->sk_rcvbuf)) { + if (rmem != skb->truesize && rmem >= rcvbuf) { atomic_sub(skb->truesize, &sk->sk_rmem_alloc); goto errout_skb; }