BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: chia-yu.chang@nokia-bell-labs.com, bpf@vger.kernel.org
Subject: Re: [PATCH net-next v5 4/4] tcp: add MSS ceiling callback for congestion control
Date: Tue, 01 Dec 2026 12:57:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-243319@kernel.org> (raw)
In-Reply-To: <20261130125658.20292-5-chia-yu.chang@nokia-bell-labs.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] tcp: mss_ceiling() skipped at conn init, in ca->init(), and on
  CC switch
- [High] bpf: unbounded recursion when struct_ops mss_ceiling() calls
  tcp_update_mss_ceiling()
- [Medium] tcp: max(mss_ceiling, min_snd_mss) in tcp_sync_mss()
  overrides half-window bound
- [Medium] tcp: tcp_v6_mtu_reduced() drops valid IPv6 PMTU reductions
  above mss_ceiling
- [Medium] tcp: mss_ceiling in tp->mss_cache corrupts MTU probing
  search_low and snd_cwnd
--

commit 6a2835052973696e33d5f9fcd760f0e3858c0186
Author: Chia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>

tcp: add MSS ceiling callback for congestion control

This commit adds an optional mss_ceiling() callback to struct
tcp_congestion_ops and a tcp_update_mss_ceiling() helper and BPF kfunc to
recompute tp->mss_cache when the congestion control module changes its MSS
ceiling.

> diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
> index 2a71dc81562f4..b03cc9e9c0641 100644
> --- a/net/ipv4/bpf_tcp_ca.c
> +++ b/net/ipv4/bpf_tcp_ca.c
> @@ -195,6 +195,7 @@ BTF_ID_FLAGS(func, tcp_reno_undo_cwnd)
>  BTF_ID_FLAGS(func, tcp_slow_start)
>  BTF_ID_FLAGS(func, tcp_cong_avoid_ai)
>  BTF_ID_FLAGS(func, tcp_tso_autosize)
> +BTF_ID_FLAGS(func, tcp_update_mss_ceiling)
>  BTF_KFUNCS_END(bpf_tcp_ca_check_kfunc_ids)

[Severity: High]
Can a BPF struct_ops congestion control program overflow the kernel stack
by calling tcp_update_mss_ceiling() from inside its mss_ceiling()
callback?

tcp_update_mss_ceiling() is exposed to all BPF_PROG_TYPE_STRUCT_OPS
callbacks without filtering out tcp_congestion_ops.mss_ceiling, and
bpf_prog_check_recur() does not enable runtime recursion checks on the
trampoline when jits_use_priv_stack is false:

tcp_sync_mss(sk, pmtu)
  icsk->icsk_ca_ops->mss_ceiling(sk)
    tcp_update_mss_ceiling(sk)
      tcp_sync_mss(sk, icsk->icsk_pmtu_cookie)
        icsk->icsk_ca_ops->mss_ceiling(sk)  <-- unbounded recursion

[ ... ]

> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 7b694479095e0..96ed9ba7abe6d 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -2147,6 +2147,21 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
>  	mss_now = tcp_mtu_to_mss(sk, pmtu);
>  	mss_now = tcp_bound_to_half_wnd(tp, mss_now);
>  
> +	/*
> +	 * Apply an optional MSS ceiling requested by the congestion control
> +	 * module. Values below the effective minimum send MSS are clamped.
> +	 */
> +	if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->mss_ceiling) {
> +		u32 mss_ceiling = icsk->icsk_ca_ops->mss_ceiling(sk);
> +
> +		if (mss_ceiling && mss_ceiling < mss_now) {
> +			u32 min_snd_mss = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss) -
> +					  (tcp_sk(sk)->tcp_header_len - sizeof(struct tcphdr));
> +
> +			mss_now = max(mss_ceiling, min_snd_mss);
> +		}
> +	}

[Severity: Medium]
Can max(mss_ceiling, min_snd_mss) raise mss_now above the peer's
half-window bound from tcp_bound_to_half_wnd()?

tcp_mtu_to_mss() already enforces sysctl_tcp_min_snd_mss, after which
tcp_bound_to_half_wnd() can reduce mss_now below min_snd_mss when the peer
advertises a small receive window and sysctl_tcp_min_snd_mss is raised.  If
mss_ceiling is smaller still, assigning max(mss_ceiling, min_snd_mss) after
tcp_bound_to_half_wnd() increases mss_now back up to min_snd_mss instead of
capping it.

> +
>  	/* And store cached results */
>  	icsk->icsk_pmtu_cookie = pmtu;
>  	if (icsk->icsk_mtup.enabled)

[Severity: Medium]
As reported by Eric Dumazet on v4 [1], does storing the ceiling-clamped
value in tp->mss_cache cause tcp_v6_mtu_reduced() to drop valid IPv6 PMTU
reductions above the ceiling?

net/ipv6/tcp_ipv6.c:tcp_v6_mtu_reduced() {
    ...
	if (tcp_mtu_to_mss(sk, mtu) >= tcp_sk(sk)->mss_cache)
		return;
    ...
}

When a Packet Too Big arrives with an MTU below icsk->icsk_pmtu_cookie
whose unclamped MSS is still at or above the ceiling-clamped tp->mss_cache,
tcp_v6_mtu_reduced() returns early without updating the route PMTU or
icsk_pmtu_cookie.  Once the congestion control later raises its ceiling and
calls tcp_update_mss_ceiling(), tp->mss_cache is recomputed from the stale
icsk_pmtu_cookie and oversized packets are sent.

[Severity: Medium]
Does clamping tp->mss_cache to mss_ceiling also corrupt MTU probing
(icsk_mtup) state when probing is enabled?

When the reprobe timer fires in tcp_mtu_check_reprobe(), it sets
icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, tcp_current_mss(sk)) from
the ceiling-clamped tp->mss_cache, so tcp_sync_mss() then clamps mss_now to
that search_low and prevents tp->mss_cache from rising when the congestion
control later increases its ceiling.  In addition, when a probe succeeds,
tcp_mtup_probe_success() scales tp->snd_cwnd down by
tcp_mss_to_mtu(sk, tp->mss_cache) / icsk->icsk_mtup.probe_size assuming
tp->mss_cache will grow to probe_size, but tcp_sync_mss() re-clamps
tp->mss_cache to mss_ceiling and leaves snd_cwnd reduced.

> @@ -2190,6 +2205,18 @@ unsigned int tcp_current_mss(struct sock *sk)
>  	return mss_now;
>  }
>  
> +__bpf_kfunc unsigned int tcp_update_mss_ceiling(struct sock *sk)
> +{
> +	struct inet_connection_sock *icsk = inet_csk(sk);
> +
> +	if (icsk->icsk_ca_initialized &&
> +	    icsk->icsk_ca_ops->mss_ceiling &&
> +	    icsk->icsk_pmtu_cookie)
> +		return tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
> +	return tcp_sk(sk)->mss_cache;
> +}
> +EXPORT_SYMBOL_GPL(tcp_update_mss_ceiling);

[Severity: High]
Does gating on icsk->icsk_ca_initialized and icsk->icsk_ca_ops->mss_ceiling
skip applying the ceiling at connection establishment, inside ca_ops->init(),
and when switching congestion controls?

During connection setup, tcp_sync_mss() runs before tcp_init_transfer()
initializes congestion control, while icsk_ca_initialized is 0, and records
icsk_pmtu_cookie = pmtu without calling mss_ceiling().  When
tcp_init_congestion_control() then runs:

net/ipv4/tcp_cong.c:tcp_init_congestion_control() {
    ...
	if (icsk->icsk_ca_ops->init)
		icsk->icsk_ca_ops->init(sk);
    ...
	icsk->icsk_ca_initialized = 1;
}

icsk_ca_initialized is set only after init() returns, so calling
tcp_update_mss_ceiling() from ca_ops->init() is a no-op, and nothing calls
tcp_sync_mss() once icsk_ca_initialized becomes 1 because dst_mtu(dst)
already matches icsk_pmtu_cookie.  Conversely, switching via
setsockopt(TCP_CONGESTION) from a module with mss_ceiling() to one without
it (such as CUBIC) in tcp_reinit_congestion_control() never recomputes
tp->mss_cache, leaving the socket stuck at the previous module's ceiling
because tcp_update_mss_ceiling() requires icsk_ca_ops->mss_ceiling to be
non-NULL.

[1] https://lore.kernel.org/r/CAL4Wiip6JFsVH_WAn4HmrXCiuKEJCoZR9nUv9X7RZU73_YJyzw@mail.gmail.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130125658.20292-1-chia-yu.chang@nokia-bell-labs.com?part=4

  reply	other threads:[~2026-12-01 12:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 12:56 [PATCH net-next v5 0/4] TCP Prague preparation series chia-yu.chang
2026-11-30 12:56 ` [PATCH net-next v5 1/4] tcp: export CE count in rate_sample chia-yu.chang
2026-12-01 13:10   ` netdev-bot+sashiko
2026-11-30 12:56 ` [PATCH net-next v5 2/4] tcp: rename ECN transmit helper function chia-yu.chang
2026-11-30 12:56 ` [PATCH net-next v5 3/4] tcp: add TCP_ECN_SEND_ECT_1 flag for congestion control chia-yu.chang
2026-12-01 12:57   ` sashiko-bot
2026-12-01 13:10   ` netdev-bot+sashiko
2026-11-30 12:56 ` [PATCH net-next v5 4/4] tcp: add MSS ceiling callback " chia-yu.chang
2026-12-01 12:57   ` sashiko-bot [this message]
2026-12-01 13:10   ` netdev-bot+sashiko

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=sashiko-outbox-243319@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chia-yu.chang@nokia-bell-labs.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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