Skip to contentSkip to conversation

selftests: mptcp: add test for IPv6 subflow SLAB placement

PATCH In review Vastargazing 3 participants 5 messages May 1 – May 4

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: mptcp: add test for IPv6 subflow SLAB placement

Add mptcp_v6_initcall.sh to verify that MPTCP IPv6 subflow child sockets are allocated from the TCPv6 SLAB cache, not the kmalloc-4k fallback.

tcpv6_prot_override must copy tcpv6_prot after proto_register(&tcpv6_prot) populates tcpv6_prot.slab. If the copy runs too early, override.slab stays NULL (frozen by __ro_after_init) and subflow children fall back to kmalloc-4k. This lacks SLAB_TYPESAFE_BY_RCU, allowing lockless ehash lookups in __inet_lookup_established to read freed memory.

The test exercises the IPv6 accept path via MPTCP connections between two network namespaces, then checks that the TCPv6 slab active object count grew. On a fixed kernel, the delta is ~2 * NR_CONNS (one subflow per side per connection); on a broken kernel, it stays near zero because children land in kmalloc-4k instead.

Topology: two netns connected via veth pair with /64 ULA addresses; NR_CONNS parallel short-lived MPTCP connections are established and held open long enough to sample /proc/slabinfo. The test skips if CONFIG_MPTCP_IPV6 is absent (checked via kallsyms) or /proc/slabinfo is unreadable.

Verified on Ubuntu 6.17 kernel predating the fix: TAP "not ok 1 ... TCPv6 slab gains MPTCPv6 subflow children" with delta=0. On kernels with the fix, delta is well above the threshold of NR_CONNS/2.

Fixes b19bc2945b40 ("mptcp: implement delegated actions")
---
 tools/testing/selftests/net/mptcp/Makefile    |   1 +
 .../selftests/net/mptcp/mptcp_v6_initcall.sh  | 140 ++++++++++++++++++
 2 files changed, 141 insertions(+)
 create mode 100644 tools/testing/selftests/net/mptcp/mptcp_v6_initcall.sh
tools/testing/selftests/net/mptcp/Makefile +1 -0
index 22ba0da2adb8..c9f329441490 100644
@@ -14,6 +14,7 @@ TEST_PROGS := \
 	mptcp_connect_splice.sh \
 	mptcp_join.sh \
 	mptcp_sockopt.sh \
+	mptcp_v6_initcall.sh \
 	pm_netlink.sh \
 	simult_flows.sh \
 	userspace_pm.sh \
tools/testing/selftests/net/mptcp/mptcp_v6_initcall.sh new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#1 lore raw

Hi Vastargazing,

(+cc Florian who did a similar review on netfilter ML)

Quoted 22 lines · Vastargazing

Add mptcp_v6_initcall.sh to verify that MPTCP IPv6 subflow child sockets are allocated from the TCPv6 SLAB cache, not the kmalloc-4k fallback.

tcpv6_prot_override must copy tcpv6_prot after proto_register(&tcpv6_prot) populates tcpv6_prot.slab. If the copy runs too early, override.slab stays NULL (frozen by __ro_after_init) and subflow children fall back to kmalloc-4k. This lacks SLAB_TYPESAFE_BY_RCU, allowing lockless ehash lookups in __inet_lookup_established to read freed memory.

The test exercises the IPv6 accept path via MPTCP connections between two network namespaces, then checks that the TCPv6 slab active object count grew. On a fixed kernel, the delta is ~2 * NR_CONNS (one subflow per side per connection); on a broken kernel, it stays near zero because children land in kmalloc-4k instead.

Topology: two netns connected via veth pair with /64 ULA addresses; NR_CONNS parallel short-lived MPTCP connections are established and held open long enough to sample /proc/slabinfo. The test skips if CONFIG_MPTCP_IPV6 is absent (checked via kallsyms) or /proc/slabinfo is unreadable.

Quoted 3 lines

Verified on Ubuntu 6.17 kernel predating the fix: TAP "not ok 1 ... TCPv6 slab gains MPTCPv6 subflow children" with delta=0. On kernels with the fix, delta is well above the threshold of NR_CONNS/2.

Thank you for adding this new test, and for having validated 9b55b253907e ("mptcp: fix slab-use-after-free in __inet_lookup_established").

(...)

My following review comments are very similar to the ones shared by Florian for another on the Netfilter ML.

tools/testing/selftests/net/mptcp/mptcp_v6_initcall.sh

Quoted 2 lines
tools/testing/selftests/net/mptcp/mptcp_v6_initcall.sh new file +0 -0
new file mode 100644

This should say '755', else you get

# Warning: file mptcp_v6_initcall.sh is not executable

(Plus our CI will not validate that test.)

Me too, I'm not sure whether we should add regression tests for regression tests sake. Else we'll also quickly accumulate thousands of such scripts and test run time will explode. Globally, we prefer adding a new subtest instead of a full test.

Here, you are validating an issue in the init code, that is very unlikely to change. If a test was needed during the submission of the original fix, I would have suggested adding a quick test in our packetdrill repo instead:

https://github.com/multipath-tcp/packetdrill

An existing packetdrill test could be modified to check the slabs in v4 and v6, but I'm still not convinced it is worth it.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#2 lore raw

Hi Matt,

Thanks for the review (and for cc'ing Florian - same mistake twice, noted).

You're right on both. The 755 thing is on me, and i'm convinced the standalone script is too much for what's essentially a one-time init ordering issue - the fix commit is the safety net here.

Withdrawing the patch.

One question if you don't mind: if something similar came up again and a test *was* warranted, which existing script would be the natural home? mptcp_join.sh seemed closest since it exercises the accept path, but i'm not sure if checking /proc/slabinfo fits there or if there's a better mechanism for that kind of thing.

Vastargazing

maintainer
#3 lore raw

Hi Vastargazing,

On 01/05/2026 19:01, Vastargazing wrote:

(...)

Quoted 5 lines

One question if you don't mind: if something similar came up again and a test *was* warranted, which existing script would be the natural home? mptcp_join.sh seemed closest since it exercises the accept path, but i'm not sure if checking /proc/slabinfo fits there or if there's a better mechanism for that kind of thing.

It depends on what needs to be covered:

- diag.sh: check various counters
- mptcp_connect.sh: single path
- mptcp_join.sh: multiple paths
- mptcp_sockopt.sh: socket options
- pm_netlink.sh: in-kernel path-manager
- simult_flows.sh: small multiple paths perf tests
- userspace_pm.sh : userspace path-manager
- + kunit: token and crypto
- + packetdrill: various tests

So not mptcp_join.sh. Maybe diag.sh, or in packetdrill.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#4 lore raw
In reply to Vastargazing

Hi Vastargazing,

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): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_fastopen ⚠️
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/25220774383

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

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)