From nobody Sat Jul 25 20:47:02 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C35134388A for ; Mon, 13 Jul 2026 23:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783985556; cv=none; b=N9GNtUYQ1hW5jk3kx+vYHQb1MHw8gjv4qDfFRVaLXKlH6thM8NuxMnaiUMNbTj8hdI1aiETbuakF2F4lh2dJVW3SzOqace0vAcqa7Ih0hMSX4no4VQqvhQLY1KJG575SPQlKiQ2uHTBoH6rg1K+gPomYS6/r1xHTO8z3tQR70GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783985556; c=relaxed/simple; bh=I8cVX0/mSzLFIdIg9RF+8d27raSzMYxFSQj1EqVpbcI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=N3GXS/l+ZURrXurjvIQ1koMzbnw0ijUk8yxUMPEt5wxtDT+SV2xQgpxVqexMInf4RdxigfeFj2qMhq2oYyVGipUy9PoHTeK1kUyKjelEzxznIR1uH/c4gCWMifZT5NPc04aCEXmn7akOi19bKEVJnWkpEDD/dLDEUAWGg8UZYw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b=FH5Wd08z; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b="FH5Wd08z" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-385ea3ce80dso3980499a91.2 for ; Mon, 13 Jul 2026 16:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1783985553; x=1784590353; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=qnqTky8wONGeiH1Gjpg0s2khivj3YtWdqTGDCWAoFvc=; b=FH5Wd08zO5yTrpsQlVjNAP2cU0nZJ7T2Brms80ecwbjWAhau+qKsDrWrcwyerI3sSB lp9fv932Z8xCOwKr+69IxAtHChcEw1O+1XXUVMYLVE3Jwo1+6oIGobP1zxNB+8UmNSIK wEUh60zXXY1N3jtqlX12CJL8E3LPvQGp1QL4uWIMUVbxGvy2Vv7yNRog/4o5kQLy1x6i 2POgAgbXxE9/KABUybmpp4YOmjzm8smRz32i+q+UHY3IUmXJf9bvuZEbTsWqmlQQCYqa XbNta21lW8mKHG6X3aBWsttFU9WoANsjcH/zaGcd9O+T3TSD2IXrhd4yAoDeOsUfnhtN GL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783985553; x=1784590353; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qnqTky8wONGeiH1Gjpg0s2khivj3YtWdqTGDCWAoFvc=; b=hVR0Vd7vrVWVfpu6C/qVL5PtGBtK5ukLh/rf5DdzYW7Msdq7iRLkuRhXd+L9LyfTjm ThUsPmeQXLkZNIomflZLxejdRur1YvJW9gWyCfDfDa/rEUNo4pitsY0U86/8OEQd/PLb y8plgrjS1gLLkSVUaAYibjol1bjQVQe9etw/Njosvr0bjfNowBqSq/XI9cjYBPhnPHBl YfUbuH4BmOFjFPz3IEAAwxm9T/joi8IdcXyEvyBJqQU4vPOsZMecmtALHF0Y5CqLQ/AZ tAzt1NTRkbNs0kv4vfaBtdAUqE+6ZmZwpPApWaXZrogYO/4yEBIJJ77EWYnxJI1zfMQ/ W9rA== X-Forwarded-Encrypted: i=1; AHgh+RrsiXf3rOKc6pVoLWLoC2Gctvd4rEYtyb0zNuWEB8ZgYDcVrF1IoRZwKFtF2G+qEH+KBeOASuFHa0ZuJJI=@vger.kernel.org X-Gm-Message-State: AOJu0YxOBhb8ItzSKvFl4u1YPgsSr/EoTgT49nX6hsuFiPnr1kRYiN1q qq3jiw1v7at0ftfYZaJYidob0Ftg0smq9CGTt8qIdaSqJUHPqHFXW1BbounRMRRcUA== X-Gm-Gg: AfdE7clAae1eOBK85mv6KIbu6s1G4HJMYwoNszK098nHHW7p0wBOHnveBuVl8WlOrPM qJ+MFSGH25tB09gKiYcYM64S2tA9IIUI5W5mo44OJZddPS2ooDmtewLoQqM54zWCsRUzJ37pFTM pT6za/qjPBd5QSBSiT/ZHI213TI0KoOu2P+L4MlAUv0+CE2en2EQT4O/hoqEhXkq+dUISlkOhe2 svqgCvMQPqlW1BVZv+zAFD1NgcHJVkM4O7aSSVXqj/asa/zDU7aMlO/2CIR/fUzrlyMFFh7+dGE Q5GCZFokzRVMLYnQvr2HNNmw8zgQYcap0PPhiIpeIyZaW5cj8RtLsNC3DC0oPzt5ISpwbOKdhvs epcPDAG4KPFXS2wlGwNTWr72I0uX3CjyS7Q1krRXtPdfynryoc1iBmUsfzSLYGoYpvn/jbjfuF6 sRvP3NmqkmOrzXrRB+/Q== X-Received: by 2002:a17:90a:ec8d:b0:380:9d0d:7ade with SMTP id 98e67ed59e1d1-38e17c7f921mr894108a91.0.1783985552902; Mon, 13 Jul 2026 16:32:32 -0700 (PDT) Received: from xiang.tailc0aff1.ts.net ([20.171.14.70]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-311b00048a3sm44507367eec.5.2026.07.13.16.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 16:32:32 -0700 (PDT) From: "Xiang Mei (Microsoft)" To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Jordan Rife , Martin KaFai Lau , Stanislav Fomichev , AutonomousCodeSecurity@microsoft.com, tgopinath@linux.microsoft.com, kys@microsoft.com, "Xiang Mei (Microsoft)" Subject: [PATCH net] bpf: tcp: fix double sock release on batch realloc Date: Mon, 13 Jul 2026 23:32:30 +0000 Message-ID: <20260713233230.3553593-1-xmei5@asu.edu> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" bpf_iter_tcp_batch() releases the current batch via bpf_iter_tcp_put_batch(), which drops the socket refs and rewrites each slot with the socket cookie, then grows the batch. cur_sk/end_sk are kept for bpf_iter_tcp_resume(), but on realloc failure the function returns ERR_PTR() before resume runs, leaving cur_sk < end_sk over slots that now hold cookies rather than sock pointers. bpf_iter_tcp_seq_stop() then calls bpf_iter_tcp_put_batch() again and dereferences a cookie as a struct sock. Empty the batch on the failure path so stop() does not release it again. The sockets were already freed by the first bpf_iter_tcp_put_batch(), so nothing leaks, and a later read() rescans the bucket from the start instead of skipping it. The sibling GFP_NOWAIT failure path still holds real socket references and is left for stop() to release. BUG: KASAN: null-ptr-deref in __sock_gen_cookie Read of size 8 at addr 0000000000000059 by task exploit ... __sock_gen_cookie (net/core/sock_diag.c:28) bpf_iter_tcp_put_batch (net/ipv4/tcp_ipv4.c:2918) bpf_iter_tcp_seq_stop (net/ipv4/tcp_ipv4.c:3270) bpf_seq_read (kernel/bpf/bpf_iter.c:205) vfs_read (fs/read_write.c:572) ksys_read (fs/read_write.c:716) do_syscall_64 entry_SYSCALL_64_after_hwframe Kernel panic - not syncing: Fatal exception Fixes: cdec67a489d4 ("bpf: tcp: Make sure iter->batch always contains a ful= l bucket snapshot") Reported-by: AutonomousCodeSecurity@microsoft.com Signed-off-by: Xiang Mei (Microsoft) Reviewed-by: Eric Dumazet Reviewed-by: Jordan Rife --- net/ipv4/tcp_ipv4.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 209ef7522508..dd3ed62704f9 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3141,8 +3141,11 @@ static struct sock *bpf_iter_tcp_batch(struct seq_fi= le *seq) bpf_iter_tcp_put_batch(iter); err =3D bpf_iter_tcp_realloc_batch(iter, expected * 3 / 2, GFP_USER); - if (err) + if (err) { + iter->cur_sk =3D 0; + iter->end_sk =3D 0; return ERR_PTR(err); + } =20 sk =3D bpf_iter_tcp_resume(seq); if (!sk) --=20 2.43.0