[Devel] [PATCH hci-8.2 3/4] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period

Eva Kurchatova eva.kurchatova at virtuozzo.com
Mon Nov 23 03:20:24 MSK 2026


From: Eric Dumazet <edumazet at kernel.org>

ireq->ipv6_opt is only set by calipso_req_setattr(), when a CALIPSO
NetLabel mapping is configured.

Request socket migration (net.ipv4.tcp_migrate_req=1, or a
BPF_SK_REUSEPORT_SELECT_OR_MIGRATE program) clones the request
socket with inet_reqsk_clone(), so that the old request socket and
its clone share the same ipv6_opt, then reqsk_migrate_reset() clears
the pointer in the old one.

Another cpu holding a reference on the old request socket can still
be using these options, sending a SYNACK from tcp_v6_send_synack()
or creating a child in tcp_v6_syn_recv_sock(), when the clone
is freed. tcp_v6_reqsk_destructor() frees ipv6_opt with a plain
kfree(), leading to a use-after-free.

Both readers already run under RCU, like their IPv4 counterparts.
Use kfree_rcu() in tcp_v6_reqsk_destructor(), as commit e3f33b0a1d89
("ipv4: free inet_opt and ireq_opt after an RCU grace period") did
for ireq_opt.

Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
Reported-by: Sashiko <sashiko-bot at kernel.org>
Closes: https://lore.kernel.org/netdev/179369559062.488856.15441115725436277776@kernel.org/
Signed-off-by: Eric Dumazet <edumazet at kernel.org>
Reviewed-by: Hangbin Liu <liuhangbin at kylinos.cn>
Reviewed-by: Jiayuan Chen <jiayuan.chen at linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu at google.com>
Tested-by: Linkui Xiao <xiaolinkui at kylinos.cn>
Link: https://patch.msgid.link/20261103090011.4128420-1-edumazet@kernel.org
Signed-off-by: Paolo Abeni <pabeni at redhat.com>
(cherry picked from commit fafbc4051123d5459ea6950899cec08ed946e278)

https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net

Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index aec76c54327c..c0dbcab756f3 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -575,7 +575,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
 
 static void tcp_v6_reqsk_destructor(struct request_sock *req)
 {
-	kfree(inet_rsk(req)->ipv6_opt);
+	kfree_rcu(inet_rsk(req)->ipv6_opt, rcu);
 	consume_skb(inet_rsk(req)->pktopts);
 }
 
-- 
2.56.1



More information about the Devel mailing list