From: Jakub Kicinski <kuba@kernel.org>
To: Jason Baron <jbaron@akamai.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, horms@kernel.org, kuniyu@amazon.com
Subject: Re: [PATCH net-next] netlink: Fix wraparounds of sk->sk_rmem_alloc
Date: Tue, 10 Jun 2025 16:09:46 -0700 [thread overview]
Message-ID: <20250610160946.10b5fb7d@kernel.org> (raw)
In-Reply-To: <20250609161244.3591029-1-jbaron@akamai.com>
On Mon, 9 Jun 2025 12:12:44 -0400 Jason Baron wrote:
> As noted in that fix, if there are multiple threads writing to a
> netlink socket it's possible to slightly exceed rcvbuf value. But as
> noted this avoids an expensive 'atomic_add_return()' for the common
> case. I've confirmed that with the fix the modified program from
> SOCK_DIAG(7) can no longer fill memory and the sk->sk_rcvbuf limit
> is enforced.
Looks good in general, could you add a Fixes tag?
A few coding style nit picks..
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index e8972a857e51..607e5d72de39 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -1213,11 +1213,15 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
> long *timeo, struct sock *ssk)
> {
> struct netlink_sock *nlk;
> + unsigned int rmem, rcvbuf, size;
Please try to short variable declaration lines longest to shortest
> nlk = nlk_sk(sk);
> + rmem = atomic_read(&sk->sk_rmem_alloc);
> + rcvbuf = READ_ONCE(sk->sk_rcvbuf);
> + size = skb->truesize;
I don't see a reason to store skb->truesize to a temp variable, is
there one?
Actually rcvbuf gets re-read every time, we probably don't need a temp
for it either. Just rmem to shorten the lines.
> - if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf ||
> - test_bit(NETLINK_S_CONGESTED, &nlk->state))) {
> + if (((rmem + size) > rcvbuf) ||
too many brackets:
if (rmem + skb->truesize > READ_ONCE(sk->sk_rcvbuf) ||
would be just fine.
Similar comments apply to other conditions.
--
pw-bot: cr
next prev parent reply other threads:[~2025-06-10 23:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 16:12 [PATCH net-next] netlink: Fix wraparounds of sk->sk_rmem_alloc Jason Baron
2025-06-10 23:09 ` Jakub Kicinski [this message]
2025-06-10 23:36 ` Jason Baron
2025-06-11 0:45 ` Jakub Kicinski
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=20250610160946.10b5fb7d@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jbaron@akamai.com \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).