Article View: linux.kernel.netdev
Article #4190[PATCH bpf-next 15/38] bpf: Fix NULL deref in the sk_storage map iterator
From: Alexei Starovoitov
Date: Sat, 17 Oct 2026 01:24
Date: Sat, 17 Oct 2026 01:24
41 lines
9792 bytes
9792 bytes
From: Josef Bacik <josef@toxicpanda.com>
bpf_sk_storage_map_seq_find_next() hands out an element only if its
local_storage pointer is set. __bpf_sk_storage_map_seq_show() then reads
the pointer a second time and dereferences it without a test.
Since bpf_local_storage_destroy() unlinks the elements with
bpf_selem_unlink_nofail(), the pointer is reset to NULL when the socket
which owns the element is destroyed, so it can change between the two
reads. Reading the iterator while sockets with an element in the map are
closed ends in a NULL pointer dereference. The sockets need not belong to
the reader: where a program gives every new socket an element, an
unprivileged user who opens and closes sockets is enough.
Skip such an element, as the TCP and UDP iterators skip a socket which
has been unhashed.
Fixes: 0be08389c7f2 ("bpf: Switch to bpf_selem_unlink_nofail in bpf_local_storage_{map_free, destroy}")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/bpf_sk_storage.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
index b5349bec5695..aea67b446c7c 100644
--- a/net/core/bpf_sk_storage.c
+++ b/net/core/bpf_sk_storage.c
@@ -813,6 +813,9 @@ static int __bpf_sk_storage_map_seq_show(struct seq_file *seq,
ctx.map = info->map;
if (selem) {
sk_storage = rcu_dereference(selem->local_storage);
+ /* reset since ->next() looked: the socket goes away */
+ if (!sk_storage)
+ return SEQ_SKIP;
ctx.sk = sk_storage->owner;
ctx.value = SDATA(selem)->data;
}
--
2.55.0
Technical Details
Message-ID:
<20261017012451.364800-7-alexei.starovoitov@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347601-linux-kernel-netdev=dewy.ruReferences:
<20261017012058.355787-1-alexei.starovoitov@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347601-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next 15/38] bpf: Fix NULL deref in the sk_storage map iterator
Date: Sat, 17 Oct 2026 01:24:28 +0000
Organization: Usenet Network
Message-ID: <20261017012451.364800-7-alexei.starovoitov@gmail.com>
References: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2934344"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YMqipv0iKj/ZEP3e4B4mIozhiu4= sha256:vhp2TDMfdTCrpIB0rlRAP3vPznk0V3VkUEsLFoggya4=
sha1:UoOGfTNxC9wJjVoC6Epfl/uG99s= sha256:feoIznl2fRm/ztDyzoQNJ23lgPYaHj1g1ocELeN/VJM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 7C9BD110641; Sat, 17 Oct 2026 04:27:21 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id Q8ANCQBE_ovr;
Sat, 17 Oct 2026 04:27:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-347601-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 1741E11063F; Sat, 17 Oct 2026 04:27:11 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id 01CD937C8D; Sat, 17 Oct 2026 01:27:09 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id C683E370AD7;
Sat, 17 Oct 2026 01:27:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mJy0ZHQy"
X-Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52])
(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 A32C236AB54
for <netdev@vger.kernel.org>; Sat, 17 Oct 2026 01:27:06 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792200427; cv=none; b=gdQNspBHxEpxu/PRPQfH9kjaOJZrJe9cUJubSiyW3uULSNFnr5wVqJ/1q2p9YDkXDHCQzNCzMyLQ7Tvx5qvC4q14p7IyMR5R9YB6DtnMj5+ri3UKq+phEfoMLuN/b4H/eZ+bsHU6O8Ftry1p1yPb5N/OdAMyNo/oe03z97TLwrc=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792200427; c=relaxed/simple;
bh=zgAncej2VMKtRTstMEpHtZxGPB+wKyq/+2Fwhv76YLA=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=N1PuSg+cTU3uwsGYMhkf8EdTc9S/MqSWQCaDGYor05imc0vwpkpJE0O5ukkE6ZnmfxLN9USW/cuiaGH2hLfTdplx6oxIg7VEdYsybEisaIP7gkaCR9yKD1n9QGN6EQ90e9I1sR54yVbUX28jRiAlXghj+GgGMAWWe9tkzILZP8s=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mJy0ZHQy; arc=none smtp.client-ip=209.85.216.52
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3ac5b090d16so362427a91.0
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 18:27:06 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792200426; x=1792805226; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=2c71ftOjOMZN/elNUQWQLQS3OBsPaj6ABPEs543IIw4=;
b=mJy0ZHQyiUPlmuo4i8/UDH25JlP7UnzsDt8lHJHCa9ewvKeQaj9ywFRsLtAVo51bYt
q0XSvqIcg0h3KUq/N7qmJq8QHQu5+AoSu9X2gQ9mU18FJLd04bvgLzDqoEvbnJ+nX9n/
P4aS7a3hDum12WUylsYunRW6MV2hKzuhg2aWXL/0/aCo379mflIabPGpQuPkP1fRkf3n
QnkJaEMUfor4ICb59K3YTXkwMmXUKNcH2//eTmrZ1Rd23LNwPzJ12L9+zK/5SR2L4Ngi
y6Co7RbvoGqX3Yfwo7OdwFnL21VXPzydjhTvQLvep9GxNPj1b4l833RVDsQTaZsb46lD
Npgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792200426; x=1792805226;
h=content-transfer-encoding:mime-version:references:in-reply-to
: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=2c71ftOjOMZN/elNUQWQLQS3OBsPaj6ABPEs543IIw4=;
b=ab523P9h1i4x6hEzyN/V+oKBJP1GXhQjWJkfm2tSTYk0TBIrqfTczYcwgMQJwurka1
0H0MQfbpDs1g65UgGMO9C17p+EPtfLtDgx6f3aJwuF5QC2Jt2uVAxweX/PTG7Dg759y0
lnqvGvqXybpumwTQV8GeVAVBjpVMUF+V42bFnlUD5W65On6yyWTFxPfBW9Ee9WXEhC4/
BKgNsu7oQcYPnzzVBD83l2pw0Mcd79/wWpwY5W3VcCOeq/LzimH4pn3u61cj1MttIYu8
JNIT90v16Q/jX0Cc0qYjJ2Fw9UgDa4iqY1BtK1hbqhs3TzZ0VpH6WFraf9e7KvFtwcmR
meUQ==
X-Forwarded-Encrypted: i=1; AKwUvByobCffVMinYNmpdREnMohW6tHNsitGzMb9D92BCiQotN0TbZ5E/JeErTYT1nvkELVKzPL4hdw=@vger.kernel.org
X-Gm-Message-State: AFq9FYIVc+qpLzMjJUl4qmcqZcw4SoABDLc9qdDsgVkIFGhTBwvew1bM
A5P3KGVsxOo5mwq0KX/tKdU8YGvww4A3Z2rx3rFK4SnSgy9tp2w1FcQZ
X-Gm-Gg: AYBFou1KhLMKVkCwx74+HWoF//ru5G+25iXNoNwryQWC1ORTThhk0eCqjUbSG/WnfDl
Bp4xfKjNelQKsD4gK5dc93ZN8enYZaEEb1Hdpw+MRhKxRfTtNbMrDkoaWeiQhsxoaUneilPdS3U
lhFFTeaRCvKXwbu0Hz7gf0+D/Q9Mld4QR7XPcX8XFhf/8tqHDrCQCIWvgP0lGoojWkHy+KGIlLR
S4rCwPRkBSIoiYB+KB5CcvmSHdpdfKzf1mLtBHROJbfufaIUSigNLJJGwv9p7Gdmy47vzuF1gZl
c5WXLE2GCXGi9/VpTzggkQ2g+4DdNrCtj6MAqUmxbYawe5vl4Hpx1CbIVPHnds9LMZ9ileOfN9a
UIKJEtEFkBXWAsHmaeDGaf3EMNVUar9g/MHZxVVH+JSISFXFIRy9ypAEYFuYJ0T1Gq6byfZSowJ
NWCKHzGF7q19SQbeLjKWAXZb6l8BP4vtJ7yVe/klPA8zJUiI/ipsI5Zj05IomcsEsH0K2/UOcWa
tTV+4+VgUoK5tgx9MYh/D7IdBqUDrWzGiNbw8eQqWyfMBxPHL3BCyazrqeBHNQUG64xE8z9lvdr
uCoLyTvO2C2znFYiOZhuNNJVnDPjzD2L1j0h8WwkC9Q=
X-Received: by 2002:a17:90b:1d0c:b0:3a0:cca0:4a8c with SMTP id 98e67ed59e1d1-3aceefbd794mr786287a91.7.1792200425825;
Fri, 16 Oct 2026 18:27:05 -0700 (PDT)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.253])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3acc38b457esm6730982a91.0.2026.10.16.18.27.04
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 16 Oct 2026 18:27:05 -0700 (PDT)
X-Cc: daniel@iogearbox.net,
andrii@kernel.org,
eddyz87@gmail.com,
memxor@gmail.com,
netdev@vger.kernel.org,
josef@toxicpanda.com,
mason@kernel.org
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>