[PATCH net v2 0/2] tcp: fix use-after-free in do_tcp_getsockopt()

Cen Zhang (Microsoft) posted 2 patches 1 week, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/20260826171344.4133-1-blbllhy@gmail.com
There is a newer version of this series
net/ipv4/tcp.c           | 18 ++++++++++++++----
net/ipv4/tcp_cong.c      |  4 ++--
net/ipv4/tcp_dctcp.c     |  2 +-
net/ipv4/tcp_minisocks.c |  2 +-
net/ipv4/tcp_output.c    |  2 +-
net/mptcp/protocol.c     |  2 +-
6 files changed, 20 insertions(+), 10 deletions(-)
[PATCH net v2 0/2] tcp: fix use-after-free in do_tcp_getsockopt()
Posted by Cen Zhang (Microsoft) 1 week, 2 days ago
From: "Cen Zhang (Microsoft Security FORGE Labs)" <blbllhy@gmail.com>

do_tcp_getsockopt() has two lockless reads of icsk_ca_ops. Since BPF
struct_ops congestion control made icsk_ca_ops point to dynamically
allocated memory, a concurrent setsockopt(TCP_CONGESTION) can replace
the pointer and free the old object while either reader is using it.

Patch 1 fixes the TCP_CONGESTION path by copying ca_ops->name to a
stack buffer while holding rcu_read_lock(). It also uses READ_ONCE()
for the lockless load and annotates every explicit icsk_ca_ops store
with WRITE_ONCE().

Patch 2 fixes the TCP_CC_INFO path by keeping the READ_ONCE() load,
ca_ops->get_info lookup, and call inside an RCU read-side critical
section.

Changes since v1 [1]:
- Add READ_ONCE() to both lockless icsk_ca_ops loads.
- Add WRITE_ONCE() to all six explicit icsk_ca_ops stores.
- Include the data-race annotations in the UAF series as requested
  by Eric Dumazet [2].

[1] https://lore.kernel.org/all/20260821182449.79785-1-blbllhy@gmail.com/
[2] https://lore.kernel.org/all/CANn89iKr1ypEFeL+7te3xWoNaK5AFyYQmr+pDh2zSZAxfgNKjw@mail.gmail.com/

Cen Zhang (Microsoft Security FORGE Labs) (2):
  tcp: fix use-after-free in do_tcp_getsockopt(TCP_CONGESTION)
  tcp: fix use-after-free in do_tcp_getsockopt(TCP_CC_INFO)

 net/ipv4/tcp.c           | 18 ++++++++++++++----
 net/ipv4/tcp_cong.c      |  4 ++--
 net/ipv4/tcp_dctcp.c     |  2 +-
 net/ipv4/tcp_minisocks.c |  2 +-
 net/ipv4/tcp_output.c    |  2 +-
 net/mptcp/protocol.c     |  2 +-
 6 files changed, 20 insertions(+), 10 deletions(-)


base-commit: f967455fb2a5a2079b9eb5823e9ccf359174bf9f
-- 
2.55.0
Re: [PATCH net v2 0/2] tcp: fix use-after-free in do_tcp_getsockopt()
Posted by MPTCP CI 1 week, 2 days ago
Hi Cen,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Script error! ❓
- KVM Validation: normal (only selftest_mptcp_join): Script error! ❓
- KVM Validation: debug (except selftest_mptcp_join): Script error! ❓
- KVM Validation: debug (only selftest_mptcp_join): Script error! ❓
- KVM Validation: btf-normal (only bpftest_all): Script error! ❓
- KVM Validation: btf-debug (only bpftest_all): Script error! ❓
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/32995824882

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/054504491348
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1152216


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Re: [PATCH net v2 0/2] tcp: fix use-after-free in do_tcp_getsockopt()
Posted by MPTCP CI 1 week, 2 days ago
Hi Cen,

Thank you for your modifications, that's great!

But sadly, our CI spotted some issues with it when trying to build it.

You can find more details there:

  https://github.com/multipath-tcp/mptcp_net-next/actions/runs/32995824879

Status: failure
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/054504491348
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1152216

Feel free to reply to this email if you cannot access logs, if you need
some support to fix the error, if this doesn't seem to be caused by your
modifications or if the error is a false positive one.

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Re: [PATCH net v2 0/2] tcp: fix use-after-free in do_tcp_getsockopt()
Posted by Cen Zhang (Microsoft) 1 week, 1 day ago
On Wed, Aug 26, 2026 at 05:50:09PM +0000, MPTCP CI wrote:
> But sadly, our CI spotted some issues with it when trying to build it.

Thanks for the report. I will fix it in v3 shortly.

Thanks,
Cen