Skip to contentSkip to conversation

tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

PATCH Applied Eric Dumazet 6 participants 9 messages Nov 2 – Nov 4

Subsystems (5)
lore
Share & tools
lore

Eric Dumazet

author maintainer
#0 lore raw

PATCH 1/1 tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")

---
Initially reported to security@ mailing list by Anvik Loitongbam, with a patch. Anvik Loitongbam provided a reproducer.
I was able to trigger the ASAN warning before the patch, and checked the warning can no longer trigger.

Yingjie Wang also sent a public patch later, very similar to Anvik's one.

 include/linux/tcp.h | 3 +++
 net/ipv6/tcp_ipv6.c | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/tcp.h +3 -0
index d18f7bc1e5d0f73c1c7452fbc573fa7cb38b206f..5a4c61fc240ec2d4554795cea7bbd65bbea0ef02 100644
@@ -179,6 +179,9 @@ struct tcp_request_sock {
 	u8				ao_rcv_next;
 	bool				used_tcp_ao;
 #endif
+#if IS_ENABLED(CONFIG_IPV6)
+	__be32				syn_flowlabel;
+#endif
 };
 
 #define tcp_rsk(ptr) container_of_const(ptr, struct tcp_request_sock, req.req)
net/ipv6/tcp_ipv6.c +3 -2
index e006a30360eae1b43a4d53173b46b931ae668825..d406cd3c8ceabfdbb66f3e1b4f9e9a74754e8d0b 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
 				    &ireq->ir_v6_rmt_addr);
 
 		fl6->daddr = ireq->ir_v6_rmt_addr;
-		if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-			fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+		if (inet6_test_bit(REPFLOW, sk))
+			fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;
 
 		tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
 				(tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
 	ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
 	ireq->ir_rmt_addr = LOOPBACK4_IPV6;
 	ireq->ir_loc_addr = LOOPBACK4_IPV6;
+	tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
 	/* So that link locals have meaning */
 	if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
Signature · 1 line
2.53.0
author maintainer
#1 lore raw
Quoted 107 lines · Eric Dumazet

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")

---
Initially reported to security@ mailing list by Anvik Loitongbam, with a patch. Anvik Loitongbam provided a reproducer.
I was able to trigger the ASAN warning before the patch, and checked the warning can no longer trigger.

Yingjie Wang also sent a public patch later, very similar to Anvik's one.

 include/linux/tcp.h | 3 +++
 net/ipv6/tcp_ipv6.c | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/tcp.h +3 -0
index d18f7bc1e5d0f73c1c7452fbc573fa7cb38b206f..5a4c61fc240ec2d4554795cea7bbd65bbea0ef02 100644
@@ -179,6 +179,9 @@ struct tcp_request_sock {
        u8                              ao_rcv_next;
        bool                            used_tcp_ao;
 #endif
+#if IS_ENABLED(CONFIG_IPV6)
+       __be32                          syn_flowlabel;
+#endif
 };
 
 #define tcp_rsk(ptr) container_of_const(ptr, struct tcp_request_sock, req.req)
net/ipv6/tcp_ipv6.c +3 -3
index e006a30360eae1b43a4d53173b46b931ae668825..d406cd3c8ceabfdbb66f3e1b4f9e9a74754e8d0b 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
                                    &ireq->ir_v6_rmt_addr);
 
                fl6->daddr = ireq->ir_v6_rmt_addr;
-               if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-                       fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+               if (inet6_test_bit(REPFLOW, sk))
+                       fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;
 
                tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
                                (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
        ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
        ireq->ir_rmt_addr = LOOPBACK4_IPV6;
        ireq->ir_loc_addr = LOOPBACK4_IPV6;
+       tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
        /* So that link locals have meaning */
        if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
--
Quoted 2 lines

2.53.0

It seems we also can drop REPFLOW condition from tcp_v6_init_req() This means each pending request on a REPFLOW-only listener would no longer pin a full SYN skb.

I will send for net-next:

net/ipv6/tcp_ipv6.c +0 -0
index d406cd3c8ceabfdbb66f3e1b4f9e9a74754e8d0b..8ad5f13d4a74f025bc47a4336f3c518cca773315

100644

net/ipv6/tcp_ipv6.c +1 -1
@@ -800,7 +800,7 @@ static void tcp_v6_init_req(struct request_sock *req,
            (ipv6_opt_accepted(sk_listener, skb, &TCP_SKB_CB(skb)->header.h6) ||
             np->rxopt.bits.rxinfo ||
             np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim ||
-            np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
+            np->rxopt.bits.rxohlim)) {
                refcount_inc(&skb->users);
                ireq->pktopts = skb;
        }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 35 lines · Eric Dumazet

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
Quoted 7 lines

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Unlike v4, I don't think this part hold here:
tcp_v6_syn_recv_sock() consumes pktopts before inet_csk_complete_hashdance() calls timer_delete_sync()

Quoted 6 lines

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Quoted 7 lines
Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
Quoted 7 lines

---
Initially reported to security@ mailing list by Anvik Loitongbam, with a patch. Anvik Loitongbam provided a reproducer.
I was able to trigger the ASAN warning before the patch, and checked the warning can no longer trigger.

Yingjie Wang also sent a public patch later, very similar to Anvik's one.

I was just looking at that patch...

I think that misses the syncookie path:

tcp_v6_do_rcv
    // skb is final ack
    cookie_v6_check
       // inc ref
       refcount_inc(&skb->users);
       ireq->pktopts = skb;
       tcp_get_cookie_sock
         tcp_v6_syn_recv_sock    <== consume_skb() removed, and ireq->pktopts still point to the ACK

Then the same ACK is delivered to the child
tcp_v6_do_rcv
   tcp_v6_cookie_check
   tcp_child_process
     tcp_data_queue
        __kfree_skb(skb)       <== frees it regardless of skb->users

req->pktopts is now dangling, and tcp_v6_reqsk_destructor() will consume_skb() it later at accept() time.

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Eric Dumazet
Quoted 99 lines · Eric Dumazet

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")

---
Initially reported to security@ mailing list by Anvik Loitongbam, with a patch. Anvik Loitongbam provided a reproducer.
I was able to trigger the ASAN warning before the patch, and checked the warning can no longer trigger.

Yingjie Wang also sent a public patch later, very similar to Anvik's one.

 include/linux/tcp.h | 3 +++
 net/ipv6/tcp_ipv6.c | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/tcp.h +3 -0
index d18f7bc1e5d0f73c1c7452fbc573fa7cb38b206f..5a4c61fc240ec2d4554795cea7bbd65bbea0ef02 100644
@@ -179,6 +179,9 @@ struct tcp_request_sock {
        u8                              ao_rcv_next;
        bool                            used_tcp_ao;
 #endif
+#if IS_ENABLED(CONFIG_IPV6)
+       __be32                          syn_flowlabel;
+#endif
 };
 
 #define tcp_rsk(ptr) container_of_const(ptr, struct tcp_request_sock, req.req)
net/ipv6/tcp_ipv6.c +2 -2
index e006a30360eae1b43a4d53173b46b931ae668825..d406cd3c8ceabfdbb66f3e1b4f9e9a74754e8d0b 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
                                    &ireq->ir_v6_rmt_addr);
 
                fl6->daddr = ireq->ir_v6_rmt_addr;
-               if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-                       fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+               if (inet6_test_bit(REPFLOW, sk))
+                       fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;
 
                tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
                                (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |

net/ipv6/tcp_ipv6.c static void tcp_v6_init_req(struct request_sock *req,

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -1
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
        ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
        ireq->ir_rmt_addr = LOOPBACK4_IPV6;
        ireq->ir_loc_addr = LOOPBACK4_IPV6;
+       tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
        /* So that link locals have meaning */
        if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
--

Thanks, Eric! The fix looks correct to me, and I ran it through two frontier LLMs, and they agreed that the fix was correct. They also suggested your follow-up change of:

- np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
+ np->rxopt.bits.rxohlim)) {

So that follow-up looks good to me and the models.

The models suggested two tweaks to the changelog. AFAICT their suggested changelog tweaks are correct, so I'm including them below for discussion and completeness, in case it is worth respinning the patches to update the changelog:

(a) The changelog says: "The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync()."

This looks carried over from e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt after an RCU grace period"). It is true there, because ireq_opt is handed to the child, and the child cannot be freed before timer_delete_sync().

It is not true for pktopts:
- tcp_v6_syn_recv_sock() frees pktopts immediately with consume_skb() (tcp_ipv6.c:1528).
- tcp_check_req() calls ->syn_recv_sock() at tcp_minisocks.c:934.
- Only afterward does it reach inet_csk_complete_hashdance() (tcp_minisocks.c:952), then inet_csk_reqsk_queue_drop(), then timer_delete_sync() (inet_connection_sock.c:1016).
- The MPTCP rsk_drop_req() path has the same ordering.

So the timer path (reqsk_timer_handler() -> tcp_rtx_synack() -> tcp_v6_send_synack()) running on another CPU races with that consume_skb() just like the dup-SYN path. The patch fixes this too, since pktopts is no longer read, but the sentence should ideally be corrected. Suggested wording:

"The SYNACK timer has the same issue: tcp_v6_syn_recv_sock()
frees pktopts before inet_csk_complete_hashdance() reaches timer_delete_sync()."

(b) Missing side effect: after this commit, TFO SYN-ACKs will now correctly carry the reflected flow label.
- With TFO, the child is created and pktopts consumed (tcp_try_fastopen() -> tcp_fastopen_create_child() -> tcp_v6_syn_recv_sock()) *before* tcp_conn_request() sends the TFO SYN-ACK.
- So today, TFO SYN-ACKs, including retransmits from tcp_fastopen_synack_timer(), never reflect the label.
The new behavior is the correct one. But it changes what goes on the wire, so it would be good to add
a sentence next to the TIME_WAIT note.

Thanks!
neal

maintainer
#4 lore raw
Quoted 153 lines · Neal Cardwell
Quoted 99 lines · Eric Dumazet

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")

---
Initially reported to security@ mailing list by Anvik Loitongbam, with a patch. Anvik Loitongbam provided a reproducer.
I was able to trigger the ASAN warning before the patch, and checked the warning can no longer trigger.

Yingjie Wang also sent a public patch later, very similar to Anvik's one.

 include/linux/tcp.h | 3 +++
 net/ipv6/tcp_ipv6.c | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/tcp.h +3 -0
index d18f7bc1e5d0f73c1c7452fbc573fa7cb38b206f..5a4c61fc240ec2d4554795cea7bbd65bbea0ef02 100644
@@ -179,6 +179,9 @@ struct tcp_request_sock {
        u8                              ao_rcv_next;
        bool                            used_tcp_ao;
 #endif
+#if IS_ENABLED(CONFIG_IPV6)
+       __be32                          syn_flowlabel;
+#endif
 };
 
 #define tcp_rsk(ptr) container_of_const(ptr, struct tcp_request_sock, req.req)
net/ipv6/tcp_ipv6.c +2 -2
index e006a30360eae1b43a4d53173b46b931ae668825..d406cd3c8ceabfdbb66f3e1b4f9e9a74754e8d0b 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
                                    &ireq->ir_v6_rmt_addr);
 
                fl6->daddr = ireq->ir_v6_rmt_addr;
-               if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-                       fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+               if (inet6_test_bit(REPFLOW, sk))
+                       fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;
 
                tclass = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
                                (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |

net/ipv6/tcp_ipv6.c static void tcp_v6_init_req(struct request_sock *req,

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -1
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
        ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
        ireq->ir_rmt_addr = LOOPBACK4_IPV6;
        ireq->ir_loc_addr = LOOPBACK4_IPV6;
+       tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
        /* So that link locals have meaning */
        if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
--

Thanks, Eric! The fix looks correct to me, and I ran it through two frontier LLMs, and they agreed that the fix was correct. They also suggested your follow-up change of:

(quoted diff) +1 -1
-            np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
+            np->rxopt.bits.rxohlim)) {

So that follow-up looks good to me and the models.

The models suggested two tweaks to the changelog. AFAICT their suggested changelog tweaks are correct, so I'm including them below for discussion and completeness, in case it is worth respinning the patches to update the changelog:

(a) The changelog says: "The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync()."

This looks carried over from e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt after an RCU grace period"). It is true there, because ireq_opt is handed to the child, and the child cannot be freed before timer_delete_sync().

It is not true for pktopts:
- tcp_v6_syn_recv_sock() frees pktopts immediately with consume_skb() (tcp_ipv6.c:1528).
- tcp_check_req() calls ->syn_recv_sock() at tcp_minisocks.c:934.
- Only afterward does it reach inet_csk_complete_hashdance() (tcp_minisocks.c:952), then inet_csk_reqsk_queue_drop(), then timer_delete_sync() (inet_connection_sock.c:1016).
- The MPTCP rsk_drop_req() path has the same ordering.

So the timer path (reqsk_timer_handler() -> tcp_rtx_synack() -> tcp_v6_send_synack()) running on another CPU races with that consume_skb() just like the dup-SYN path. The patch fixes this too, since pktopts is no longer read, but the sentence should ideally be corrected. Suggested wording:

"The SYNACK timer has the same issue: tcp_v6_syn_recv_sock()
frees pktopts before inet_csk_complete_hashdance() reaches timer_delete_sync()."

Quoted 11 lines

(b) Missing side effect: after this commit, TFO SYN-ACKs will now correctly carry the reflected flow label.
- With TFO, the child is created and pktopts consumed (tcp_try_fastopen() -> tcp_fastopen_create_child() -> tcp_v6_syn_recv_sock()) *before* tcp_conn_request() sends the TFO SYN-ACK.
- So today, TFO SYN-ACKs, including retransmits from tcp_fastopen_synack_timer(), never reflect the label.
The new behavior is the correct one. But it changes what goes on the wire, so it would be good to add
a sentence next to the TIME_WAIT note.

I had an LLM write packetdrill tests to verify that TFO SYNACK flow label reflection is broken before this patch and fixed after this patch. I've attached the packetdrill scripts and packetdrill enhancements to support them, in case it's useful. I can merge the packetdrill enhancement patches and send the packetdrill self tests to the list if there's consensus that this is useful.

neal

From ed8506b68519d5ada1bb5e235a175d54ca410aae Mon Sep 17 00:00:00 2001
From: Neal Cardwell <[email protected]>
Date: Mon, 2 Nov 2026 06:19:08 -0800
Subject: [PATCH] selftests/net: packetdrill: add TFO IPv6 flow label
reflection tests

Add two packetdrill tests checking that a TCP Fast Open server reflects the flow label of the SYN in its SYN-ACK, and in SYN-ACK retransmits, when flow label reflection is enabled either:

- with IPV6_FL_F_REFLECT set on the listener with IPV6_FLOWLABEL_MGR (tcp_fastopen_server_ipv6-flowlabel-reflect-sockopt.pkt), or

- with FLOWLABEL_REFLECT_ESTABLISHED in the net.ipv6.flowlabel_reflect sysctl (tcp_fastopen_server_ipv6-flowlabel-reflect-sysctl.pkt).

With TFO, tcp_fastopen_create_child() -> tcp_v6_syn_recv_sock() consumes ireq->pktopts before tcp_conn_request() sends the SYN-ACK. So, before commit "tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()", tcp_v6_send_synack() did not reflect the flow label in TFO SYN-ACKs, and these tests fail. They pass with that commit.

The tests disable auto flow labels, so that a SYN-ACK that does not reflect the flow label carries flow label 0 rather than a random one.

The tests need packetdrill support for exact flow label checks ("flowlabel_exact") and for the IPV6_FLOWLABEL_MGR socket option.

This patch was developed with the help of an AI coding assistant.

---
 ..._server_ipv6-flowlabel-reflect-sockopt.pkt | 39 +++++++++++++++++++
 ...n_server_ipv6-flowlabel-reflect-sysctl.pkt | 38 ++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 tools/testing/selftests/net/packetdrill/tcp_fastopen_server_ipv6-flowlabel-reflect-sockopt.pkt
 create mode 100644 tools/testing/selftests/net/packetdrill/tcp_fastopen_server_ipv6-flowlabel-reflect-sysctl.pkt
tools/testing/selftests/net/packetdrill/tcp_fastopen_server_ipv6-flowlabel-reflect-sockopt.pkt new file +39 -0
new file mode 100644
index 000000000..4a81da065
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test that a TFO server reflects the flow label of the SYN in its
+// SYN-ACK, and in SYN-ACK retransmits, when IPV6_FL_F_REFLECT is set
+// on the listener.
+//
+// With TFO, the child socket is created before the SYN-ACK is sent.
+
+--ip_version=ipv6
+
+// IPV6_FL_F_REFLECT requires flowlabel_consistency=0.
+// Disable auto flow labels so that a SYN-ACK that does not reflect the
+// flow label of the SYN carries flow label 0.
+`./defaults.sh
+sysctl -q net.ipv4.tcp_fastopen=0x202
+sysctl -q net.ipv6.flowlabel_consistency=0
+sysctl -q net.ipv6.auto_flowlabels=0`
+
+    0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+   +0 setsockopt(3, SOL_IPV6, IPV6_FLOWLABEL_MGR, {flr_label=0, flr_action=IPV6_FL_A_GET, flr_share=IPV6_FL_S_NONE, flr_flags=IPV6_FL_F_REFLECT, flr_expires=0, flr_linger=0}, 32) = 0
+   +0 bind(3, ..., ...) = 0
+   +0 listen(3, 1) = 0
+   +0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
+
+// TFO_SERVER_COOKIE_NOT_REQD: a SYN with data creates a TFO child.
+// The SYN-ACK must carry the flow label of the SYN.
+   +0 < (flowlabel 0x12345) S 0:1000(1000) win 32792 <mss 1460,sackOK,nop,nop>
+   +0 > (flowlabel_exact 0x12345) S. 0:0(0) ack 1001 <mss 1460,nop,nop,sackOK>
+   +0 accept(3, ..., ...) = 4
+   +0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) != 0, tcpi_options }%
+   +0 read(4, ..., 1024) = 1000
+
+// The SYN-ACK is lost. The retransmitted SYN-ACK must also carry the
+// flow label of the SYN.
+   +1 > (flowlabel_exact 0x12345) S. 0:0(0) ack 1001 <mss 1460,nop,nop,sackOK>
+
+// Complete the handshake.
+ +.01 < (flowlabel 0x12345) . 1001:1001(0) ack 1 win 5840
tools/testing/selftests/net/packetdrill/tcp_fastopen_server_ipv6-flowlabel-reflect-sysctl.pkt new file +38 -0
new file mode 100644
index 000000000..e706b225c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test that a TFO server reflects the flow label of the SYN in its
+// SYN-ACK, and in SYN-ACK retransmits, when the net.ipv6.flowlabel_reflect
+// sysctl has FLOWLABEL_REFLECT_ESTABLISHED (1).
+//
+// With TFO, the child socket is created before the SYN-ACK is sent.
+
+--ip_version=ipv6
+
+// FLOWLABEL_REFLECT_ESTABLISHED applies to sockets created after it is set.
+// Disable auto flow labels so that a SYN-ACK that does not reflect the
+// flow label of the SYN carries flow label 0.
+`./defaults.sh
+sysctl -q net.ipv4.tcp_fastopen=0x202
+sysctl -q net.ipv6.flowlabel_reflect=1
+sysctl -q net.ipv6.auto_flowlabels=0`
+
+    0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3
+   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+   +0 bind(3, ..., ...) = 0
+   +0 listen(3, 1) = 0
+   +0 setsockopt(3, SOL_TCP, TCP_FASTOPEN, [1], 4) = 0
+
+// TFO_SERVER_COOKIE_NOT_REQD: a SYN with data creates a TFO child.
+// The SYN-ACK must carry the flow label of the SYN.
+   +0 < (flowlabel 0x12345) S 0:1000(1000) win 32792 <mss 1460,sackOK,nop,nop>
+   +0 > (flowlabel_exact 0x12345) S. 0:0(0) ack 1001 <mss 1460,nop,nop,sackOK>
+   +0 accept(3, ..., ...) = 4
+   +0 %{ assert (tcpi_options & TCPI_OPT_SYN_DATA) != 0, tcpi_options }%
+   +0 read(4, ..., 1024) = 1000
+
+// The SYN-ACK is lost. The retransmitted SYN-ACK must also carry the
+// flow label of the SYN.
+   +1 > (flowlabel_exact 0x12345) S. 0:0(0) ack 1001 <mss 1460,nop,nop,sackOK>
+
+// Complete the handshake.
+ +.01 < (flowlabel 0x12345) . 1001:1001(0) ack 1 win 5840
Signature · 1 line
2.56.0.398.g882cbad275-goog

From 7f6e4d1f248d3ad26947234330c03878bc6247dd Mon Sep 17 00:00:00 2001
From: Neal Cardwell <[email protected]>
Date: Mon, 2 Nov 2026 06:19:46 -0800
Subject: [PATCH 1/2] net-test: packetdrill: support exact IPv6 flow label
checks

Today a flow label on an outbound IPv6 packet in a script is only checked for consistency: the first outbound packet with a given script flow label records which live flow label it maps to, and later packets must use the same (or, for a different script label, a different) live label. This is useful for auto-generated flow labels, whose values are not predictable, but it cannot check that the kernel sends a specific flow label, e.g. when it reflects the flow label of an incoming packet (IPV6_FL_F_REFLECT, or the net.ipv6.flowlabel_reflect sysctl).

Add a "flowlabel_exact <hex>" IP info option. For an outbound packet, the live flow label must be exactly the given value, e.g.:

+0 < (flowlabel 0x12345) S 0:0(0) win 32792 <mss 1460> +0 > (flowlabel_exact 0x12345) S. 0:0(0) ack 1 <mss 1460>

For an inbound packet, "flowlabel_exact" is the same as "flowlabel". The existing "flowlabel <hex>" behavior is unchanged.

This patch was developed with the help of an AI coding assistant.

---
 gtests/net/packetdrill/icmp_packet.c |  2 ++
 gtests/net/packetdrill/lexer.l       |  1 +
 gtests/net/packetdrill/packet.h      |  1 +
 gtests/net/packetdrill/parser.y      | 46 ++++++++++++++++++++++------
 gtests/net/packetdrill/run_packet.c  | 12 ++++++++
 gtests/net/packetdrill/tcp_packet.c  |  2 ++
 gtests/net/packetdrill/types.h       |  1 +
 gtests/net/packetdrill/udp_packet.c  |  2 ++
 8 files changed, 58 insertions(+), 9 deletions(-)
gtests/net/packetdrill/icmp_packet.c +2 -0
index 6dc5f9b..17089fd 100644
@@ -361,6 +361,8 @@ struct packet *new_icmp_packet(int address_family,
 	packet->direction = direction;
 	packet->flags = 0;
 	packet->tos_chk = ip_info.tos.check;
+	if (ip_info.flow_label_exact)
+		packet->flags |= FLAG_FLOWLABEL_EXACT;
 
 	/* Set IP header fields */
 	set_packet_ip_header(packet, address_family, ip_bytes, ip_info.tos.value,
gtests/net/packetdrill/lexer.l +1 -0
index 63e70ee..f69b372 100644
@@ -267,6 +267,7 @@ e1b			return ACCECN_E1B;
 ceb			return ACCECN_CEB;
 tos			return TOS;
 flowlabel		return FLOWLABEL;
+flowlabel_exact		return FLOWLABEL_EXACT;
 flags			return FLAGS;
 Flags			return FLAGS;
 val			return VAL;
gtests/net/packetdrill/packet.h +1 -0
index 87439ad..6fdcdd6 100644
@@ -108,6 +108,7 @@ struct packet {
 #define FLAG_WIN_NOCHECK	0x1  /* don't check TCP receive window */
 #define FLAG_OPTIONS_NOCHECK	0x2  /* don't check TCP options */
 #define FLAG_PARSE_ACE		0x400 /* output parsed AccECN ACE field */
+#define FLAG_FLOWLABEL_EXACT	0x800 /* check IPv6 flow label exactly */
 
 	enum tos_chk_t tos_chk;	/* how to treat the TOS byte of a packet */
 
gtests/net/packetdrill/parser.y +37 -9

95 lines not on this page · raw message

gtests/net/packetdrill/run_packet.c +12 -0
index b7f8848..6628c45 100644
@@ -1281,6 +1281,18 @@ static int verify_outbound_live_ipv6_flowlabel(
 	u32 script_flowlabel = ipv6_flow_label(script_packet->ipv6);
 	u32 live_flowlabel = ipv6_flow_label(actual_packet->ipv6);
 
+	/* With flowlabel_exact, the live flow label must match exactly. */
+	if (script_packet->flags & FLAG_FLOWLABEL_EXACT) {
+		if (live_flowlabel != script_flowlabel) {
+			asprintf(error,
+				 "bad outbound IPv6 flow label: "
+				 "expected: 0x%05x vs actual: 0x%05x",
+				 script_flowlabel, live_flowlabel);
+			return STATUS_ERR;
+		}
+		return STATUS_OK;
+	}
+
 	/* Return directly if script_flowlabel is not set */
 	if (!script_flowlabel)
 		return STATUS_OK;
gtests/net/packetdrill/tcp_packet.c +2 -0
index 28b52c3..3c4ece6 100644
@@ -156,6 +156,8 @@ struct packet *new_tcp_packet(int address_family,
 	packet->direction = direction;
 	packet->flags = 0;
 	packet->tos_chk = ip_info.tos.check;
+	if (ip_info.flow_label_exact)
+		packet->flags |= FLAG_FLOWLABEL_EXACT;
 
 	/* Set IP header fields */
 	set_packet_ip_header(packet, address_family, ip_bytes,
gtests/net/packetdrill/types.h +1 -0
index 37cb740..7fb97ca 100644
@@ -111,6 +111,7 @@ struct tos_spec {
 struct ip_info {
 	struct tos_spec tos;
 	u32 flow_label;
+	bool flow_label_exact;	/* outbound: check flow_label exactly */
 	u8 ttl;
 };
 
gtests/net/packetdrill/udp_packet.c +2 -0
index e8004c5..422dfbc 100644
@@ -101,6 +101,8 @@ struct packet *new_udp_packet(int address_family,
 	packet->direction = direction;
 	packet->flags = 0;
 	packet->tos_chk = ip_info.tos.check;
+	if (ip_info.flow_label_exact)
+		packet->flags |= FLAG_FLOWLABEL_EXACT;
 
 	/* Set IP header fields */
 	set_packet_ip_header(packet, address_family, ip_bytes,
Signature · 1 line
2.56.0.398.g882cbad275-goog

From 9d167c9a8caf8f570314657a5af0c38b41ca2a66 Mon Sep 17 00:00:00 2001
From: Neal Cardwell <[email protected]>
Date: Mon, 2 Nov 2026 06:19:47 -0800
Subject: [PATCH 2/2] net-test: packetdrill: support IPV6_FLOWLABEL_MGR
setsockopt

Add support for passing a struct in6_flowlabel_req to setsockopt(), so that scripts can use the IPV6_FLOWLABEL_MGR socket option, e.g. to enable flow label reflection on a TCP listener:

setsockopt(3, SOL_IPV6, IPV6_FLOWLABEL_MGR, {flr_label=0,

             flr_action=IPV6_FL_A_GET, flr_share=IPV6_FL_S_NONE,
             flr_flags=IPV6_FL_F_REFLECT, flr_expires=0,
             flr_linger=0}, 32) = 0

flr_label is given in host byte order, and flr_dst is zeroed. Field values can be integers or symbolic names. Add the IPV6_FL_A_*, IPV6_FL_F_* and IPV6_FL_S_* symbols, plus IPV6_FLOWLABEL_MGR and IPV6_FLOWINFO_SEND.

As with struct in6_ifreq, declare our own copy of struct in6_flowlabel_req and its constants in ipv6.h, since they are only available in linux/in6.h, which conflicts with <netinet/in.h>.

This patch was developed with the help of an AI coding assistant.

---
 gtests/net/packetdrill/ipv6.h            | 45 ++++++++++++++++++
 gtests/net/packetdrill/lexer.l           |  6 +++
 gtests/net/packetdrill/parser.y          | 58 ++++++++++++++++++++++++
 gtests/net/packetdrill/run_system_call.c |  2 +
 gtests/net/packetdrill/script.c          |  7 +++
 gtests/net/packetdrill/script.h          |  2 +
 gtests/net/packetdrill/symbols_linux.c   | 15 ++++++
 7 files changed, 135 insertions(+)
gtests/net/packetdrill/ipv6.h +45 -0

49 lines not on this page · raw message

gtests/net/packetdrill/lexer.l +6 -0
index f69b372..d4a17a6 100644
@@ -224,6 +224,12 @@ events			return EVENTS;
 revents			return REVENTS;
 onoff			return ONOFF;
 linger			return LINGER;
+flr_label		return FLR_LABEL;
+flr_action		return FLR_ACTION;
+flr_share		return FLR_SHARE;
+flr_flags		return FLR_FLAGS;
+flr_expires		return FLR_EXPIRES;
+flr_linger		return FLR_LINGER;
 htons			return _HTONS_;
 ipv4			return IPV4;
 ipv6			return IPV6;
gtests/net/packetdrill/parser.y +58 -0

82 lines not on this page · raw message

gtests/net/packetdrill/run_system_call.c +2 -0
index 36f9f51..1fdb8a4 100644
@@ -2737,6 +2737,8 @@ static int syscall_setsockopt(struct state *state, struct syscall_spec *syscall,
 		return STATUS_ERR;
 	if (val_expression->type == EXPR_LINGER) {
 		optval = &val_expression->value.linger;
+	} else if (val_expression->type == EXPR_IN6_FLOWLABEL_REQ) {
+		optval = &val_expression->value.in6_flowlabel_req;
 	} else if (val_expression->type == EXPR_GRE) {
 		optval = &val_expression->value.gre;
 	} else if (val_expression->type == EXPR_IN6_ADDR) {
gtests/net/packetdrill/script.c +7 -0
index b713713..533a56b 100644
@@ -62,6 +62,7 @@ struct expression_type_entry expression_type_table[] = {
 	{ EXPR_SOCKET_ADDRESS_IPV4,  "sockaddr_in" },
 	{ EXPR_SOCKET_ADDRESS_IPV6,  "sockaddr_in6" },
 	{ EXPR_LINGER,               "linger" },
+	{ EXPR_IN6_FLOWLABEL_REQ,    "in6_flowlabel_req" },
 	{ EXPR_BINARY,               "binary_expression" },
 	{ EXPR_LIST,                 "list" },
 	{ EXPR_IOVEC,                "iovec" },
@@ -302,6 +303,7 @@ void free_expression(struct expression *expression)
 	case EXPR_GRE:
 	case EXPR_IN6_ADDR:
 	case EXPR_LINGER:
+	case EXPR_IN6_FLOWLABEL_REQ:
 		break;
 	case EXPR_WORD:
 		assert(expression->value.buf.ptr);
@@ -684,6 +686,11 @@ static int evaluate(struct expression *in,
 		memcpy(&out->value.linger, &in->value.linger,
 		       sizeof(in->value.linger));
 		break;
+	case EXPR_IN6_FLOWLABEL_REQ:	/* copy as-is */
+		memcpy(&out->value.in6_flowlabel_req,
+		       &in->value.in6_flowlabel_req,
+		       sizeof(in->value.in6_flowlabel_req));
+		break;
 	case EXPR_WORD:
 		out->type = EXPR_INTEGER;
 		if (symbol_to_int(in->value.buf.ptr,
gtests/net/packetdrill/script.h +2 -0
index e2939be..9c466ea 100644
@@ -37,6 +37,7 @@ enum expression_t {
 	EXPR_ELLIPSIS,		  /* ... but no value */
 	EXPR_INTEGER,		  /* integer in 'num' */
 	EXPR_LINGER,		  /* struct linger for SO_LINGER */
+	EXPR_IN6_FLOWLABEL_REQ,	  /* struct in6_flowlabel_req */
 	EXPR_WORD,		  /* unquoted word in 'string' */
 	EXPR_STRING,		  /* double-quoted string in 'string' */
 	EXPR_GRE,		  /* GRE header */
@@ -71,6 +72,7 @@ struct expression {
 		s64 num;
 		struct memory_buffer buf;
 		struct linger linger;
+		struct in6_flowlabel_req in6_flowlabel_req;
 		struct gre gre;
 		struct in6_addr address_ipv6;
 		struct sockaddr_in *socket_address_ipv4;
gtests/net/packetdrill/symbols_linux.c +15 -0
index 1655143..469711d 100644
@@ -46,6 +46,7 @@
 
 #include "epoll.h"
 #include "ip.h"
+#include "ipv6.h"
 #include "tcp.h"
 #include "capability.h"
 
@@ -167,6 +168,20 @@ struct int_symbol platform_symbols_table[] = {
 	{ IPV6_MTU,                         "IPV6_MTU"                        },
 #endif
 	{ IPV6_TCLASS,                      "IPV6_TCLASS"                     },
+	{ IPV6_FLOWLABEL_MGR,               "IPV6_FLOWLABEL_MGR"              },
+	{ IPV6_FLOWINFO_SEND,               "IPV6_FLOWINFO_SEND"              },
+	{ IPV6_FL_A_GET,                    "IPV6_FL_A_GET"                   },
+	{ IPV6_FL_A_PUT,                    "IPV6_FL_A_PUT"                   },
+	{ IPV6_FL_A_RENEW,                  "IPV6_FL_A_RENEW"                 },
+	{ IPV6_FL_F_CREATE,                 "IPV6_FL_F_CREATE"                },
+	{ IPV6_FL_F_EXCL,                   "IPV6_FL_F_EXCL"                  },
+	{ IPV6_FL_F_REFLECT,                "IPV6_FL_F_REFLECT"               },
+	{ IPV6_FL_F_REMOTE,                 "IPV6_FL_F_REMOTE"                },
+	{ IPV6_FL_S_NONE,                   "IPV6_FL_S_NONE"                  },
+	{ IPV6_FL_S_EXCL,                   "IPV6_FL_S_EXCL"                  },
+	{ IPV6_FL_S_PROCESS,                "IPV6_FL_S_PROCESS"               },
+	{ IPV6_FL_S_USER,                   "IPV6_FL_S_USER"                  },
+	{ IPV6_FL_S_ANY,                    "IPV6_FL_S_ANY"                   },
 	{ IPV6_HOPLIMIT,                    "IPV6_HOPLIMIT"                   },
 
 	{ TCP_NODELAY,                      "TCP_NODELAY"                     },
Signature · 1 line
2.56.0.398.g882cbad275-goog
#5 lore raw
In reply to Eric Dumazet
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch fixes only half of the migration use-after-free (UAF) it describes.
- [Low] Leftover from this patch: tcp_v6_init_req() (net/ipv6/tcp_ipv6.c:799-806) still keeps a reference to the SYN skb…

--

tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

This commit adds a syn_flowlabel field to tcp_request_sock. The field is filled from the SYN in tcp_v6_init_req(), and tcp_v6_send_synack() now uses it instead of reading ireq->pktopts. The old read could hit a freed skb when another cpu completed the 3WHS or migrated the request socket.

net/ipv6/tcp_ipv6.c static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst, · line 582

Quoted 12 lines
net/ipv6/tcp_ipv6.c +2 -2
index e006a30360eae..d406cd3c8ceab 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
 				    &ireq->ir_v6_rmt_addr);
 
 		fl6->daddr = ireq->ir_v6_rmt_addr;
-		if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-			fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+		if (inet6_test_bit(REPFLOW, sk))
+			fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;

[Severity: High]
This removes the pktopts read. Does the migration race described in the commit message still apply to ireq->ipv6_opt, a few lines further down in the same function?

net/ipv6/tcp_ipv6.c:tcp_v6_send_synack() {
    ...
		rcu_read_lock();
		opt = ireq->ipv6_opt;
		if (!opt)
			opt = rcu_dereference(np->opt);
		err = ip6_xmit(sk, skb, fl6, skb->mark ? : READ_ONCE(sk->sk_mark),
			       opt, tclass, READ_ONCE(sk->sk_priority));
    ...
}

reqsk_migrate_reset() hands ipv6_opt over to the clone along with pktopts:

net/ipv4/inet_connection_sock.c:reqsk_migrate_reset() {
	req->saved_syn = NULL;
#if IS_ENABLED(CONFIG_IPV6)
	inet_rsk(req)->ipv6_opt = NULL;
	inet_rsk(req)->pktopts = NULL;
    ...
}

inet_reqsk_clone() memcpy()s the request socket. Until the reset runs, nreq and oreq both point at the same ipv6_txoptions. After the reset, nreq owns it. When nreq is freed, the destructor releases it without waiting for an RCU grace period:

net/ipv6/tcp_ipv6.c:tcp_v6_reqsk_destructor() {
	kfree(inet_rsk(req)->ipv6_opt);
	consume_skb(inet_rsk(req)->pktopts);
}

So the rcu_read_lock() in tcp_v6_send_synack() does not protect opt. IPv4 does this differently: tcp_v4_reqsk_destructor() frees ireq_opt with kfree_rcu().

Could this sequence happen?

CPU0 (holds a reference on oreq) tcp_v6_rcv()->tcp_check_req()->tcp_rtx_synack()->tcp_v6_send_synack()

    opt = ireq->ipv6_opt;     /* still non-NULL */

CPU1
inet_csk_complete_hashdance() or reqsk_timer_handler()

    reqsk_migrate_reset(oreq);
...
nreq is freed, on accept() of the child or after an RST leads to
inet_csk_reqsk_queue_drop() and the last reqsk_put():
    tcp_v6_reqsk_destructor()
        kfree(inet_rsk(req)->ipv6_opt);

CPU0

    ip6_xmit(..., opt, ...)
        /* reads opt->opt_nflen/opt_flen, pushes opt->hopopt etc. */

Only calipso_req_setattr() sets ireq->ipv6_opt. It is reached through security_inet_conn_request()->netlbl_req_setattr() when a CALIPSO NetLabel mapping is configured. The race also needs:

- SO_REUSEPORT listeners with request migration enabled (net.ipv4.tcp_migrate_req or a BPF sk_reuseport migrate program)
- a listener being closed

The patch carries Fixes: c905dee62232, and the commit message names reqsk_migrate_reset() as one of the causes. Should ipv6_opt be handled here too?

[ ... ]

net/ipv6/tcp_ipv6.c static void tcp_v6_init_req(struct request_sock *req, · line 795

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -0
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
 	ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
 	ireq->ir_rmt_addr = LOOPBACK4_IPV6;
 	ireq->ir_loc_addr = LOOPBACK4_IPV6;
+	tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
 	/* So that link locals have meaning */
 	if ((!sk_listener->sk_bound_dev_if || l3_slave) &&

[Severity: Low]
This isn't a bug, but now that the flowlabel comes from syn_flowlabel, is the REPFLOW term still needed in the pktopts condition further down in tcp_v6_init_req()?

	if (!tw_isn &&
	    (ipv6_opt_accepted(sk_listener, skb, &TCP_SKB_CB(skb)->header.h6) ||
	     np->rxopt.bits.rxinfo ||
	     np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim ||
	     np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
		refcount_inc(&skb->users);
		ireq->pktopts = skb;
	}

On a REPFLOW listener with no rxopt bits set, every request socket still holds a reference to its SYN skb. cookie_v6_check() uses the same condition without the REPFLOW term, so the two places now differ.

One reader is left: IPV6_2292PKTOPTIONS in do_ipv6_getsockopt(), through np->pktoptions on the child. It only produces cmsgs if rxopt bits are set on the child after accept(). Dropping the term would change behaviour slightly in that case.

Could a follow-up remove the term so that tcp_v6_init_req() matches cookie_v6_check()?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102075441.3771550-1-edumazet%40kernel.org
author maintainer
#6 lore raw
Quoted 104 lines · Le mar. 3 nov. 2026 à 09:46, <[email protected]> a écrit :

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch fixes only half of the migration use-after-free (UAF) it describes.
- [Low] Leftover from this patch: tcp_v6_init_req() (net/ipv6/tcp_ipv6.c:799-806) still keeps a reference to the SYN skb…

--

tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

This commit adds a syn_flowlabel field to tcp_request_sock. The field is filled from the SYN in tcp_v6_init_req(), and tcp_v6_send_synack() now uses it instead of reading ireq->pktopts. The old read could hit a freed skb when another cpu completed the 3WHS or migrated the request socket.

net/ipv6/tcp_ipv6.c static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst, · line 582

Quoted 12 lines
net/ipv6/tcp_ipv6.c +2 -2
index e006a30360eae..d406cd3c8ceab 100644
@@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
                                  &ireq->ir_v6_rmt_addr);
 
              fl6->daddr = ireq->ir_v6_rmt_addr;
-             if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
-                     fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
+             if (inet6_test_bit(REPFLOW, sk))
+                     fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;

[Severity: High]
This removes the pktopts read. Does the migration race described in the commit message still apply to ireq->ipv6_opt, a few lines further down in the same function?

net/ipv6/tcp_ipv6.c:tcp_v6_send_synack() {
    ...
                rcu_read_lock();
                opt = ireq->ipv6_opt;
                if (!opt)
                        opt = rcu_dereference(np->opt);
                err = ip6_xmit(sk, skb, fl6, skb->mark ? : READ_ONCE(sk->sk_mark),
                               opt, tclass, READ_ONCE(sk->sk_priority));
    ...
}

reqsk_migrate_reset() hands ipv6_opt over to the clone along with pktopts:

net/ipv4/inet_connection_sock.c:reqsk_migrate_reset() {
        req->saved_syn = NULL;
#if IS_ENABLED(CONFIG_IPV6)
        inet_rsk(req)->ipv6_opt = NULL;
        inet_rsk(req)->pktopts = NULL;
    ...
}

inet_reqsk_clone() memcpy()s the request socket. Until the reset runs, nreq and oreq both point at the same ipv6_txoptions. After the reset, nreq owns it. When nreq is freed, the destructor releases it without waiting for an RCU grace period:

net/ipv6/tcp_ipv6.c:tcp_v6_reqsk_destructor() {
        kfree(inet_rsk(req)->ipv6_opt);
        consume_skb(inet_rsk(req)->pktopts);
}

So the rcu_read_lock() in tcp_v6_send_synack() does not protect opt. IPv4 does this differently: tcp_v4_reqsk_destructor() frees ireq_opt with kfree_rcu().

Could this sequence happen?

CPU0 (holds a reference on oreq) tcp_v6_rcv()->tcp_check_req()->tcp_rtx_synack()->tcp_v6_send_synack()

    opt = ireq->ipv6_opt;     /* still non-NULL */

CPU1
inet_csk_complete_hashdance() or reqsk_timer_handler()

    reqsk_migrate_reset(oreq);
...
nreq is freed, on accept() of the child or after an RST leads to
inet_csk_reqsk_queue_drop() and the last reqsk_put():
    tcp_v6_reqsk_destructor()
        kfree(inet_rsk(req)->ipv6_opt);

CPU0

    ip6_xmit(..., opt, ...)
        /* reads opt->opt_nflen/opt_flen, pushes opt->hopopt etc. */

Only calipso_req_setattr() sets ireq->ipv6_opt. It is reached through security_inet_conn_request()->netlbl_req_setattr() when a CALIPSO NetLabel mapping is configured. The race also needs:

Quoted 7 lines

- SO_REUSEPORT listeners with request migration enabled (net.ipv4.tcp_migrate_req or a BPF sk_reuseport migrate program)
- a listener being closed

The patch carries Fixes: c905dee62232, and the commit message names reqsk_migrate_reset() as one of the causes. Should ipv6_opt be handled here too?

This is a different issue, which exists independently of this patch. It is CALIPSO-only (ipv6_opt is only set by calipso_req_setattr()), and was mentioned in the changelog of e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt after an RCU grace period").

Both readers (tcp_v6_send_synack() and tcp_v6_syn_recv_sock()) already run under RCU,
so freeing ipv6_opt with kfree_rcu() in tcp_v6_reqsk_destructor() is enough.

I will send a separate patch.

Quoted 30 lines

[ ... ]

net/ipv6/tcp_ipv6.c static void tcp_v6_init_req(struct request_sock *req, · line 795

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -0
@@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
      ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
      ireq->ir_rmt_addr = LOOPBACK4_IPV6;
      ireq->ir_loc_addr = LOOPBACK4_IPV6;
+     tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
 
      /* So that link locals have meaning */
      if ((!sk_listener->sk_bound_dev_if || l3_slave) &&

[Severity: Low]
This isn't a bug, but now that the flowlabel comes from syn_flowlabel, is the REPFLOW term still needed in the pktopts condition further down in tcp_v6_init_req()?

        if (!tw_isn &&
            (ipv6_opt_accepted(sk_listener, skb, &TCP_SKB_CB(skb)->header.h6) ||
             np->rxopt.bits.rxinfo ||
             np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim ||
             np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
                refcount_inc(&skb->users);
                ireq->pktopts = skb;
        }

On a REPFLOW listener with no rxopt bits set, every request socket still holds a reference to its SYN skb. cookie_v6_check() uses the same condition without the REPFLOW term, so the two places now differ.

Quoted 7 lines

One reader is left: IPV6_2292PKTOPTIONS in do_ipv6_getsockopt(), through np->pktoptions on the child. It only produces cmsgs if rxopt bits are set on the child after accept(). Dropping the term would change behaviour slightly in that case.

Could a follow-up remove the term so that tcp_v6_init_req() matches cookie_v6_check()?

Yes, I already mentioned this. I have a net-next patch for this.

reviewer Reviewed-by on v1 1/1
#7 lore raw
In reply to Eric Dumazet
Quoted 49 lines · Eric Dumazet

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

  BUG: KASAN: slab-use-after-free in tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
  Read of size 8 at addr ffff88802b08b608 by task poc-ipv6-pktopt/5076

  Call Trace:
   <IRQ>
   tcp_v6_send_synack (include/linux/skbuff.h:3152 include/linux/ipv6.h:110 net/ipv6/tcp_ipv6.c:582)
   tcp_rtx_synack (net/ipv4/tcp_output.c:4719)
   tcp_check_req (net/ipv4/tcp_minisocks.c:762)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)
   ip6_input (include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:545)
   ipv6_rcv (include/net/dst.h:481 net/ipv6/ip6_input.c:119 include/linux/netfilter.h:325 include/linux/netfilter.h:319 net/ipv6/ip6_input.c:351)

  Freed by task 5074 on cpu 0 at 15.412249s:
   kmem_cache_free (include/linux/kasan.h:235 mm/slub.c:2780 mm/slub.c:6630 mm/slub.c:6757)
   tcp_v6_syn_recv_sock (net/ipv6/tcp_ipv6.c:1528)
   tcp_check_req (net/ipv4/tcp_minisocks.c:934)
   tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1826)
   ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479)
   ip6_input_finish (net/ipv6/ip6_input.c:534)

Request socket migration has the same issue: reqsk_migrate_reset() transfers ireq->pktopts to the clone, which can be freed while another cpu holding a reference on the old request socket is still sending a SYNACK.

The SYNACK timer itself is not an issue, because inet_csk_reqsk_queue_drop() calls timer_delete_sync().

Save the flowlabel of the SYN in the request socket instead, so that tcp_v6_send_synack() no longer needs ireq->pktopts.

As a side effect, the flowlabel is also reflected for SYN packets reusing a TIME_WAIT socket, as ireq->pktopts is not set in this case.

Quoted 7 lines
Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Fixes c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
#8 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 13 lines · On Mon, 2 Nov 2026 08:54:41 +0100 you wrote:

When IPV6_FL_F_REFLECT is set on a listener, or the net.ipv6.flowlabel_reflect sysctl has FLOWLABEL_REFLECT_ESTABLISHED, tcp_v6_send_synack() reflects the flowlabel of the SYN packet, reading it from the skb stored in ireq->pktopts.

Since commit 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table"), request sockets are processed without holding the listener lock. A cpu can then process a retransmitted SYN for a request socket, and send a SYNACK from tcp_check_req(), while another cpu receives the ACK completing the 3WHS. tcp_v6_syn_recv_sock() consumes ireq->pktopts when it wins the hashdance, and the first cpu reads a freed skb:

Quoted 1 line

[...]

Here is the summary with links:
- [net] tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()

    https://git.kernel.org/netdev/net/c/8e069fd3fd39

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html