From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 9DD6F80033 for ; Mon, 23 Nov 2026 00:26:45 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AN0PVwG017869; Mon, 23 Nov 2026 03:25:32 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AN0PVwG017869 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="pGfLLUmo" Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AN0PCGW017806 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 23 Nov 2026 03:25:13 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AN0PCGW017806 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-6babdfe377cso92112a12.0 for ; Sun, 22 Nov 2026 16:25:12 -0800 (PST) X-Gm-Message-State: APuU4Z+doMlKw/IqLG9z0mGxkbMjg7dxqCqL7yePCamN8IM+O32LD95l r35lAX/Zhb0QLho5JCpqbxmbP1J3KwNEp5w4Hpb192N9hzWxTazzpdH8QdzoiYNrseBuwq+Nda2 +yiV98eYZ7PpxSkT+gSY/Kx0BjriqHFE0g6qpCF95K35EIn6fhPSiwg== X-Gm-Gg: AZFdTZf46MYz9B8aU8R9FYE8eP8j8IclFh9s6CP6+1tkWa5RCXSQitNz78Lbt1I+nh+ 4QIvE0TFKdwK8keeBKtKHXRAz6LaB65GWidbe4z2tJfXIC+Yv+SsqdWStGx7+bS9ybJHhhcg6d5 7NUKtNXcTFd8Fn62slCrAHlz5C8fKcMJP1aO9uk9KUiD+op/QdtWQitfaQUwMAdPcPdhr2sr4JQ Mmr/3RjIh28lsdyE0NF0gx+F79j88oH9rGZ8oGqomTyLP66HDnoaKd14o0+krkRO1n/hQq1+FhL FeJwu9E2eeOrSpKPWteKkseS4amB+6aOuu6Q96D8+8L1mVIqhjKCXJEUCZTAkog65qLEzVVsOiz Z3a2ftViJpmYuHmYTmMEJs/4p1g== X-Received: by 2002:a05:6402:540a:b0:6b1:c5c3:9624 with SMTP id 4fb4d7f45d1cf-6ba37e75559mr7113464a12.22.1795393512314; Sun, 22 Nov 2026 16:25:12 -0800 (PST) X-Received: by 2002:a05:6402:540a:b0:6b1:c5c3:9624 with SMTP id 4fb4d7f45d1cf-6ba37e75559mr7113457a12.22.1795393511886; Sun, 22 Nov 2026 16:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795393511; cv=none; d=google.com; s=arc-20260327; b=QeYh2dg/OIUGTTIwLOD5rT0KwKhgk8yF5XrZFa/fzacv9bX0gBtK2RfspCmNROXUDv Y0Zop2pTeDHQ+24C7E6SMr45d2q+XgcJBj+W1G5m6D/1fZ82q80qUiMkAQAWviHt/Vid 0p5usfnpxtRt+PryaFtoz4CzroUnN+twgkVxXriAp98gMgB0zs1AWx5YRPwdg7hbaPfg yvkDEi9WZQC4uoWAq4eTWCmsh3EKRYctpVhlkirbXJcnaNwCoEVGt08Y0FHKxbIBQw1r X3KtheJdLYgxJUYKQkl6giC59bbXf2Te+S7uPWFsgrICJGgKDY1m91JmDv5lmIvM/93v A37w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ugvk+6+iQr1L7U5rK39B2F15+Xb4xxXKajyvUBXFNTk=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=NQGkmtitBSBcoSV98OMjerLGkG1H9/UMlNqSfXH8mK+MOVVzvYVMpp8PcA7lNT7q9w btdrhHjXq4P+4wokxkh3D+7frOjV3ZNfnUcA3Cx7F3RA/Uizf+uFRwR24WKsBt6VxhrZ rOogVyBEz/InznOylXtE1SnfelaPM+DSviRz+eXaoW7vvSXo3ROyDsLgVlit0GRGCAcZ +jd94HNmmI2JHblBFhcHPsYrbUDK0wvDWrbCTRgZ0FDEbYGTz6iubyZP4UD08c02x+/j uCrl+sR5K7ZZc2NXZUNkp27oPtmDaELyhyKefVCkPO7VEY8eZF++oVjougI9ptDuCZ82 5iPg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=pGfLLUmo; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6baa76c8624si2070796a12.224.2026.11.22.16.25.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 16:25:11 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=pGfLLUmo; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=ugvk+6+iQr1L7U5rK39B2F15+Xb4xxXKajyvUBXFNTk=; b=pGfLLUmoUFDJ 8Fz7BE+lVrsyQg69lUFL0Z2k+mcxiWpQRfGrpIY/wyP/V3/Xk1gaf3bh9EhzwsMkr3Ezp0CwoiOng r6gmRjpe1HWlqf1GGeuwABcxVQJZW8DO/OibWlxgVOqVq4AQmySqcXVSGPUUbzV2LXL28SDDJGEnQ bt87bsvVpTFuHIHZtLO01hnrJxbZ3DeVDCVgLbPzkjTVZ6LsA6gFi9IGvy8QjeBOxu3l6zvDg9C3P g9d1dOMTNt84W5uigQZmczWMAcEVoaK8v/2+XcTkpd6xmRi0AtJ29YUIjD+LAuPZs9h+h+TYfqnNL AgBCPvsEnvnUdPD+uKfdeg==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xVHrk-003eek-0A; Mon, 23 Nov 2026 01:25:04 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Mon, 23 Nov 2026 02:20:25 +0200 Message-ID: <20261123002500.1652289-5-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123002500.1652289-1-eva.kurchatova@virtuozzo.com> References: <20261123002500.1652289-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 4/4] ms/tcp: free saved_syn after an RCU grace period X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Yingjie Wang 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 Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com Signed-off-by: Jakub Kicinski (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 --- 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 254646530dc8..ef0fe6492277 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 1b2b62a52408..8388af69720e 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