Skip to content

Commit 9b55b25

Browse files
mrprekuba-moo
authored andcommitted
mptcp: fix slab-use-after-free in __inet_lookup_established
The ehash table lookups are lockless and rely on SLAB_TYPESAFE_BY_RCU to guarantee socket memory stability during RCU read-side critical sections. Both tcp_prot and tcpv6_prot have their slab caches created with this flag via proto_register(). However, MPTCP's mptcp_subflow_init() copies tcpv6_prot into tcpv6_prot_override during inet_init() (fs_initcall, level 5), before inet6_init() (module_init/device_initcall, level 6) has called proto_register(&tcpv6_prot). At that point, tcpv6_prot.slab is still NULL, so tcpv6_prot_override.slab remains NULL permanently. This causes MPTCP v6 subflow child sockets to be allocated via kmalloc (falling into kmalloc-4k) instead of the TCPv6 slab cache. The kmalloc-4k cache lacks SLAB_TYPESAFE_BY_RCU, so when these sockets are freed without SOCK_RCU_FREE (which is cleared for child sockets by design), the memory can be immediately reused. Concurrent ehash lookups under rcu_read_lock can then access freed memory, triggering a slab-use-after-free in __inet_lookup_established. Fix this by splitting the IPv6-specific initialization out of mptcp_subflow_init() into a new mptcp_subflow_v6_init(), called from mptcp_proto_v6_init() before protocol registration. This ensures tcpv6_prot_override.slab correctly inherits the SLAB_TYPESAFE_BY_RCU slab cache. Fixes: b19bc29 ("mptcp: implement delegated actions") Cc: stable@vger.kernel.org Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20260406031512.189159-1-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5a37d22 commit 9b55b25

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

net/mptcp/protocol.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,8 @@ int __init mptcp_proto_v6_init(void)
46604660
{
46614661
int err;
46624662

4663+
mptcp_subflow_v6_init();
4664+
46634665
mptcp_v6_prot = mptcp_prot;
46644666
strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
46654667
mptcp_v6_prot.slab = NULL;

net/mptcp/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
875875
void __init mptcp_proto_init(void);
876876
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
877877
int __init mptcp_proto_v6_init(void);
878+
void __init mptcp_subflow_v6_init(void);
878879
#endif
879880

880881
struct sock *mptcp_sk_clone_init(const struct sock *sk,

net/mptcp/subflow.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,15 @@ void __init mptcp_subflow_init(void)
21652165
tcp_prot_override.psock_update_sk_prot = NULL;
21662166
#endif
21672167

2168+
mptcp_diag_subflow_init(&subflow_ulp_ops);
2169+
2170+
if (tcp_register_ulp(&subflow_ulp_ops) != 0)
2171+
panic("MPTCP: failed to register subflows to ULP\n");
2172+
}
2173+
21682174
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
2175+
void __init mptcp_subflow_v6_init(void)
2176+
{
21692177
/* In struct mptcp_subflow_request_sock, we assume the TCP request sock
21702178
* structures for v4 and v6 have the same size. It should not changed in
21712179
* the future but better to make sure to be warned if it is no longer
@@ -2204,10 +2212,5 @@ void __init mptcp_subflow_init(void)
22042212
/* Disable sockmap processing for subflows */
22052213
tcpv6_prot_override.psock_update_sk_prot = NULL;
22062214
#endif
2207-
#endif
2208-
2209-
mptcp_diag_subflow_init(&subflow_ulp_ops);
2210-
2211-
if (tcp_register_ulp(&subflow_ulp_ops) != 0)
2212-
panic("MPTCP: failed to register subflows to ULP\n");
22132215
}
2216+
#endif

0 commit comments

Comments
 (0)