All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Paul Moses" <p@1g4.org>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
	<daniel@iogearbox.net>, <martin.lau@linux.dev>,
	<edumazet@kernel.org>, <ncardwell@google.com>,
	<kuniyu@google.com>, <jiayuan.chen@linux.dev>
Subject: Re: [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check
Date: Sat, 05 Dec 2026 07:14:03 +0000	[thread overview]
Message-ID: <DNCM3DV8M5L6.OHHGYZKM3COW@gmail.com> (raw)
In-Reply-To: <2otRMj-pH-vkYkLYIT6dpXg8UAuU1t2qabqsrXWCNC70Ql4DRMtxzPZXfKbcNvHXSHRuP-oRVyQqflfD9K_55OnWL1ORrbQAdQYyBNqYo1c=@1g4.org>

On Fri, Dec 04, 2026 at 08:50 PM Paul Moses <p@1g4.org> wrote:
> 1. The LSM hook selects nv and runs tcpnv_init() with bpf_chg_cc_inprogress
>    set. The nested CA change returns -EBUSY.
> 2. Patch 2 clears icsk_ca_initialized in tcp_ca_openreq_child().
> 3. tcp_init_transfer() calls tcpnv_init() again, this time without the guard
>    set.
> 4. The nested CA change succeeds, but tcpnv_init() continues writing to
>    icsk_ca_priv after the CA has been replaced, corrupting the new CA's state.

The steps are correct, but step 4 is the bug.
It doesn't need steps 1-3.
bpf_chg_cc_inprogress is set only when bpf_setsockopt() selects nv.
Every other way to select nv runs tcpnv_init() without it.
Remove the lsm prog and keep the sockops prog:

  setsockopt(lfd, TCP_CONGESTION, "nv")   before listen()
  tcp_init_transfer() of the child        bpf_chg_cc_inprogress == 0
    tcpnv_init()
      BPF_SOCK_OPS_BASE_RTT prog
        bpf_setsockopt("highspeed")       hstcp_init(): ca->ai = 0
      ca->nv_min_rtt_reset_jiffies = jiffies + 2 * HZ   <- ca->ai
  hstcp_cong_avoid()                      hstcp_aimd_vals[ca->ai] <- oops

Both fields are at offset 0 of icsk_ca_priv.

> This does not happen on unpatched or with [2] applied.

This sequence is the same on all three kernels.
It's the issue from [3]: ->init() writes icsk_ca_priv after
bpf_setsockopt() returns. Here ->init() is tcpnv_init().
It needs its own fix.
bpf_sock_ops_setsockopt() can refuse TCP_CONGESTION in
BPF_SOCK_OPS_BASE_RTT, like it refuses TCP_NODELAY in
BPF_SOCK_OPS_HDR_OPT_LEN_CB.

> What about oot modules? bpf is incredibly intricate and I'd imagine is forced
> to be less considerate, but it's less the case for net.

Out of tree modules are not a concern. That's the same in net.
sol_tcp_sockopt_congestion() refuses "cdg" by name.
An oot cc with a pointer in icsk_ca_priv is not on that list.
A bpf cc can switch to it and overwrite the pointer today.

> More historical context:
> https://github.com/torvalds/linux/commit/8919a9b31eb4fb4c0a93e5fb350a626924302aa6
> https://github.com/torvalds/linux/commit/be5d1b61a2ad28c7e57fe8bfa277373e8ecffcdc

be5d1b61a2ad fixed a leak in cdg.
User space sets cdg in TCP_SYN_SENT. The 2nd tcp_cdg_init() loses
ca->gradients.
Only the lsm prog runs between the clone and tcp_ca_openreq_child().
It can't set cdg.

Nothing changes for patch 2.

      reply	other threads:[~2026-12-05  7:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  9:01 [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 1/3] tcp: reset congestion-control state when the route selects a new CA Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 2/3] tcp: clear inherited congestion-control state for a cloned child Paul Moses
2026-12-04  9:01 ` [PATCH bpf v2 3/3] bpf: check and set TCP congestion control from the same name Paul Moses
2026-12-04 21:04 ` [PATCH bpf v2 0/3] tcp, bpf: fix CA state on open and the TCP_CONGESTION name check Alexei Starovoitov
2026-12-04 21:26   ` Paul Moses
2026-12-05  1:36     ` Alexei Starovoitov
2026-12-05  2:22       ` Paul Moses
2026-12-05  2:36         ` Alexei Starovoitov
2026-12-05  4:50           ` Paul Moses
2026-12-05  7:14             ` Alexei Starovoitov [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=DNCM3DV8M5L6.OHHGYZKM3COW@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=edumazet@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=kuniyu@google.com \
    --cc=martin.lau@linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=p@1g4.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.