🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11512

[PATCH] bpf: fix verifier model mismatch on __sk_buff.remote_port narrow read

#11512
From: Henry Martin
Date: Thu, 05 Nov 2026 06:03
57 lines
12886 bytes
On little endian, the ctx access conversion for __sk_buff.remote_port
loads the 16-bit skc_dport and shifts it left by 16, producing a
4-byte value of up to 0xffff0000.  It reports its width through
bpf_target_off() as 2, the member size.

A 2-byte read is a narrower load of this 4-byte ctx field, but the
fixup pass only masks the result when the access size is smaller
than the reported width, so the masking is skipped.  The verifier
models the register as [0, 0xffff] while the runtime value is
[0, 0xffff0000].  Arithmetic the verifier folds to a constant can
therefore take any 16-bit port value at runtime, enabling
out-of-bounds reads and writes relative to map values.

Report the real produced width (4) so the fixup pass applies the
usual RSH/AND masking to narrow reads.  Full 4-byte reads are
unaffected.

This issue was discovered by Tencent CodeBuddy Security.

Reported-by: zeroday zhao <zerodayzhao@tencent.com>
Fixes: 8a31db5615667 ("bpf: add access to sock fields and pkt data from sk_skb programs")
Cc: stable@vger.kernel.org
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 net/core/filter.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 9245009d9f1eb..6eb4751441f39 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -10455,13 +10455,19 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
 	case offsetof(struct __sk_buff, remote_port):
 		BUILD_BUG_ON(sizeof_field(struct sock_common, skc_dport) != 2);
 
+		/*
+		 * The converted value is 4 bytes wide, not 2: on little
+		 * endian the 16-bit port is shifted into the high half.
+		 * Don't use bpf_target_off() here, it would report the
+		 * member size and the narrow-load masking in the fixup
+		 * pass would be skipped.
+		 */
+		*target_size = 4;
 		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, sk),
 				      si->dst_reg, si->src_reg,
 				      offsetof(struct sk_buff, sk));
 		*insn++ = BPF_LDX_MEM(BPF_H, si->dst_reg, si->dst_reg,
-				      bpf_target_off(struct sock_common,
-						     skc_dport,
-						     2, target_size));
+				      offsetof(struct sock_common, skc_dport));
 #ifndef __BIG_ENDIAN_BITFIELD
 		*insn++ = BPF_ALU32_IMM(BPF_LSH, si->dst_reg, 16);
 #endif
-- 
2.43.7
Technical Details
Message-ID: <20261105060331.1912252-1-bsdhenrymartin@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-357083-linux-kernel-netdev=dewy.ru

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-357083-linux-kernel-netdev=dewy.ru
From: bsdhenrymartin@gmail.com (Henry Martin)
Newsgroups: linux.kernel.netdev
Subject: [PATCH] bpf: fix verifier model mismatch on __sk_buff.remote_port narrow read
Date: Thu,  5 Nov 2026 14:03:31 +0800
Organization: Usenet Network
Message-ID: <20261105060331.1912252-1-bsdhenrymartin@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3571879"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:v3ldn/I7q1ERaK9KQwmYugTocVo= sha256:YHuvxPnBIGjHwI3ONbGB2rU0YBv1qbgTXW7rvwtltF0=
	sha1:qaHG84qFxDcxjhWAdX2VjE8QOKk= sha256:axv5S3j3A9AZdX2GyW0UNu1+b9FzD+uxGqA6zXGyvS4=
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 DB540112E98; Thu,  5 Nov 2026 09:04:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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.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=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 yUat7XnqgKr9;
	Thu,  5 Nov 2026 09:04:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-357083-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 2E1E5112E65; Thu,  5 Nov 2026 09:04:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id C81FD26A89; Thu,  5 Nov 2026 06:03:57 +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=1793858636;
	b=cUaexSKGs1mEfyS9k5TB8Ju1DvaA9uOjS9EMam44SqwFG7VD2QGNS2/a8hE0ZDnfWzxE
	 q5K3aB4Q9Y70S+b9EfFNUi9lPMUHty/2f/qUxu/rehSQBn64+WNhjGaHhle7AQB6bl6zl
	 zE93kvX6MTm7YBoGVWT8Sq60BfqTs9dl7nCle89aAx21hjr5Maq6eohjayux5BGtTwOq+
	 eNelmXIigZZ1KyNSnhh9+QLIlv2DUN9iwvJAeQT+jFrRbqG7PdIfqGwFL3FdU0NrPQKlX
	 yWSOqc6Lkop7AUdBa3Pomx0+N2I6XrhJx4hD1fOR9WZ9u7iVrZCNRuHnL0TBHYKDYKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793858636;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=fl+RqVSy++c8t4D9ZLDA6qx49eqFU8GFdwgJMfJOyN4=;
	b=u0x7gpCyEEZFqNe3/BYNj8JFeG+mtShc4dYRE0wMMFfH90+IWqnVh2+sHKMBP02HBx/W
	 n/o12TL9XZxlLsUOdNHki0Yydqn4TLYv8U2gYpdGiLtJXHaCovVOAvchN7wRkO6gpqu/4
	 LV6SKgeHOqi3e/hipN/RLXS26IlMhHHpSdRHfjVI2zXSJVmiEMu2sqGHqVsTnwhtTr+bY
	 +x1m7wmNg6+/0GNx4z61ng8l4yI9KwcLK/jFRSbTzypkgS1niI6Whz780yiPFQhP8Dx12
	 78kCPHWHOk7yISMA35SpyQP1VhkyWhGmDLQWeteOf93VqlIeRqi/NVacFVG5j1vMXvA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sITsORkr;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 D78FD606A326;
	Thu,  5 Nov 2026 06:03:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sITsORkr
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.231.202
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793858636;
	b=NjXB3S22O1yxxjaV50Y1Wmihn0IGd2hjHsT+UeD9MewJ2SeO+HQrx90cxQvz90ciXvK5
	 EXfA9tUYAqbs/DdwMWWyU7ib1895r830loZG6wdEF3M4vlgX0NpbCM+SqHEDKM2OG5X9y
	 Y0P/XjyGJVaDug+ZCc8ubR8aYc94j0Dztt19ueEu/kKGWTNZsGzcvzqpk/9zqGbnDAmsU
	 S965zH8BdV/C5QYHCpbyE9ezJyiEcqK44xIzhYEZGaGlswkHmC9W3N6FWiruickZDVSSt
	 5LkAaoj95tAsDIQInlHzzk3e2AvvZUMrBK508fhzsnIhrX3L3Im283k44kRwWyHXsgQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793858636;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=fl+RqVSy++c8t4D9ZLDA6qx49eqFU8GFdwgJMfJOyN4=;
	b=h601LzMh89JaN4HA4UtZ1kFydMjB4mB7CvtGEwA98gEjflWjoCG69mJ/OB1JHcBGpxA7
	 JiiK/2KGgW1oJbA+E9BKJdJu1ZAdBaoQMgQVhpZgfRVzNy9lG/X+oRuf9279iJcY5o77+
	 tV2j/gIlzkPBHHee68keVSkjDOj2/Kkk7G4vvPwuC/WwznM3UoA2qrR9JcDoPdL0EnP2O
	 r+Ghp5nZYHlq7HF/ys+FjWO3YA9+uhTZFzbSzup/6Hd4RdBluIVzXlGSTAZkjx5iCti5B
	 ct+VUCswPnZvNf9oNQqD8QNfAgniK/7/SGY6ZV4gBhIziQfWOFj/nGWta+4yZKeFqEg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sITsORkr;
	arc=none smtp.remote-ip=74.125.231.202
X-Received: from mail-oi2-f10.google.com (mail-oi2-f10.google.com [74.125.231.202])
	(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 A5A0F606A329
	for <netdev@vger.kernel.org>; Thu,  5 Nov 2026 06:03:55 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5A0F606A329
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-oi2-f10.google.com with SMTP id 5614622812f47-4c3bb46aaf0so715120b6e.1
        for <netdev@vger.kernel.org>; Wed, 04 Nov 2026 22:03:55 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793858634; x=1794463434; 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=fl+RqVSy++c8t4D9ZLDA6qx49eqFU8GFdwgJMfJOyN4=;
        b=sITsORkr/kUi1tLLm2LhV4O4MeBBZD5P42Mn7DMsbqXc1l0My7lI4VmgtVtnfCNRPm
         F2K5ABd1e0VHSJ8v2yESdYDjTq4i63tkKEsmDkfU94JGf8/kaTIlpLIWCue9vT5bF1Nu
         nuFchHwAR7Ftsz3TEZCXr+WCGl9OD/waFlfO7CL1Jilo/txk7zlc2begOhUWVb0h/j/R
         TGbTC/6DEKgD1gf7luCdWPsrmDKhVsiH4PA2kU5S6CZ068gtUu1ny0pcnBfzdI1R8zjJ
         BNwajppvpcVWWXsA70Yz5DddZP4BTQKmTeGOmnqBOD5ep97jZ1ZC4JL9FAWfb5NB8wJq
         qSnQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793858634; x=1794463434;
        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=fl+RqVSy++c8t4D9ZLDA6qx49eqFU8GFdwgJMfJOyN4=;
        b=QkB29VwvvB9/0H1jmEKZYkVNjShCoAZogb8Qh2/Vcc00oIZ12apFk+dzb1vQ+ACsVu
         txQncVYt1m9b13JU0Wm0RaQb6CqHy3BLZUkyLk17KyIK5H2S7WuFIja0nJ81CL561Tq7
         hIcT5+LNjpNCOLpn6t7b+TQkPRY8GFxgKhO4ShSqJZGy6NQvr8AtkTqVsFb33k5XPyqS
         B/wVH+w3JGaNi4g6c99YscnNIqi229ivPUI3GjjHPQ6zorQI3qSYcC8orr0+FIbcyOYl
         KrSYSq1KJOBEshoj/76kNHa5qAdbItj6qCXW5baGlk5yvzXVQT+82dpIDKXmg0LqAjGo
         UM1Q==
X-Forwarded-Encrypted: i=1; AKwUvBzt497w+jaqV28ElpRW9mmTnLYvfyRx2v6zItLQfCEa55ro5yLtFHLGA3nZRxoIoonfyAjb3WI=@vger.kernel.org
X-Gm-Message-State: APuU4Z97JxnqTwtK8ACGG9i/bkw4hZf1VhmWu6lgNaueUAlYw5QU744K
	dG1xV71qBjXS5s3fqrShOLkbPRt7XeVA5+85NhoLa5CQ1a20ZYI0J0Ro
X-Gm-Gg: AYBFou1mbptqe0AhvzyXLgVkxXaZAc3nx0AaNgurgGhKkMTZVyH9lBqiu8VUDevtp23
	kBUmqHJ8Tp+AAB4RW/VwvU0MrC/EcCz0LSOOIZKWc43CrAQ7+nw6TaPwJL67vFmXrfchK4Gw5ng
	42V4mGBN1+V5QCwNr90fkrQr+nohgfX43+dQuCizdskqGj5AxsSOdUXcT1R9X0Fqfl8FIj90PoZ
	yfhKpcaLonk3TjuvdJY1qEP0etkUSwpBnOEA3kQ04Fzc/lmhlNhGmA1ApxtNpfYt0upFHWqG6sE
	uw0YWy853X8/5lGUI1ZDTjX+dtujg8G8ZDDCCQu7VwcRovXThC13Q8vcvgnKyxsVwETwk6axwTx
	9g3MQVgCBMDoiPpCa2S7SCTYyMm0Q3IBINpv7wOYw3VhLl6paD1mO3xcN9zfHpUrsYzf6oGR7rx
	X0thy6Fy6i/+If8LilPUSFh/oNRbXNlCwRU6ZuLgwJV24e80nY6DIbbTw6ANXKPJSxIZSM4yrb7
	cKI6kCn8qrRNCVtDSPF8MxVjjfo9RIZQnBXhKQfTmC4TMgFls58k5kO8mYiTzqKzMYvpehA0los
	eynZ4T5BntMoe48jNhwKf4uW34Da86tXGXlp04kv6IsLvOwtBp3mnCsXUiu4C8esTZQ=
X-Received: by 2002:a05:6808:14d2:b0:532:963f:3118 with SMTP id 5614622812f47-5640d97353cmr12997705b6e.3.1793858634408;
        Wed, 04 Nov 2026 22:03:54 -0800 (PST)
X-Received: from localhost.localdomain ([14.22.11.161])
        by smtp.gmail.com with ESMTPSA id 5614622812f47-567a9f41424sm3493476b6e.9.2026.11.04.22.03.50
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 04 Nov 2026 22:03:53 -0800 (PST)
X-Cc: bpf@vger.kernel.org,
	netdev@vger.kernel.org,
	stable@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>
X-Mailer: git-send-email 2.43.7
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