From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793911012; b=Tm2RBA5zHXZc63EKbztrz49FF23HlbIhbtTEyjppg7az0ZoD5uzF0tO5v8jlDvzloVa6 gIxl1hgirBWBEpcoKx1FhoAgWn/hkGVKl9sfyQa4BK/9Wl9IyYH+J6THI2T0bYfr7ysZT LgOj2fHfv1tiHREon26rvIEurX0gww4AGP8GT4u4e8ePRgRT98xMPbUbn/+KO+kzFkA6j Bgcy7DEUqjWhKbsC7Js8tLLFGDqcax6zGgjBMrZJjhDIBpMBZsMx8OA9Uu2yQZhTQIyJU z/VHCWHsZdWnb0DFxfFvnPnoXi5/JkMcHyLLOPAawEH5xilu8lB5ks+L17Czbn6pdNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793911012; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=Ho0ssxdcOFZYydNEqXR/HyGk3gfggTzWbAzroYVX1OE=; b=V1tCkVhT62b4tptbELeJ1f8SGhIvKyhZsNADyMluqL3JsbGV4bCdlkDwt9Da+/38WKiA K+V8RGPem+cUHgdAwPetLGfWg/PjtWftwT3MiHVVT2TQbMhIZHYOLSynTvRdlVw5ykv57 rXKkfxw9BecaZQkEq0ayDV2k86dB0NDmbxiPzcGxHXxvHfObmqBkbtILVfi88tsBHIvNj cdeaKAnxDqe5rmY1JQtyur30LpN6dVJaht5gV7PIYhDggsKddMt1ZrqNT+LllpoyiyWSb xi/uRqt8SDr/aRAXBxPGtv/UAQMd6p4T69aeSXgA5gA57x9rZTlNqu/meB4TAlWQdeQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Ww0Od+k6; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C540606D81E for ; Thu, 5 Nov 2026 20:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C540606D81E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Ww0Od+k6 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cd5ca3840c5so2713405a12.2 for ; Thu, 05 Nov 2026 12:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793911011; x=1794515811; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Ho0ssxdcOFZYydNEqXR/HyGk3gfggTzWbAzroYVX1OE=; b=Ww0Od+k6WA74rbnGWCyPafAGJwjeDn1zHh7oJWkaWumgIa6Wy+e5IlIqTWjI7w6GYd C6cJe85FRieOS64oVYv5URhTugXLp52pjBylTbvV8WcaB4AbgqHDVzvCWQdRa0xE6vi1 YxjurHWH1nWasxOOJVPy7eyMiUu7PfoPd/5mTJOeSx0z4LVN7sqL+W+B+HdigvItufdV CXaTu0ebmA3QFMUvX5aTAXUf2zufir0N/4WAoE5QL7GnTqnAIWYzFM+1UoqZbSElpcbI dr1NZzihgJNWbVrSgE/0TihQHwfsphK2MjMQZpwIcEP7jS6DRCk2Wz9nPUc/H94c4Q/2 LYsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793911011; x=1794515811; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ho0ssxdcOFZYydNEqXR/HyGk3gfggTzWbAzroYVX1OE=; b=d0lRJ2D3yAG5K2o4wT7aywYnf6GjLtHCMkmy0D8nCI6Odqm6jwkn5V2oQjlomlGGr7 umvE8apJlKY1eEzqfsNIWuqHG3bJw+6QoPP1PsnhWlRtMvmzLAioq6/cfOy/rPvUUih9 p88YvjyV10EIDMEXTrc60R8r12X3pAX+RjH7SOZbUxKGrkMliOkTxLFmfIs3iNuVziv8 GZxgab1aYwBGuu+Q4UEBwQbTFr2U0/fLg5oC70T4Ff0QgSxsEpsW7VzpHp9eN0QyhOF7 g9NnHl3qCEdsZhktNX3RlsOcti1HiVu3/4HMNK2K5J9DpcRsZpE06LKHp/bNYf9pv2bS a/Tg== X-Forwarded-Encrypted: i=1; AKwUvBxyEriC6TgdcsAaSpwwJiSWsRToxBzDHKycShxCZ7cVCMwcfiGvlDcxlpFrEzV57fAnQxGuWT9yZ60j5t8=@vger.kernel.org X-Gm-Message-State: APuU4Z/SAYTkJoFtzz56Axa5a5KT4e0jRYVTU525ugLtVW8cqsVppvh9 hxlzPSv9XjGtn0QEmi/VSPRd83BzLYfepa8sxhVSBAWsqPnVggVL+T4hVxb8COB6gwREXi2FV2B AEspvMw== X-Received: from pgca13-n1.prod.google.com ([2002:a05:6a02:638d:10b0:cd8:5a84:95f]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:db09:b0:3e2:7c10:d46b with SMTP id adf61e73a8af0-3ebb29af117mr653557637.13.1793911010709; Thu, 05 Nov 2026 12:36:50 -0800 (PST) Date: Thu, 5 Nov 2026 20:36:50 +0000 In-Reply-To: <38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com> Message-ID: Subject: Re: [PATCH net v3] tcp: free saved_syn after an RCU grace period From: Kuniyuki Iwashima To: Yingjie Wang Cc: Eric Dumazet , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Daniel Borkmann , John Fastabend , Stanislav Fomichev , Martin KaFai Lau , Alexei Starovoitov , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" On Wed, 04 Nov 2026 12:32:19 +0000, Yingjie Wang wrote: > 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