Article View: linux.kernel.netdev
Article #18854[PATCH iproute2-next 1/5] lib/bpf: parse /proc/mounts with getmntent and check fs magic
From: Stephen Hemminger
Date: Thu, 19 Nov 2026 00:15
Date: Thu, 19 Nov 2026 00:15
101 lines
13689 bytes
13689 bytes
bpf_find_mntpt() parsed /proc/mounts with fscanf("%s"). The kernel
does not escape \r, \v or \f in mount paths, so a mount path
containing them can be misparsed as a bpf mount at some other path.
That path was used without the statfs() check done for the well
known mount points, and tc/ip then created the tc/globals hierarchy
and symlinks there.
The scan is done whenever /sys/fs/bpf is not bpffs, which is always
the case under ip -n, tc -n and ip netns exec.
Also, the %4096s conversion into a PATH_MAX buffer could write the
terminating NUL one byte past the end.
Use getmntent() and apply the statfs() magic check to every
candidate. Reject paths that are too long rather than truncate them.
Fixes: 32e93fb7f66d ("{f,m}_bpf: allow for sharing maps")
Reported-by: Anthropic OSS scanner (ANT-2026-SJ93QIGZ)
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/bpf_legacy.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 9d5fcf5f..5b8ac47d 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -32,6 +32,7 @@
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/resource.h>
+#include <mntent.h>
#include <arpa/inet.h>
@@ -543,12 +544,13 @@ static const char *bpf_find_mntpt_single(unsigned long magic, char *mnt,
int ret;
ret = bpf_valid_mntpt(mntpt, magic);
- if (!ret) {
- strlcpy(mnt, mntpt, len);
- return mnt;
- }
+ if (ret)
+ return NULL;
- return NULL;
+ if (strlcpy(mnt, mntpt, len) >= (size_t)len)
+ return NULL;
+
+ return mnt;
}
static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
@@ -556,7 +558,8 @@ static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
const char * const *known_mnts)
{
const char * const *ptr;
- char type[100];
+ const char *found = NULL;
+ struct mntent *ent;
FILE *fp;
if (known_mnts) {
@@ -568,24 +571,21 @@ static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
}
}
- if (len != PATH_MAX)
- return NULL;
-
- fp = fopen("/proc/mounts", "r");
+ fp = setmntent("/proc/mounts", "r");
if (fp == NULL)
return NULL;
- while (fscanf(fp, "%*s %" textify(PATH_MAX) "s %99s %*s %*d %*d\n",
- mnt, type) == 2) {
- if (strcmp(type, fstype) == 0)
+ while ((ent = getmntent(fp)) != NULL) {
+ if (strcmp(ent->mnt_type, fstype) != 0)
+ continue;
+
+ found = bpf_find_mntpt_single(magic, mnt, len, ent->mnt_dir);
+ if (found)
break;
}
- fclose(fp);
- if (strcmp(type, fstype) != 0)
- return NULL;
-
- return mnt;
+ endmntent(fp);
+ return found;
}
int bpf_trace_pipe(void)
--
2.53.0
Technical Details
Message-ID:
<20261119001539.2868072-2-stephen@networkplumber.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366566-linux-kernel-netdev=dewy.ruReferences:
<20261119001539.2868072-1-stephen@networkplumber.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366566-linux-kernel-netdev=dewy.ru
From: stephen@networkplumber.org (Stephen Hemminger)
Newsgroups: linux.kernel.netdev
Subject: [PATCH iproute2-next 1/5] lib/bpf: parse /proc/mounts with getmntent and check fs magic
Date: Wed, 18 Nov 2026 16:15:05 -0800
Organization: Usenet Network
Message-ID: <20261119001539.2868072-2-stephen@networkplumber.org>
References: <20261119001539.2868072-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2738868"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/w/2rluW8w8BX4RE29Vcb7u7xxU= sha256:eL3yZfeLRgmGHR5TgJEGOFkGhcBmrk5i2aHZtjlowzc=
sha1:K2OYnj8CZckq8CnKKewg42HYBtE= sha256:TgIaevSqYMqTjun8GooAWinYUpssMeMDSQIP29TF+dg=
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 5C21811544F; Thu, 19 Nov 2026 03:16:07 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=networkplumber-org.20260707.gappssmtp.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 AxfbpSlb6sVx;
Thu, 19 Nov 2026 03:16:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366566-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=quarantine dis=none) header.from=networkplumber.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id CEC3011544E; Thu, 19 Nov 2026 03:15:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 0D943229B29; Thu, 19 Nov 2026 00:15:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795047345;
b=C0bIiVVlt42mCIHapMiWct9gCfAz8SDg2Qvl/6btMXQ57Cf6IJ+bX6zQkRSTYR91xo/m
v2gQKAEto68JHxKJI/KY8FHmsGzNEYn9AiLaZw8JE3+zC+rxtmdJogU4HKlQDxeNMCNs6
CtSS3kicA4THLldbTwb1rLfxJxohWn1J8XfPLl0j/UthjvO9pOCfDBZNa1Tpc6LgJrlsx
Nln5nK90v6ipW2A5Qx9RJ2rH1JLo9XC/zFzYlVUWUtofobefSe7K5Hvid4iz0x3shNUwb
2iKjfay0hrYb00Hulu4mUneGx1O8el8Z+xJzW8cjNa0WImON0yC9KNQw7vntP6RBEzA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795047345;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=2VHt6DRJXo286lDMz7Vj0ZDEKtUATaLidk8Vb4Ed+zU=;
b=3gHOv83Vocxd1Y0EdXu+1i6fJeJdDTIIzqPSFG08xRNjv170P9c/hy+oO0VM8jTmCxPA
oQqS7NDOUILxIwI6sFdc463X7z7FDqCFKSdjSZSdP1SvtI9pSDi3xiwfrcKDvI5EOEMXP
mFnoRjGKDDzymnJ3LYEIb3xMvtF0lKN+vXtbLOlUWDYYF9mqf3EJze2AuRWOIFTFrCyGm
fs0hOBeVlFGfN8zuvXi43Ocql5999q7TqABLnt4cGyR+65Brw1feBQptIsmmwsY68jGT/
AbGG7B6lPLekGU9jKiHHV+XV9orMVrEnmx5yhEYiwHAW5AfEMtMvNZfrzaoteVs/wPA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=hJKBO5ex;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.org;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id A5DF1606A334;
Thu, 19 Nov 2026 00:15:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=hJKBO5ex
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.52
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795047344;
b=SpjcqsslBRvPvnBjDNGXVAAJhDu9RQ9JtLZEXRPbA9VjdHckySIZoDh3biADJyozSFbh
HhLB7NlwoH1LTDyq36DMtLBRcfqZzx0EGAotQ5ep9p73XBtMaMKRxEdiwLJnCGlfAxhf7
MlxICCre0EH79bXXVrIhve8Dvw8Mwr4rb0EcOfw4Lnrv+ca0QC0+PByfOcwDZots+jVVD
7uSuC6OXI0mViHfOTpEQNAe3swJESTOckTk6ULDNw6wQugWzCtzY1JFKQLB3agu5ORjyC
TQkHBh5bCm4FG3HvNSZSAQqydStL+SaTOTuI5IoPG323xZuQiwrnFNSH4n7vP5MKUjA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795047344;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=2VHt6DRJXo286lDMz7Vj0ZDEKtUATaLidk8Vb4Ed+zU=;
b=a1EYetjrULn3ODUV6oqcFe+/tqhB+pn5xw31Qhrn3NNtPYokrxJvdoOvIkt01YgAzrov
JbS4hAc0MCOSZMMZ30ZoElUNyhjD2+5G+fLCbwVeoFznpc8COsecfZfU6euwRtVlk9WBR
jzeo6y4ZjDRsgzMb2Q2Z5+R02hAskRyuJZd4vt+iKdSNvcRjJhugByL3l5BzGf6XlJPF8
0uwdfmnfiHYd0yXFn0BDdgmUl4icMCcx8vrIAuPxfkKvil9+b2oPoLJAcuCZ53PoR7fWm
GIq3eVNkflS930USq+7X9ih51wuw+7FlTEQkB0snzG+klJZE2zjPk0UD1WsG9NBvHLw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=networkplumber.org;
spf=pass smtp.mailfrom=networkplumber.org;
dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=hJKBO5ex;
arc=none smtp.remote-ip=209.85.216.52
X-Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52])
(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 78754606A32C
for <netdev@vger.kernel.org>; Thu, 19 Nov 2026 00:15:44 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 78754606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org
X-Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3b37951a397so1365956a91.0
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 16:15:44 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1795047344; x=1795652144; 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=2VHt6DRJXo286lDMz7Vj0ZDEKtUATaLidk8Vb4Ed+zU=;
b=hJKBO5exFiHj88Tk/7ZSj1bcMAZkNxtbBVrMAgq97GSACwdyjCO0vA1f54USyY/Bej
j7gI62b6vuVOkUgLf0E9NVoXPjMQ2CWBbIxBduYpBmktrK37zjVvGigwP8nzxf4rDxyd
GUR9HsjBvJzsSKYYvWzCFPoUIf0ufQZ4J21+V78abzaiy0n7j0cY0r5EeSmTDr18Yq/k
wrSsPkQa/2kkuuCMivB9ATCgKP2lZf+k+ORQbzf2moy6faueocN9nUaWuEJ+g4USeHm5
6pKQwwKPhXpjQBCzhsR1jLXBgHE4C0zB2mSLmKUV1rXGTvTrsK4wvALN59EVmB1xC62B
grJg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795047344; x=1795652144;
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=2VHt6DRJXo286lDMz7Vj0ZDEKtUATaLidk8Vb4Ed+zU=;
b=Ly+8rEAJtxOzpYyMmRCFwUKsumXE4bSWoJgnpL4r0vuczw2v/wdXE0coLamKxUFNpn
Cbe/nDMypWD8YJ0VXpAifnlwdm1R7fxFFbE0GCMhS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Vvb+3trAwh6+IVr
X-Received: by 2002:a17:90b:4410:b0:3b1:12ba:867e with SMTP id 98e67ed59e1d1-3b3d07a26dcmr4572633a91.13.1795047343829;
Wed, 18 Nov 2026 16:15:43 -0800 (PST)
X-Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b3fe0b62e7sm444278a91.11.2026.11.18.16.15.43
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 18 Nov 2026 16:15:43 -0800 (PST)
X-Cc: dsahern@kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
Daniel Borkmann <daniel@iogearbox.net>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261119001539.2868072-1-stephen@networkplumber.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list