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 8482A80027 for ; Wed, 25 Nov 2026 06:23:13 +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 6AP6LxpN016544; Wed, 25 Nov 2026 09:22:00 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6LxpN016544 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="lnroBcDR" Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP6Lc23016485 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 09:21:38 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP6Lc23016485 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-6ba62acd927so4303363a12.3 for ; Tue, 24 Nov 2026 22:21:38 -0800 (PST) X-Gm-Message-State: APuU4Z+kLZrQsDO6sxeLiao+5Q09QpukZCm7Q3JwkhwC/+x47W8BsSRL msGQ1jrR509XUUk7YRiHhXDzOieu7wH+8247LAxbgd8sVaHa2QBgJ/Y8t7VPtpTLRutUnS4qT6t 44RnGgZ5Yfg3x+6kIj6AJKccf6+vIn5bm+Sdqq3gSDIDbtM/4HfYVBA== X-Gm-Gg: AZFdTZe0khgBXqE9IixfSQ9Q61pxPNMMShXHVrFkWT2+umsBZ+eBiddbNRgHQLAkZ3M 0g8K2SiCgCoTSVRAxbmLNcTE58zUu6bRF+hXM3zM2F68IV6cUIJrJXiLxTvh2QzFMb4oNSufTZV oeHuHaW0HV1UKElvpbOsvexo2cRCtEmUaGzBRUvu5qgQCLZOzbhJ0WU3X7uJTp8P+DEjvOPujO9 mmbIfJAD4eNccxhXIhiE0gx7Gzv4cYVywROyJd8kYO4BK5EyT0IP05hEST1eRTGrlorE1RwN9OP yccF6myNgcm9V8WdOm46/fptDC9Kdl+EZyxL+wvwbIHPawPtlvs6VcsxMbOusGkx5+TjllTTIeX 1/fZ0/Vwr+c5qE+jRR6m0J27Q X-Received: by 2002:a05:6402:1603:b0:6b9:f00b:6553 with SMTP id 4fb4d7f45d1cf-6ba37d6289cmr9054084a12.11.1795587698049; Tue, 24 Nov 2026 22:21:38 -0800 (PST) X-Received: by 2002:a05:6402:1603:b0:6b9:f00b:6553 with SMTP id 4fb4d7f45d1cf-6ba37d6289cmr9054074a12.11.1795587697621; Tue, 24 Nov 2026 22:21:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795587697; cv=none; d=google.com; s=arc-20260327; b=W6VUQTivhb3dhjlpWLgS30B/x8S9cfeeh+SZUKg1L7ZqT/k39mmBO6qlD7GtTsShHl 6l/C887pRE7hKe6KG9lb7+XQOv41xhaz+j2WF/T2P/quvpN8CrELnHKf3aOhhVjIP0AI sLpWwPopkmvuVlDh/gRnQycRzrbg4wUVa8VkuvCE9Qkadm72bOBh7FP38J6bbH7Ab86N ehSnjYQc3Hns3HrRM4ccn7yS1s2atJ35/kgPjGvBA+WHVcYoTGuETEI+yU3rmtTGRcUH bezqIa2ISYDRTYx4zMSPod08fnpaaZvl8jzjHqEC9yDUtowSym8qMvzTNT/CAtksZ5UQ c2Hw== 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=Xbpps0KvQ1hsx2uCLB0uHg6YqMU+VETkyUqBlTofNNw=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=i9jZrVIrPDhaoFWPdWcU2LDuBnw6Xz6sfC/EK+SrLN2tc1c2vQyi5eRthT0T7bHS2M pdkyDSWhZnjf05FkgZOj56IcVWp0NmLWe0PlL2Z/01Zk8CiTwkUNE0xsgp3PscxeM/73 z0mGG6mar+S2bPLauXAF6ivWCahGSYHreLT24GQDwdamH0wlptEhVo76LU1gEY6ZBl8I jMB03yN2GfajLVYx3ZarKp7/Fxe6GrsxgodccX1wzSAiz+GdePqCEE549OWI0eB3AgYW RVQwRPAnqrloKC5ChM1oZI4XPwabZHusIzu7fYgIy+FDJzZqz2AgBG/duof8t3KiK2bA XNrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=lnroBcDR; 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-6bb1294fb4dsi2181125a12.7.2026.11.24.22.21.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 22:21:37 -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=lnroBcDR; 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=Xbpps0KvQ1hsx2uCLB0uHg6YqMU+VETkyUqBlTofNNw=; b=lnroBcDRofdB oDIP2MTYs4CtP4NjLOL93FbuPhDxDBS+Df0SDDbzhqNz59Vxu8dUcufpJ7cUEXhBgESCdLTh9jgL7 pbUV7M4UzLoeNKV70JveScoeX2VvgADf04s3zLpcve156hLIbUkKlZbrEXoAYcW3HBYcx+5euhVZO KM8x2cGZSITlh/+uqZ2Ra3O/dYtLWlDoRapQuMqKFhYQ7Ly12laccT1Vf/aJx9Hk3OYiwzta85N8U +XV+XTVE8SIKXVNzmU0Ji1Hw6Lp9Zh6/7IuYPXD/G7kzFUpl01UHPBk/ed336asCHwgsTfK6aPMNW x5oEyJsxQsSYQkC2D0mEvQ==; 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 1xW6Ni-006mb7-12; Wed, 25 Nov 2026 07:21:36 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Wed, 25 Nov 2026 08:14:15 +0200 Message-ID: <20261125062128.1996509-6-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> References: <20261125062128.1996509-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 5/8] 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 Reviewed-by: Sashiko --- 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 05ccc95cd7bd..63af4334d65c 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