🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #3843

[PATCH] net: ipv4: ipconfig: fix OOB read in DHCP option parsing

#3843
From: Liu Chao
Date: Fri, 16 Oct 2026 04:11
71 lines
7610 bytes
The DHCP option parser in ic_bootp_recv() advances the option
pointer by the option length and only checks that the new pointer
has not reached the end of the packet.  The length byte and the
option payload (opt[1], opt[2]) are then read without verifying
that they lie within the buffer, so a malformed reply from a
rogue DHCP server can trigger an out-of-bounds read.

Validate the option length against the remaining bytes before
consuming the option, and skip options that do not fit.  This
keeps the existing parsing logic intact while ensuring all reads
stay within the received packet.

Reviewed-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
 net/ipv4/ipconfig.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 22a788987..0b39a5ccf 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -1081,25 +1081,27 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
 			__be32 server_id = NONE;
 			int mt = 0;
 
-			ext = &b->exten[4];
-			while (ext < end && *ext != 0xff) {
-				u8 *opt = ext++;
-				if (*opt == 0)	/* Padding */
-					continue;
-				ext += *ext + 1;
-				if (ext >= end)
-					break;
-				switch (*opt) {
-				case 53:	/* Message type */
-					if (opt[1])
-						mt = opt[2];
-					break;
-				case 54:	/* Server ID (IP address) */
-					if (opt[1] >= 4)
-						memcpy(&server_id, opt + 2, 4);
-					break;
+				ext = &b->exten[4];
+				while (ext < end && *ext != 0xff) {
+					u8 *opt = ext++;
+					if (*opt == 0)	/* Padding */
+						continue;
+					if (ext >= end)
+						break;
+					ext += *ext + 1;
+					if (ext > end)
+						break;
+					switch (*opt) {
+					case 53:	/* Message type */
+						if (opt[1])
+							mt = opt[2];
+						break;
+					case 54:	/* Server ID (IP address) */
+						if (opt[1] >= 4)
+							memcpy(&server_id, opt + 2, 4);
+						break;
+					}
 				}
-			}
 
 			pr_debug("DHCP: Got message type %d (%s)\n", mt, d->dev->name);
 
-- 
2.50.1
Technical Details
Message-ID: <20261016041152.2294843-1-liuc63@xiaopeng.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-347105-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-347105-linux-kernel-netdev=dewy.ru
From: liuc63@xiaopeng.com (Liu Chao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH] net: ipv4: ipconfig: fix OOB read in DHCP option parsing
Date: Fri, 16 Oct 2026 12:11:52 +0800
Organization: Usenet Network
Message-ID: <20261016041152.2294843-1-liuc63@xiaopeng.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2683247"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:OUStNkwpQWe9EOAtINOX57yci0A= sha256:yFT4gcaNQnYwM87A/ueRn9qn1q4MXI3fGb6maCTikBk=
	sha1:y22b6fWPrYorwQUrSDabDg6uf6o= sha256:txbSM8PsaqN6Za0kW286DGMQ1fbD+PZ06yWcHkI1PI4=
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 36791110460; Fri, 16 Oct 2026 07:14:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.749
X-Spam-Status: No, score=-0.749 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, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=xiaopeng.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 1NQPnaXJDUMg;
	Fri, 16 Oct 2026 07:14:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-347105-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 3904F10D723; Fri, 16 Oct 2026 07:14:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id 7DBAD43CB8; Fri, 16 Oct 2026 04:12:06 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1505739794A;
	Fri, 16 Oct 2026 04:12:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b="aezxHtbP"
X-Received: from out28-123.mail.aliyun.com (out28-123.mail.aliyun.com [115.124.28.123])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE22137F006;
	Fri, 16 Oct 2026 04:12:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.123
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792123925; cv=none; b=tw3f9HFe/Y3xb1hnNun6zTmwsSabI0bGvnzWh7mf32IE1gGSh0COv+Vz6qSmbewa9GHePNxdpAPaFsmWSCNIrOpvoCwu9JUTS26oeO1QYhjymizhNi/bznv+4HcVCUypB6O+x3Xz+bb4CsTkPA1sLgatc4Wfi1itkC9oKrcxSQc=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792123925; c=relaxed/simple;
	bh=SR9U9zFwf4ohXXSs1IFWCy9pAc5l12b6KOZuvX8XW2Y=;
	h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rhgTQ5xpslAN3Ru5FSVfEpGuDjQbajJFBYz2tyAvnhnNhYpbFWyuEYiY3htjgsbOpLEQFRqKmkoAETaNHbfIAQz3U93GIKc7ZfMWO8KDFYb9E3dBqydrL/7cd4Jub2kGfcPU9rRWpbFEz0EatMmP7oOIV+CWQpXymRHxYYTcLRo=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com; spf=pass smtp.mailfrom=xiaopeng.com; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.b=aezxHtbP; arc=none smtp.client-ip=115.124.28.123
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=xiaopeng.com; s=default;
	t=1792123913; h=From:To:Subject:Date:Message-ID:MIME-Version;
	bh=0a5T7wx+TeWcfwy+1qS3o5fCKHYJbaB3LB2/Y2K8J5w=;
	b=aezxHtbPFSIHZVi8nblFpbmPM0EhjW/+A2772anJdRCl0VSphRM1DY66E3s0h0QoPcRvTq9oWcI2Gun9pLIRk7QQNfFQ/XJMpCwri/f5mYrXECGyXTCkI4uYWCqTisjYuvf1YrVJJV7p3G96DF7eqRhM/Wy/3ibgrysIhrzskCs=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.0751425|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.0101323-0.00207211-0.987796;FP=5090283234190380785|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033045213054;MF=liuc63@xiaopeng.com;NM=1;PH=DS;RN=8;RT=8;SR=0;TI=SMTPD_---.jfvLNd-_1792123912;
X-Received: from localhost(mailfrom:liuc63@xiaopeng.com fp:SMTPD_---.jfvLNd-_1792123912 cluster:ay29)
          by smtp.aliyun-inc.com;
          Fri, 16 Oct 2026 12:11:53 +0800
X-Cc: netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.50.1
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>