* [Devel] [PATCH hci-8.2 v3 01/10] ms/tcp: Fix potential UAF in reqsk_timer_handler().
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 02/10] ms/tcp: Fix imbalanced icsk_accept_queue count Eva Kurchatova
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Kuniyuki Iwashima <kuniyu@google.com>
commit 97c8a3c1f73d828de43a5a88e8a9a143efb2b661 upstream.
When TCP socket migration fails at inet_ehash_insert() in
reqsk_timer_handler(), we jump to the no_ownership: label
and free the new reqsk immediately with __reqsk_free().
Thus, we must stop the new reqsk's timer before jumping to the
label, but the timer might be missed since the cited commit,
resulting in UAF.
As we are in the original reqsk's timer context, we can safely
call timer_delete_sync() for the new reqsk.
Let's pass false to __inet_csk_reqsk_queue_drop() to stop
the new reqsk's timer.
Fixes: 83fccfc3940c ("inet: fix potential deadlock in reqsk_queue_unlink()")
Reported-by: Damiano Melotti <melotti@google.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260506035954.1563147-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit f7fba81b00699360f96ed7d9a47b8c801e74c6f9)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/inet_connection_sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 9736f35e4e97..7182115292b4 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1127,7 +1127,7 @@ static void reqsk_timer_handler(struct timer_list *t)
if (!inet_ehash_insert(req_to_sk(nreq), req_to_sk(oreq), NULL)) {
/* delete timer */
- __inet_csk_reqsk_queue_drop(sk_listener, nreq, true);
+ __inet_csk_reqsk_queue_drop(sk_listener, nreq, false);
goto no_ownership;
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 02/10] ms/tcp: Fix imbalanced icsk_accept_queue count.
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 01/10] ms/tcp: Fix potential UAF in reqsk_timer_handler() Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 03/10] ms/inet: reject unhashed sockets during established lookups Eva Kurchatova
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Kuniyuki Iwashima <kuniyu@google.com>
[ Upstream commit 7eca3292cac7c26dad4c236f51ba225c39a0523f ]
When TCP socket migration happens in reqsk_timer_handler(),
@sk_listener will be updated with the new listener.
When we call __inet_csk_reqsk_queue_drop(), the listener must
be the one stored in req->rsk_listener.
The cited commit accidentally replaced oreq->rsk_listener with
sk_listener, leading to imbalanced icsk_accept_queue count.
Let's pass the correct listener to __inet_csk_reqsk_queue_drop().
Fixes: e8c526f2bdf1 ("tcp/dccp: Don't use timer_pending() in reqsk_queue_unlink().")
Reported-by: Damiano Melotti <melotti@google.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260506035954.1563147-3-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit df8060ca14ac6061f6659927b8fd7d6ce07e99cf)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/inet_connection_sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 7182115292b4..2ccad559e962 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1153,7 +1153,7 @@ static void reqsk_timer_handler(struct timer_list *t)
}
drop:
- __inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
+ __inet_csk_reqsk_queue_drop(oreq->rsk_listener, oreq, true);
reqsk_put(oreq);
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 03/10] ms/inet: reject unhashed sockets during established lookups
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 01/10] ms/tcp: Fix potential UAF in reqsk_timer_handler() Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 02/10] ms/tcp: Fix imbalanced icsk_accept_queue count Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 04/10] ms/net: restore refcount ordering for lockless socket access Eva Kurchatova
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Hyunwoo Kim <imv4bel@gmail.com>
[ Upstream commit 4e2b3ef19e0e04adca38442f07dd6bc93c712bf1 ]
TCP established ehash lookups are lockless. The socket caches involved
use SLAB_TYPESAFE_BY_RCU, so memory can be reused before an RCU reader
that retained its old address has finished.
After a tuple match, __inet_lookup_established() and
__inet6_lookup_established() acquire a reference and repeat the tuple
check. They do not check whether the new object is hashed. If the
address is reused for a socket with the same tuple, the lookup can
acquire a reference to the new object and return it while its nulls node
is unhashed.
A PoC that drives reuse with a SYN cookie request socket reproduced the
crash. The new request socket is unhashed and has a NULL rsk_listener.
A lookup that had loaded the address of the old request socket acquired
the reference published by tcp_get_cookie_sock() and returned the new
object. tcp_v4_rcv() then read sk_state through the NULL listener.
The resulting crash was:
BUG: kernel NULL pointer dereference, address: 0000000000000012
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
...
Oops: Oops: 0000 [#1] SMP NOPTI
CPU: 4 UID: 0 PID: 0 Comm: swapper/4 Not tainted 7.3.0-00591-g0e135910deec #1 PREEMPT(lazy)
...
RIP: 0010:tcp_v4_rcv+0x44e/0x1280
...
R10: 0000000000000001 R11: 00000000024ca8c0 R12: 0000000000000000
...
CR2: 0000000000000012 CR3: 0000000103d50004 CR4: 0000000000770ef0
...
Call Trace:
<IRQ>
? raw_local_deliver+0xae/0x240
ip_protocol_deliver_rcu+0x2d/0x180
ip_local_deliver_finish+0x84/0x100
ip_sublist_rcv_finish+0x5f/0x70
ip_sublist_rcv+0x12a/0x1d0
ip_list_rcv+0xfd/0x130
__netif_receive_skb_list_core+0x223/0x250
netif_receive_skb_list_internal+0x1d2/0x2c0
? try_fill_recv+0x39/0x7b0
napi_complete_done+0x74/0x170
virtnet_poll+0x445/0x600
__napi_poll+0x27/0x1e0
net_rx_action+0x2fe/0x3b0
handle_softirqs+0xc2/0x2c0
__irq_exit_rcu+0x74/0xd0
common_interrupt+0x7f/0x90
</IRQ>
...
Kernel panic - not syncing: Fatal exception in interrupt
After taking a reference, check whether the nulls node is unhashed in
both IPv4 and IPv6 established lookups. If it is unhashed or the tuple
no longer matches, drop the reference and restart the lookup.
Lookups racing with the TIME_WAIT hashdance, or with a request being
replaced by its child, now restart and find the new socket instead of
returning the old one.
Request sockets that were never inserted into ehash can have a nonzero
refcount, and a stale lookup can hold a transient reference. Therefore,
when SYN cookie, Fast Open, and request migration paths fail after
setting a nonzero refcount, release the references held by those paths
with reqsk_put() instead of freeing the request directly.
Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20261029214219.1035176-2-imv4bel@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit d69100340b4cae08d40f898f1b601032403f6be6)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/inet_connection_sock.c | 10 +++++++---
net/ipv4/inet_hashtables.c | 5 +++--
net/ipv4/syncookies.c | 2 ++
net/ipv4/tcp_input.c | 4 +++-
net/ipv6/inet6_hashtables.c | 4 +++-
5 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 2ccad559e962..acbc104e6709 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1146,10 +1146,14 @@ static void reqsk_timer_handler(struct timer_list *t)
*/
if (nreq) {
__NET_INC_STATS(net, LINUX_MIB_TCPMIGRATEREQFAILURE);
+ /* The timer was not armed, drop its reference here. */
+ reqsk_put(nreq);
no_ownership:
reqsk_migrate_reset(nreq);
reqsk_queue_removed(queue, nreq);
- __reqsk_free(nreq);
+ /* Drop the temporary reference and the one reserved for ehash. */
+ reqsk_put(nreq);
+ reqsk_put(nreq);
}
drop:
@@ -1421,7 +1425,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQFAILURE);
reqsk_migrate_reset(nreq);
- __reqsk_free(nreq);
+ reqsk_put(nreq);
} else if (inet_csk_reqsk_queue_add(sk, req, child)) {
return child;
}
@@ -1477,7 +1481,7 @@ void inet_csk_listen_stop(struct sock *sk)
__NET_INC_STATS(sock_net(nsk),
LINUX_MIB_TCPMIGRATEREQFAILURE);
reqsk_migrate_reset(nreq);
- __reqsk_free(nreq);
+ reqsk_put(nreq);
}
rcu_read_unlock();
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 3fab3198d1f5..b0f0c7c45917 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -512,8 +512,9 @@ struct sock *__inet_lookup_established(const struct net *net,
if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) {
if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
goto out;
- if (unlikely(!inet_match(net, sk, acookie,
- ports, dif, sdif))) {
+ if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
+ !inet_match(net, sk, acookie, ports, dif,
+ sdif))) {
sock_gen_put(sk);
goto begin;
}
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 3976c821ecdf..153559eb679f 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -217,6 +217,8 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,
bh_unlock_sock(child);
sock_put(child);
+ reqsk_put(req);
+ return NULL;
}
__reqsk_free(req);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 1b2b62a52408..ce04031e944c 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -7348,7 +7348,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
if (!inet_csk_reqsk_queue_add(sk, req, fastopen_sk)) {
bh_unlock_sock(fastopen_sk);
sock_put(fastopen_sk);
- goto drop_and_free;
+ /* tcp_disconnect() already dropped one reqsk ref. */
+ reqsk_put(req);
+ goto drop;
}
sk->sk_data_ready(sk);
bh_unlock_sock(fastopen_sk);
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 9ec05e354baa..70633fed6e6a 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -74,7 +74,9 @@ struct sock *__inet6_lookup_established(const struct net *net,
if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
goto out;
- if (unlikely(!inet6_match(net, sk, saddr, daddr, ports, dif, sdif))) {
+ if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
+ !inet6_match(net, sk, saddr, daddr, ports, dif,
+ sdif))) {
sock_gen_put(sk);
goto begin;
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 04/10] ms/net: restore refcount ordering for lockless socket access
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (2 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 03/10] ms/inet: reject unhashed sockets during established lookups Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 05/10] ms/tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack() Eva Kurchatova
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Hyunwoo Kim <imv4bel@gmail.com>
[ Upstream commit 5b5d8f351dd96f56a58bb516a80e2d4d742fe4e2 ]
Before commit fb041bb7c0a9 ("locking/refcount: Consolidate implementations
of refcount_t"), default builds implemented refcount_inc_not_zero() using
atomic_add_unless(), which provided full memory ordering on success. The
commit removed that ordering on weakly ordered architectures, allowing
accesses after a successful reference acquisition to be reordered before
it.
Use refcount_inc_not_zero_acquire() in the IPv4 and IPv6 established
lookups and in inet_twsk_purge(), where the socket is validated again
after taking a reference.
bpf_sk_assign() can receive a socket pointer obtained through BTF
without a reference. Use acquire ordering when it takes its own reference
for a refcounted socket.
Use refcount_set_release() when setting refcounts in the SYN cookie,
TCP Fast Open, request migration, and TIME_WAIT paths. Keep the existing
TIME_WAIT smp_wmb(), which separately orders the refcount store before
ehash publication.
Fixes: fb041bb7c0a9 ("locking/refcount: Consolidate implementations of refcount_t")
Fixes: 27e5203bd9c5 ("bpf: Change bpf_sk_assign to accept ARG_PTR_TO_BTF_ID_SOCK_COMMON")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20261029214219.1035176-3-imv4bel@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 6f4fc93f76cd8ebd3c89a064573715503048d1ad)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
---
net/core/filter.c | 2 +-
net/ipv4/inet_connection_sock.c | 6 +++---
net/ipv4/inet_hashtables.c | 2 +-
net/ipv4/inet_timewait_sock.c | 4 ++--
net/ipv4/syncookies.c | 2 +-
net/ipv4/tcp_fastopen.c | 2 +-
net/ipv6/inet6_hashtables.c | 2 +-
7 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index b976eaabedd2..3b0ca58da7b5 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -7564,7 +7564,7 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags)
if (sk_unhashed(sk))
return -EOPNOTSUPP;
if (sk_is_refcounted(sk) &&
- unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
+ unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
return -ENOENT;
skb_orphan(skb);
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index acbc104e6709..6dff5a7145bc 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1070,8 +1070,8 @@ static void reqsk_timer_handler(struct timer_list *t)
* hold another count to prevent use-after-free and
* call reqsk_put() just before return.
*/
- refcount_set(&nreq->rsk_refcnt, 2 + 1);
timer_setup(&nreq->rsk_timer, reqsk_timer_handler, TIMER_PINNED);
+ refcount_set_release(&nreq->rsk_refcnt, 2 + 1);
reqsk_queue_migrated(&inet_csk(nsk)->icsk_accept_queue, req);
req = nreq;
@@ -1415,7 +1415,7 @@ struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
goto child_put;
}
- refcount_set(&nreq->rsk_refcnt, 1);
+ refcount_set_release(&nreq->rsk_refcnt, 1);
if (inet_csk_reqsk_queue_add(sk, nreq, child)) {
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQSUCCESS);
reqsk_migrate_reset(req);
@@ -1469,7 +1469,7 @@ void inet_csk_listen_stop(struct sock *sk)
if (nsk) {
nreq = inet_reqsk_clone(req, nsk);
if (nreq) {
- refcount_set(&nreq->rsk_refcnt, 1);
+ refcount_set_release(&nreq->rsk_refcnt, 1);
rcu_read_lock();
if (inet_csk_reqsk_queue_add(nsk, nreq, child)) {
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index b0f0c7c45917..866c758af08f 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -510,7 +510,7 @@ struct sock *__inet_lookup_established(const struct net *net,
if (sk->sk_hash != hash)
continue;
if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) {
- if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
+ if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
goto out;
if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
!inet_match(net, sk, acookie, ports, dif,
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index cf84a3c7de14..943693040a8c 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -139,7 +139,7 @@ void inet_twsk_hashdance_schedule(struct inet_timewait_sock *tw,
* Also note that after this point, we lost our implicit reference
* so we are not allowed to use tw anymore.
*/
- refcount_set(&tw->tw_refcnt, 3);
+ refcount_set_release(&tw->tw_refcnt, 3);
/* Ensure tw_refcnt has been set before tw is published.
* smp_wmb() provides the necessary memory barrier to enforce this
@@ -324,7 +324,7 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo)
if (refcount_read(&sock_net(sk)->ns.count))
continue;
- if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
+ if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
continue;
if (refcount_read(&sock_net(sk)->ns.count)) {
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 153559eb679f..bba484725a1e 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -204,7 +204,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,
child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
NULL, &own_req, NULL);
if (child) {
- refcount_set(&req->rsk_refcnt, 1);
+ refcount_set_release(&req->rsk_refcnt, 1);
sock_rps_save_rxhash(child, skb);
if (rsk_drop_req(req)) {
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 9c1173f1bddd..9764f72aeaf0 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -278,7 +278,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
tcp_reset_xmit_timer(child, ICSK_TIME_RETRANS,
req->timeout, false);
- refcount_set(&req->rsk_refcnt, 2);
+ refcount_set_release(&req->rsk_refcnt, 2);
sk_mark_napi_id_set(child, skb);
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 70633fed6e6a..dee00ba290f6 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -71,7 +71,7 @@ struct sock *__inet6_lookup_established(const struct net *net,
continue;
if (!inet6_match(net, sk, saddr, daddr, ports, dif, sdif))
continue;
- if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
+ if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
goto out;
if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 05/10] ms/tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (3 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 04/10] ms/net: restore refcount ordering for lockless socket access Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 06/10] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period Eva Kurchatova
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Eric Dumazet <edumazet@kernel.org>
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.")
Reported-by: Anvik Loitongbam <permissiontogallop@gmail.com>
Reported-by: Yingjie Wang <x-professor@outlook.com>
Closes: https://lore.kernel.org/netdev/82c31e4d5043f3dbd11b44177cfba779d335aae3.1793599929.git.x-professor@outlook.com/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Neal Cardwell <ncardwell@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20261102075441.3771550-1-edumazet@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
(cherry picked from commit 8e069fd3fd396b89af417e50b359bc9892dd41cd)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
---
include/linux/tcp.h | 3 +++
net/ipv6/tcp_ipv6.c | 5 +++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 6a5e08b937b3..c52d9348ef47 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -171,6 +171,9 @@ struct tcp_request_sock {
u8 ao_rcv_next;
bool used_tcp_ao;
#endif
+#if IS_ENABLED(CONFIG_IPV6)
+ __be32 syn_flowlabel;
+#endif
};
static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index d572bec5cc51..aec76c54327c 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -546,8 +546,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) |
@@ -798,6 +798,7 @@ static void tcp_v6_init_req(struct request_sock *req,
ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr;
ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
+ 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) &&
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 06/10] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (4 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 05/10] ms/tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack() Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 07/10] ms/tcp: free saved_syn " Eva Kurchatova
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Eric Dumazet <edumazet@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@kernel.org>
Closes: https://lore.kernel.org/netdev/179369559062.488856.15441115725436277776@kernel.org/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Tested-by: Linkui Xiao <xiaolinkui@kylinos.cn>
Link: https://patch.msgid.link/20261103090011.4128420-1-edumazet@kernel.org
Signed-off-by: Paolo Abeni <pabeni@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@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 07/10] ms/tcp: free saved_syn after an RCU grace period
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (5 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 06/10] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 08/10] ms/tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req() Eva Kurchatova
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Yingjie Wang <x-professor@outlook.com>
tcp_reqsk_record_syn() allocates saved_syn separately from its request
socket. bpf_sock_ops_get_syn() can load that pointer while processing a
retransmitted SYN under RCU.
There are two ownership transfers which can let another CPU reclaim the
allocation while such a reader is still using it.
First, tcp_move_syn() transfers req->saved_syn to a newly created child
socket. The child can be closed and tcp_saved_syn_free() can reclaim the
allocation before a reader of the old request finishes.
Second, inet_reqsk_clone() shallow-copies request_sock during request
migration. After reqsk_migrate_reset() clears the old request pointer, the
migrated clone owns it. However, a reader which already loaded the pointer
from the old request can still be using it when the clone is released.
I found this through LLM-assisted concurrency fuzzing.
Mark the request-socket saved_syn pointer as RCU protected and use RCU
accessors for its reads and updates. Keep the full-socket pointer plain
because all of its accesses hold the socket lock. Embed an rcu_head in
struct saved_syn and use kfree_rcu() in both teardown paths. This lets a
request-side reader which loaded the object before an ownership transfer
finish.
This follows commit e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt
after an RCU grace period"), which fixed the same ownership-transfer
pattern for IPv4 options.
The issue was confirmed with KASAN on v7.3-16007-g36aad21d50d1 using
temporary kernel instrumentation to widen the reader and request-migration
window. KASAN reported a slab-use-after-free read in
bpf_sock_ops_get_syn(), with the allocation freed by __reqsk_free() from
reqsk_timer_handler(). The same explicit migration test completed without
a report with deferred reclamation. A patched kernel without the delay
instrumentation also completed a successful migration and seven saved-SYN
reads without a KASAN report.
Fixes: 0813a841566f ("bpf: tcp: Allow bpf prog to write and parse TCP header option")
Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Link: https://patch.msgid.link/38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 2b9fd1a0abf0c1c7200be7a33cfeeca1c68089b6)
Rebase note: __reqsk_free() is still inline in include/net/request_sock.h
here, so the kfree_rcu() goes there. Mainline moved it to
inet_connection_sock.c with 22c1264415ef ("tcp: move __reqsk_free() out
of line").
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
---
include/linux/tcp.h | 6 +++---
include/net/request_sock.h | 5 +++--
net/core/filter.c | 2 +-
net/ipv4/inet_connection_sock.c | 4 ++--
net/ipv4/tcp_input.c | 2 +-
5 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index c52d9348ef47..5565cb4d0e31 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -578,13 +578,13 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog)
static inline void tcp_move_syn(struct tcp_sock *tp,
struct request_sock *req)
{
- tp->saved_syn = req->saved_syn;
- req->saved_syn = NULL;
+ tp->saved_syn = unrcu_pointer(req->saved_syn);
+ RCU_INIT_POINTER(req->saved_syn, NULL);
}
static inline void tcp_saved_syn_free(struct tcp_sock *tp)
{
- kfree(tp->saved_syn);
+ kfree_rcu(tp->saved_syn, rcu);
tp->saved_syn = NULL;
}
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index b07b1cd14e9f..27c7cbe1a5fb 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -44,6 +44,7 @@ struct request_sock_ops {
int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req);
struct saved_syn {
+ struct rcu_head rcu;
u32 mac_hdrlen;
u32 network_hdrlen;
u32 tcp_hdrlen;
@@ -73,7 +74,7 @@ struct request_sock {
struct timer_list rsk_timer;
const struct request_sock_ops *rsk_ops;
struct sock *sk;
- struct saved_syn *saved_syn;
+ struct saved_syn __rcu *saved_syn;
u32 secid;
u32 peer_secid;
u32 timeout;
@@ -133,7 +134,7 @@ static inline void __reqsk_free(struct request_sock *req)
req->rsk_ops->destructor(req);
if (req->rsk_listener)
sock_put(req->rsk_listener);
- kfree(req->saved_syn);
+ kfree_rcu(unrcu_pointer(req->saved_syn), rcu);
kmem_cache_free(req->rsk_ops->slab, req);
}
diff --git a/net/core/filter.c b/net/core/filter.c
index 3b0ca58da7b5..e9fe0b118985 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5740,7 +5740,7 @@ static int bpf_sock_ops_get_syn(struct bpf_sock_ops_kern *bpf_sock,
* not be available. It has to resort to
* saved_syn (if it is saved).
*/
- saved_syn = inet_reqsk(sk)->saved_syn;
+ saved_syn = rcu_dereference(inet_reqsk(sk)->saved_syn);
else
saved_syn = tcp_sk(sk)->saved_syn;
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 6dff5a7145bc..bf1abf88cae6 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -895,7 +895,7 @@ reqsk_alloc_noprof(const struct request_sock_ops *ops, struct sock *sk_listener,
req_to_sk(req)->sk_prot = sk_listener->sk_prot;
sk_node_init(&req_to_sk(req)->sk_node);
sk_tx_queue_clear(req_to_sk(req));
- req->saved_syn = NULL;
+ RCU_INIT_POINTER(req->saved_syn, NULL);
req->syncookie = 0;
req->timeout = 0;
req->num_timeout = 0;
@@ -987,7 +987,7 @@ static void reqsk_queue_migrated(struct request_sock_queue *queue,
static void reqsk_migrate_reset(struct request_sock *req)
{
- req->saved_syn = NULL;
+ RCU_INIT_POINTER(req->saved_syn, NULL);
#if IS_ENABLED(CONFIG_IPV6)
inet_rsk(req)->ipv6_opt = NULL;
inet_rsk(req)->pktopts = NULL;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index ce04031e944c..ab20950fedfb 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -7175,7 +7175,7 @@ static void tcp_reqsk_record_syn(const struct sock *sk,
saved_syn->network_hdrlen = skb_network_header_len(skb);
saved_syn->tcp_hdrlen = tcp_hdrlen(skb);
memcpy(saved_syn->data, base, len);
- req->saved_syn = saved_syn;
+ RCU_INIT_POINTER(req->saved_syn, saved_syn);
}
}
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 08/10] ms/tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req().
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (6 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 07/10] ms/tcp: free saved_syn " Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 09/10] ms/tcp: fastopen: note that a child socket was created Eva Kurchatova
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Kuniyuki Iwashima <kuniyu@google.com>
When connection migration happens in tcp_v[46]_rcv(), a new
listener is passed to tcp_check_req().
When either of the following is true,
* the new listener queue is full and
net.ipv4.tcp_abort_on_overflow is set
* the packet has RST or (not stripped) SYN
tcp_check_req() sends RST and calls inet_csk_reqsk_queue_drop().
Here, the new listener is passed, and its qlen is decremented
wrongly while reqsk is tied to the old listener.
Once qlen underflows, inet_csk_reqsk_queue_is_full() always
return true, and the new listener stops serving.
Without the patch, this script times out while waiting for SYN+ACK
since the new listener drops SYN, but with the patch, 3WHS completes.
0 `sysctl -q net.ipv4.tcp_migrate_req=1`
+0 `sysctl -q net.ipv4.tcp_syncookies=0`
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 setsockopt(3, SOL_SOCKET, SO_REUSEPORT, [1], 4) = 0
+0 bind(3, ..., ...) = 0
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4
+0 setsockopt(4, SOL_SOCKET, SO_REUSEPORT, [1], 4) = 0
+0 bind(4, ..., ...) = 0
+0 listen(4, 128) = 0
+0 < S 0:0(0) win 32792 <mss 1000>
+0 > S. 0:0(0) ack 1 <...>
+0 listen(3, 128) = 0
+0 close(4) = 0
+.01 < R 1:1(0) win 0
+0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 5
+0 listen(5, 1) = 0
+.01 < S 0:0(0) win 32792 <mss 1000>
+0 > S. 0:0(0) ack 1 <...>
+0 < . 1:1(0) ack 1 win 32792
+0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
+0 accept(3, ..., ...) = 6
Let's pass req->rsk_listener instead.
Fixes: d4f2c86b2b7e ("tcp: Migrate TCP_NEW_SYN_RECV requests at receiving the final ACK.")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20261111020304.1532064-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit a9782a6f2bbd0c444689725a710d8b21eab61bc5)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/tcp_minisocks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index bc1393dda551..d540af9ff6e5 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -904,7 +904,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
tcp_reset(sk, skb);
}
if (!fastopen) {
- bool unlinked = inet_csk_reqsk_queue_drop(sk, req);
+ bool unlinked = inet_csk_reqsk_queue_drop(req->rsk_listener, req);
if (unlinked)
__NET_INC_STATS(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 09/10] ms/tcp: fastopen: note that a child socket was created
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (7 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 08/10] ms/tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req() Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 10/10] ms/tcp: fix request_sock use-after-free during Fast Open accept() Eva Kurchatova
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Jeremy Harris <jgh@exim.org>
tcp: fastopen: note that a child socket was created
This uses up the last bit in a field of tcp_sock.
Signed-off-by: Jeremy Harris <jgh@exim.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Neal Cardwell <ncardwell@google.com>
Link: https://patch.msgid.link/20250423124334.4916-2-jgh@exim.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit bc2550b4e195754fbb24aac1f012d3dd9e3b4edc)
Taken as a prerequisite of 62754aad50d0b ("tcp: fix request_sock
use-after-free during Fast Open accept()").
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
include/linux/tcp.h | 3 ++-
net/ipv4/tcp.c | 1 +
net/ipv4/tcp_fastopen.c | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 5565cb4d0e31..07f0b949bff7 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -384,7 +384,8 @@ struct tcp_sock {
syn_fastopen:1, /* SYN includes Fast Open option */
syn_fastopen_exp:1,/* SYN includes Fast Open exp. option */
syn_fastopen_ch:1, /* Active TFO re-enabling probe */
- syn_data_acked:1;/* data in SYN is acked by SYN-ACK */
+ syn_data_acked:1,/* data in SYN is acked by SYN-ACK */
+ syn_fastopen_child:1; /* created TFO passive child socket */
u8 keepalive_probes; /* num of allowed keep alive probes */
u32 tcp_tx_delay; /* delay (in usec) added to TX packets */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4d6886a86246..bc0e987bd7e0 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3382,6 +3382,7 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->rack.reo_wnd_persist = 0;
tp->rack.dsack_seen = 0;
tp->syn_data_acked = 0;
+ tp->syn_fastopen_child = 0;
tp->rx_opt.saw_tstamp = 0;
tp->rx_opt.dsack = 0;
tp->rx_opt.num_sacks = 0;
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 9764f72aeaf0..9178d5ef1a78 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -404,6 +404,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
}
NET_INC_STATS(sock_net(sk),
LINUX_MIB_TCPFASTOPENPASSIVE);
+ tcp_sk(child)->syn_fastopen_child = 1;
return child;
}
NET_INC_STATS(sock_net(sk),
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* [Devel] [PATCH hci-8.2 v3 10/10] ms/tcp: fix request_sock use-after-free during Fast Open accept()
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (8 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 09/10] ms/tcp: fastopen: note that a child socket was created Eva Kurchatova
@ 2026-11-26 6:11 ` Eva Kurchatova
2026-11-30 15:50 ` [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Konstantin Khorenko
2026-11-30 15:51 ` Konstantin Khorenko
11 siblings, 0 replies; 13+ messages in thread
From: Eva Kurchatova @ 2026-11-26 6:11 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Hyunwoo Kim <imv4bel@gmail.com>
Commit e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
made inet_csk_accept() check tfo_listener before taking fastopenq.lock
to avoid taking the lock for connections that did not use Fast Open.
reqsk_fastopen_remove() clears tfo_listener while holding fastopenq.lock,
then reads req->sk. If inet_csk_accept() concurrently observes
tfo_listener after it has been cleared, it skips fastopenq.lock and
drops the last reference to the request_sock. This can free the
request_sock while reqsk_fastopen_remove() is still using it.
If the freed memory is reused for a new request_sock with req->sk ==
NULL, the reset path in reqsk_fastopen_remove() can append the new
request_sock to the original listener's list of requests that caused an
RST. After the new request_sock is freed, the next append writes through
the stale rskq_rst_tail into freed memory.
KASAN reported the following use-after-free when writing
fastopenq->rskq_rst_tail->dl_next = req:
BUG: KASAN: slab-use-after-free in reqsk_fastopen_remove+0x142/0x210
Write of size 8 at addr ffff888108230688 by task swapper/5/0
...
Call Trace:
<IRQ>
...
reqsk_fastopen_remove+0x142/0x210
tcp_check_req+0x96f/0xdd0
...
tcp_rcv_state_process+0x19c/0x26b0
...
tcp_v4_do_rcv+0x16e/0x490
tcp_v4_rcv+0x14a0/0x1af0
...
ip_protocol_deliver_rcu+0x39/0x1e0
ip_local_deliver_finish+0x124/0x1e0
ip_local_deliver+0xfb/0x1e0
...
</IRQ>
To widen the race windows, mdelay(5) was added after newsk = req->sk,
mdelay(20) after the if (req) reqsk_put(req) block, and mdelay(100)
after tcp_rsk(req)->tfo_listener = false. The KASAN report above was
reproduced with this kernel.
For the lockless check, use tcp_sk(newsk)->syn_fastopen_child instead of
tfo_listener, which reqsk_fastopen_remove() clears.
syn_fastopen_child is a field of the Fast Open child TCP socket
referenced by newsk, not of the request_sock. It is set before the child
socket is added to the accept queue. The paths that call
reqsk_fastopen_remove() in response to a remote ACK or RST do not clear
this field.
inet_csk_accept() uses this field to take fastopenq.lock only for Fast
Open child sockets and rechecks tfo_listener while holding the lock.
Connections that did not use Fast Open continue to avoid the lock.
Fixes: e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/avQKA_YTAThtbsYU@v4bel
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 62754aad50d0b30938bd8ce30b43474ce502a2af)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/inet_connection_sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index bf1abf88cae6..8af596b3e9e0 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -681,7 +681,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
newsk = req->sk;
if (sk->sk_protocol == IPPROTO_TCP &&
- tcp_rsk(req)->tfo_listener) {
+ tcp_sk(newsk)->syn_fastopen_child) {
spin_lock_bh(&queue->fastopenq.lock);
if (tcp_rsk(req)->tfo_listener) {
/* We are still waiting for the final ACK from 3WHS
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (9 preceding siblings ...)
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 10/10] ms/tcp: fix request_sock use-after-free during Fast Open accept() Eva Kurchatova
@ 2026-11-30 15:50 ` Konstantin Khorenko
2026-11-30 15:51 ` Konstantin Khorenko
11 siblings, 0 replies; 13+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:50 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
Applying as is.
All ten patches match their upstream commits, and the v2 items are
done in the patches. The "Patchess" typo is still in the v2 changelog,
which is not applied, so it does not matter.
On Thu, 26 Nov 2026 08:11:00 +0200, Eva Kurchatova wrote:
> request migration with net.ipv4.tcp_migrate_req=1 over IPv4 with IP
> options and IPv6 with a TCP_SAVE_SYN client, an RST to a migrated
TCP_SAVE_SYN is read from the listener, not the client:
tcp_reqsk_record_syn() checks save_syn of the listening socket. If it
was set only on the client, req->saved_syn stayed NULL and the path of
7/10 did not run. Nothing to resend, just for the next test.
Separate patches, not needed for this series. I added one more
mainline fix of the same ipv6_opt code to the existing task:
1. b4a2cc6d748d3 ("calipso: do not charge request socket options to
the listener").
https://virtuozzo.atlassian.net/browse/VSTOR-157090
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
` (10 preceding siblings ...)
2026-11-30 15:50 ` [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Konstantin Khorenko
@ 2026-11-30 15:51 ` Konstantin Khorenko
11 siblings, 0 replies; 13+ messages in thread
From: Konstantin Khorenko @ 2026-11-30 15:51 UTC (permalink / raw)
To: vladimir.riabchun, Eva Kurchatova; +Cc: devel
On Thu, 26 Nov 2026 08:11:00 +0200, Eva Kurchatova wrote:
> ms/net: backport request migration RCU fixes and lockless refcount ordering
>
> Mainline fixes for sockets whose data another CPU can still read after
> an ownership transfer, mostly with request migration, or after the TCP
> handshake completes on another CPU.
>
> Patches 1-4 are plain cherry-picks from 6.12.y. Patches 5-10 are picks
> from mainline, where patch 5 needed altered context, patch 7 is rebased,
> and patch 9 is a prerequisite of 10. Patch 4 uses the refcount helpers:
> "ms/refcount: provide ops for cases when object's memory can be reused".
> The IPv4 part of patch 6, e3f33b0a1d89, is already in this tree.
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.6.vz10, thanks!
[01/10] ms/tcp: Fix potential UAF in reqsk_timer_handler().
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/49597a14131f
[02/10] ms/tcp: Fix imbalanced icsk_accept_queue count.
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/76c663a5ce5d
[03/10] ms/inet: reject unhashed sockets during established lookups
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/041796135039
[04/10] ms/net: restore refcount ordering for lockless socket access
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/6f32dc02ccbd
[05/10] ms/tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/06025ba4b3e3
[06/10] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b06cfaa5696f
[07/10] ms/tcp: free saved_syn after an RCU grace period
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b31676b4fb10
[08/10] ms/tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req().
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/b3047d94bdc8
[09/10] ms/tcp: fastopen: note that a child socket was created
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/9826c58bf29b
[10/10] ms/tcp: fix request_sock use-after-free during Fast Open accept()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/5ffdc80849f9
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 13+ messages in thread