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=XJUncblVQyXE+Y0BUEIRGZKQdQS6XD0AdMmbsbatrJOWfluOoCyYnZAZojG9nmD3Rsdz OUDFBlq5gJdWD1mm+QSHrkKbS+tTzuPSON4H3mf3XmkWfwjfrSrRI1yrrwuaT4KZb2zLm jeWYYw5tcyDEQeTjAXyJQ1fDH21Hev+Ju1NvEyXxglVkX8vmsv/wmdWZNUyJevP+fyBu8 31hr4Cle+dqDcNcCWsGwOh6u16lAGFMZ061kSM27/g0GfRmnsTUSJ49KjHRfNB1QX3zP9 KzgCaqohjMZkWA5lRSgdvhJyw8oMDCf+qLXk4v5y6+sdIyzS2ApuNBoAAbV476wzYyg== 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=eaaB+DvwJ02ccMXD7vyPOnPA/HRxP8Vnwq1z90fmejjqF5Cr2uluHAqAO5NBKwF9KOPY M7wz1RGF4OohqJUELaDuMffGhrP8+DhCKDdb/C2rUh0N4ZdtJhEaQR34Cx5GkkJ/9hPnU HoCWMUGaJiH4ljo4h38hTAQLE/DCwZGypojxgAWoRfr1200/rsmW34KUcyXLgq2GSUuEu k7433Ww4ygx077iFUZor3MO+UQ/VGr9KYQdfevqtZzpk/W5qSs8dreRPd8JNVS3fYLe2s 8VEcnvAu0lyIi9mZqofr8fRatahIOZmsmyR/Rl5uEwFYHvl1vtbCIRSYTGqgOIv7JVg== 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 9C512606D81B for ; Thu, 5 Nov 2026 20:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C512606D81B 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-cdb4c49e52fso2064657a12.0 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=vNdLJJ6Dp6HmLuVhcfep+/HmaXwnCey8ETT31+v+0jyNNbXZCcJwGUjnrshi/cIEPV dstCrRoKgERpWNKPuXduD2iXr7JYfU3pkLgi2sW4LzmzvhEPBgAlus/skucXyjoALlNk v5Y6ESgo8n2fayXSqbYol0mUo+yV7njcwnCPsv5VHX9kMexmohypDDAiF04xrV34icWI 84HmLrW1nfJZuq9dYELH41f7VAH2y2GyN4i+xc+FQLTF2kHQa+eHbR2U1nWpOrmUL577 p7SWYRRx1CeHAeQts/C3rIPIBRZxliBSCt1/Oh1sXDyPlXIKABerneJdyM/jwayw5cjt Qviw== X-Forwarded-Encrypted: i=1; AKwUvByUF/brXmPSWR+usoh8XsgdDHuC+ysfH7ZeyYrcZJv/nBM/5wcXfwhLLedgtKp0grwg8OlZjp8=@vger.kernel.org X-Gm-Message-State: APuU4Z+11tTfOF1MJ0yXSHtin79zWdKMneVLC/UUgNgaOkp8mwQDtyiR 2M+q1DYmKbJJ9l4TZsfVqEYCRtsUhgDsvZl/nKre0NxCJewgDzyRFY0UqFeNcKz+8U3NWNdzflt 7zmSsDw== 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: netdev@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