🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9431

[PATCH net v2] openvswitch: advance by the real header length in get_ipv6_ext_hdrs()

#9431
From: Joas Antonio dos Santos via B4 R...
Date: Mon, 02 Nov 2026 01:45
116 lines
14901 bytes
From: Joas Antonio dos Santos <joasantonio108@gmail.com>

get_ipv6_ext_hdrs() walks the IPv6 extension header chain to fill
key->ipv6.exthdrs, but advances to the next header with ipv6_optlen()
whatever the current header is.  That is only right for Hop-by-Hop,
Destination Options and Routing headers:

 - an Authentication Header is ((hdrlen + 2) << 2) bytes long
   (ipv6_authlen()), so with hdrlen = 4 the walk skips 40 bytes instead
   of 24 and reads the next "header" from the ICV and payload;

 - a Fragment header is always 8 bytes, and the byte read as hdrlen is
   its Reserved field, which the sender controls and receivers ignore,
   so a non-zero value makes the walk skip up to 2048 bytes and miss
   the headers that follow;

 - in a non-first fragment nothing after the Fragment header is a
   header at all, it is the middle of the fragmentable part, yet the
   walk keeps parsing it as an extension header chain.

In all cases the OFPIEH12_* bits stored in key->ipv6.exthdrs depend on
bytes chosen by the sender rather than on the headers that are actually
present: payload bytes that look like another AH or a Hop-by-Hop header
add OFPIEH12_UNREP/OFPIEH12_UNSEQ, and real headers after a Fragment
header can go unreported.  Flows that match on OVS_KEY_ATTR_IPV6_EXTHDRS
then classify such packets wrongly.  There is no memory safety issue,
skb_header_pointer() bounds every read.

Advance by sizeof(struct frag_hdr) for Fragment headers and by
ipv6_authlen() for AH, and stop at the Fragment header if its offset is
non-zero, as ipv6_find_hdr() does.

Fixes: 28a3f0601727 ("net: openvswitch: IPv6: Add IPv6 extension header support")
Link: https://lore.kernel.org/all/178905555085.219967.6617611783437228045@kernel.org/
Cc: stable@vger.kernel.org
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
---
Changes in v2:
- Stop the walk at a non-first fragment, nothing after its Fragment
  header is a header (Ilya).
- Drop the Assisted-by tag (Ilya).

Found while going through the pre-existing issues the Sashiko review of
"openvswitch: fix wrong flag value in get_ipv6_ext_hdrs()" pointed out
(Link above).

Tested by building get_ipv6_ext_hdrs() from net/openvswitch/flow.c
before and after this patch in a userspace harness (skb_header_pointer()
replaced by a bounds-checked memcpy from a buffer) and feeding it
crafted packets:

  AH(hdrlen=4) + DSTOPTS + TCP, payload mimicking AH at old offset
    before: AUTH DEST UNREP UNSEQ      after: AUTH DEST UNSEQ
  FRAG(first, Reserved=0xff) + DSTOPTS + ROUTING + TCP
    before: DEST FRAG UNSEQ            after: DEST FRAG ROUTER UNSEQ
  FRAG(offset=1000), payload bytes looking like HOP + DSTOPTS
    before: DEST FRAG UNSEQ            after: FRAG
  ROUTING + FRAG(offset=16), payload bytes looking like AH
    before: AUTH FRAG ROUTER UNREP UNSEQ   after: FRAG ROUTER
  FRAG(first) + ROUTING + TCP, HOP + DST + ROUTING + TCP
    unchanged

net/openvswitch/ builds cleanly with W=1.  I did not test it on a live
datapath.

The analysis and testing were done with help from an LLM-based
assistant; I reviewed the change and ran the tests myself.

v1: https://lore.kernel.org/all/179328922134.76862.10417963652853801970@gmail.com/
---
 net/openvswitch/flow.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 1c4f3a079..3734416b5 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -369,11 +369,28 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh,
 			return;
 		}
 
+		if (next_type == IPPROTO_FRAGMENT) {
+			struct frag_hdr _fh, *fh;
+
+			fh = skb_header_pointer(skb, start, sizeof(_fh), &_fh);
+			if (!fh)
+				break;
+			/* Only the first fragment has the headers that follow. */
+			if (fh->frag_off & htons(IP6_OFFSET))
+				break;
+			start += sizeof(_fh);
+			next_type = fh->nexthdr;
+			continue;
+		}
+
 		hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
 		if (!hp)
 			break;
+		if (next_type == IPPROTO_AH)
+			start += ipv6_authlen(hp);
+		else
+			start += ipv6_optlen(hp);
 		next_type = hp->nexthdr;
-		start += ipv6_optlen(hp);
 	}
 }
 

---
base-commit: 94cea342e8915812b45f93c56e134041c7fdb4d7
change-id: 20261102-ovs-exthdrs-c101f8d5b62c

Best regards,
-- 
Joas Antonio dos Santos <joasantonio108@gmail.com>
Technical Details
Message-ID: <20261102-ovs-exthdrs-v2-1-21ceef6a243d@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-354421-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-354421-linux-kernel-netdev=dewy.ru
From: devnull+joasantonio108.gmail.com@kernel.org (Joas Antonio dos Santos via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] openvswitch: advance by the real header length in
 get_ipv6_ext_hdrs()
Date: Mon, 02 Nov 2026 01:45:35 +0000
Organization: Usenet Network
Message-ID: <20261102-ovs-exthdrs-v2-1-21ceef6a243d@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2822132"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Gc28DawzQGCNEiz8vMlfB0GNDhw= sha256:xe+6QxU6Bk+W8jQQwYoXZvQ+yE+qRdcB6uwYfe8ffHo=
	sha1:KeYtt3VgSLW+pkbEagvHhPc71sI= sha256:X4hAReEoIaM1DdgMUpNsBaKjZKNNINUvZ4ZCtSXCWJ4=
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 BBB1A1123F5; Mon,  2 Nov 2026 04:45:58 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	FREEMAIL_REPLYTO_END_DIGIT=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=kernel.org
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 Npes_jqAd5BB;
	Mon,  2 Nov 2026 04:45:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354421-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 013C5111BF2; Mon,  2 Nov 2026 04:45:45 +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 965932CA23; Mon,  2 Nov 2026 01:45:38 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793583938;
	b=JFvCw/55W3nhZs9lUwLGcFMq1+mk4VgZ8tur+8dD1+J5s3T2HBWQcfXpIneNLGVYdUU9
	 rOEc4M6EMEsa6t0G9O/3fj+YhwEZlLJCwnRkonNPLX4tirEhCrGK0iRU0ZNIkql/oT9cH
	 4PZMR9GPeQmqY66aCpCadMONAgVWYNgRkaIz590iMa729aXl/i5pMkP0kYmCX2m98AIpA
	 xTaF7x1yWObDY6mV9RBipY5G7TjFBP8eXuEqH9XYteU/fi53ypnLGFI49Com8+adIQiXF
	 MDOYRfDpHLaiSNt3+MRBkuKDUreeuPi4qpFDRNsF1r2R9MnmGUpsFALdKYNLX5brjxQ==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793583938;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Message-Id:X-B4-Tracking:To:Cc:X-Mailer:X-Developer-Signature:
	 X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To:
	 Content-Transfer-Encoding;
	bh=Eeswh71nQ4eodvDnqz28Zx2VhRFam1DEmTWBcVLFmgE=;
	b=lhUDovZtlBJRrY5/1il8SjYRuqQCDXtRhXyUV7NgqkkW7CqswcEKbGMLVMHEB4qQMdrI
	 25FBcokG6lypaZFMc+FmG9M4/4Y1nkD+423T0kpE65lx7HYy8sinrB0GLDK9k1zrPawdu
	 bQro8jCS1gTWJnTIQDEGAimYitdYnpRCaMa5LCBJsApwp1/jZhOsfwaHPdSPqvCscVlxu
	 lns5Jo8e0BtdR1PurrOq4CPSYTlzc7Kdq73ru2F05q3FQx9Gf/gWsOsajJygcYeTojSqb
	 TeIULQ1URKu7k8CjoXBf43oenmRcW0ZyaP3uOjc7nDwkrt/3fVIqwhUHVg7BLI7ROQg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a2C6I0nJ;
	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 6B248606A330;
	Mon,  2 Nov 2026 01:45:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a2C6I0nJ
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793583937;
	b=tvgXFD8lH6yeqlVDoGObuZLXI55b1Jxp7upYeOwLsl3zc5sHffue0XV/ZYUtgXTTDbgU
	 /Uay7R08QhrnBwbvDmXct+2675ItrgScLDUc+0zbZJPdK+zcwEGQ5PRbLqG26DqbHfMgW
	 FFapDzgqoAebC4BhgDOGanWS6FsBtDPfvPX2YxQ4uI6nEoAdLsEv52ETvfKtqtf28XdB8
	 0GYOMuVbdGkTQ8jqolaDF+n2953Ki13et/aoNiNIbwxvDGm1IbDUtqCHTXL9RJnFgsvwf
	 ZVs7Eu9mn8X/pgWQOxK0iBfgdrugNMZW3+VswjHvpLvbanEnHSUTg+nrp20/7vdohcQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793583937;
	h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version:
	 Content-Type:Message-Id:X-B4-Tracking:To:Cc:X-Mailer:
	 X-Developer-Signature:X-Developer-Key:X-Endpoint-Received:
	 X-Original-From:Reply-To:Content-Transfer-Encoding;
	bh=Eeswh71nQ4eodvDnqz28Zx2VhRFam1DEmTWBcVLFmgE=;
	b=ZkGAXMyNQ1E4ZLRNIhsZtfOXm9NT8hN7yQ0kmYcCb6huqnrCDaEl482Js0DCMLGkqvDl
	 xz+88eblrv760/6dZK4+sxOmQ8L+78Jwn7ey20IOR7G0EblhbvV2c6VTzggPHOP5m80pw
	 dw56iolvkx5SoNsjeXW1U66HoU4nfA3vCqOUPBHBOiBF7loT0KKnZW5QT9KU1Fa+gs4S5
	 HrJh2TltHEkSnwMboFKItSiWyrYujO/1Qq20Oh5ELYNb2lc5ZxpVo+PvaMig1QUKpKGj9
	 uEpdawDwuKexLJp+Gv29rZdgtDAHmdQcFNK97XSXwNAHDdiBTscJUoPKjo1O5K8hRbg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a2C6I0nJ;
	arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BD22606A324;
	Mon,  2 Nov 2026 01:45:36 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none;
	t=1793583936;
	b=Y2WQBc7XCWNj72+1J0hrDEKkS+xv5xWz2AuCl1HGE96onZfcL0g5j2F4eZB+jp0wnEnK
	 qS7sXM+cin/C2RyBzlbyXdOJSmt6wkTxxq8gH+MFQ0LA642lpZvSCrFcbqhqalOjm6+f6
	 OznYMUk1ZAkEYbxCqGsaatt93HjbTLt1Dt/zZpR26drPJlnOhPtCo7b6ZiKWU690Akr7i
	 ip1H1e89Tr8n6MwlZjl1ux2r731dtu2yCOMxW3flG6QglL7kVLnXb9X+stsiprJFUpQW0
	 mWo7hIDo7IkFWv+qg5DM9iSgKWQ18S09y9xnS5Hc/z/fkMKXNOWR2RoDWj8Y6BQ1UtQ==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256;
	c=relaxed/relaxed; t=1793583936;
	h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type:
	 Message-Id:X-B4-Tracking:To:Cc:X-Mailer:X-Developer-Signature:
	 X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To:
	 Content-Transfer-Encoding;
	bh=Eeswh71nQ4eodvDnqz28Zx2VhRFam1DEmTWBcVLFmgE=;
	b=npieCHKqPPRmhbwXj02u77QK8pKhS1AKr0E0Ek/o0H/OdrKkh5VHOEnXVGTmbQHCOUMS
	 4nhq6OM2GDwB1yBeLlFNeVVNItM6zH1gPz13YGt3/NxE96oV+VMgDRpdaA6RF95PFMXgh
	 9igy6Y/6anNKpnA/s14+yHvDWGvhn39lEswjkWZmoefJdfiePvgl/pXXkA9fhA+uZZmjI
	 rRbVe1zaTjSoqBy10Or2XoTtyClCYZ10+6CkQjco/T4otZp0xEsqBPal3ULMhiUsI3JBk
	 Ysz/uU9vR/2DmqtFBmZUgdPPmJPdnX4QxDSMa9N9y71AZfiiAmU80pccFfcUDRtEklQ==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; 
	arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.kernel.org (Postfix) with ESMTPS id B6E9F1F000C1;
	Mon,  2 Nov 2026 01:45:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793583936;
	bh=Eeswh71nQ4eodvDnqz28Zx2VhRFam1DEmTWBcVLFmgE=;
	h=From:Date:Subject:To:Cc:Reply-To;
	b=a2C6I0nJElHZfJN2J3Jv9VEc40zyffVSAj9ZIz+3t3zxdoSTHdvUSs5vAvpKjbPBz
	 iw2bSc4vaan2GS1d4vxqrvCqapNtfrDVqAN+ibxQaF/wHeTlDMJrXxgu7jJ+OXkVb/
	 HEjQMGDslzIIbSyUgpPxq4C4bkE/JxOGRDOgiGYXRG5eZdMXFFOKrwuelR3c8Pg7Qe
	 88ZwVFoDmPA8XE6IMI39C921jTegv31Pb87zqR5OseY5nEZvEvVVF7IMy3HXE2p1KQ
	 UCQESVyypNt0orDSDoX5OZ1HwmxmR/kNBT+4tzqYFQe0v3LGUEYeQnJzawm4wYbGWj
	 accUjoZtVArFQ==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1])
	by lkml.kernel.org (Postfix) with ESMTP id 3508346302;
	Mon,  2 Nov 2026 01:45:35 +0000 (UTC)
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
X-B4-Tracking: v=1; b=H4sIAD7r52oC/x3MQQqAIBBA0avIrBN0IImuEi1Kx5yNhRMShHdPW
 r7F/y8IFSaBWb1QqLLwmTtwUODTlg/SHLoBDTprDeqziqbnTqGI9tbYOIVxd+ihF1ehyM9/WyD
 TDWtrHwUwQcRiAAAA
X-Cc: netdev@vger.kernel.org, dev@openvswitch.org, 
 linux-kernel@vger.kernel.org, stable@vger.kernel.org, 
 Joas Antonio dos Santos <joasantonio108@gmail.com>
X-Mailer: b4 0.13.0
X-Developer-Signature: v=1; a=ed25519-sha256; t=1793583934; l=4412;
 i=joasantonio108@gmail.com; s=20261031; h=from:subject:message-id;
 bh=hupOxG9gfTdg83Q56zynhHUJuMArSkJdz7lPZA5eIFw=;
 b=sjAGEwAfDl/oGKwvKIn9mFWS2sHBz4fC5dT+I4IDVYbp1Yt2G4YHThpjVkGolAxISJOHufuvn
 duFFwC6ZeezCQGyhQBOMBK4RxBdWNgdJeREkS4zgx7jrsuR3p59Jf+M
X-Developer-Key: i=joasantonio108@gmail.com; a=ed25519;
 pk=ZxAznJT/FcPPdzLrDDFJQm4LLjjHVGBBqDSG3TXS23w=
X-Endpoint-Received: by B4 Relay for joasantonio108@gmail.com/20261031 with
 auth_id=1371
X-Original-From: Joas Antonio dos Santos <joasantonio108@gmail.com>
X-Reply-To: joasantonio108@gmail.com