Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Zihan Xi <zihanx@nebusec.ai>, netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, willemb@google.com,
	horms@kernel.org, brauner@kernel.org, runyu.xiao@seu.edu.cn,
	jiayuan.chen@shopee.com, leitao@debian.org,
	rjethwani@purestorage.com, tom@herbertland.com, vega@nebusec.ai
Subject: Re: [PATCH net 1/1] net: kcm: check sndbuf space while building a message
Date: Fri, 4 Dec 2026 15:26:52 +0100	[thread overview]
Message-ID: <d4163dbc-4bf4-4aa9-aac7-818d15e06c6a@redhat.com> (raw)
In-Reply-To: <bba172167bf15db0cd19226541324db7bae1a86d.1795676623.git.zihanx@nebusec.ai>

On 11/26/26 09:25, Zihan Xi wrote:
> @@ -771,11 +786,24 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
>   		goto out_error;
>   
>   	if (kcm->seq_skb) {
> +		unsigned int queued;
> +		size_t sndbuf = READ_ONCE(sk->sk_sndbuf);
> +
>   		/* Previously opened message */
>   		head = kcm->seq_skb;
>   		skb = kcm_tx_msg(head)->last_skb;
> +		queued = kcm_skb_frags_len(head);
> +		if (queued > sndbuf || msg_data_left(msg) > sndbuf - queued) {
> +			err = -EMSGSIZE;
> +			goto out_error;
> +		}
>   		goto start;
>   	}
> +	/* A message larger than sndbuf can never be completed. */
> +	if (msg_data_left(msg) > sk->sk_sndbuf) {
> +		err = -EMSGSIZE;
> +		goto out_error;
> +	}

Inconsistent usage of sk->sk_sndbuf. Please always READ_ONCE() it.

If you let kcm_skb_frags_len() handle NULL skb, you can consolidate
the 2 checks in a single one before the `if (kcm->seq_skb)` statement.

> @@ -964,6 +997,12 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
>   		if (head != kcm->seq_skb)
>   			kfree_skb(head);
>   	} else {
> +		if (head) {
> +			int queued = kcm_skb_frags_len(head);
> +
> +			sk_wmem_queued_add(sk, -queued);
> +			sk_mem_uncharge(sk, queued);

This last chunk looks unrelated. Should go in separate patch.

Also note all of this is net-next material, as broken from
day-1 and it changes the kernel behavior.

/P

      reply	other threads:[~2026-12-04 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:25 [PATCH net 0/1] kcm: enforce per-socket send buffer limit Zihan Xi
2026-11-26  8:25 ` [PATCH net 1/1] net: kcm: check sndbuf space while building a message Zihan Xi
2026-12-04 14:26   ` Paolo Abeni [this message]

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=d4163dbc-4bf4-4aa9-aac7-818d15e06c6a@redhat.com \
    --to=pabeni@redhat.com \
    --cc=brauner@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiayuan.chen@shopee.com \
    --cc=leitao@debian.org \
    --cc=netdev@vger.kernel.org \
    --cc=rjethwani@purestorage.com \
    --cc=runyu.xiao@seu.edu.cn \
    --cc=tom@herbertland.com \
    --cc=vega@nebusec.ai \
    --cc=willemb@google.com \
    --cc=zihanx@nebusec.ai \
    /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