Netdev List
 help / color / mirror / Atom feed
From: Liu Chao <liuc63@xiaopeng.com>
To: "David S . Miller" <davem@davemloft.net>,
	David Ahern <dsahern@kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] net: ipv4: ipconfig: fix OOB read in DHCP option parsing
Date: Fri, 16 Oct 2026 12:11:52 +0800	[thread overview]
Message-ID: <20261016041152.2294843-1-liuc63@xiaopeng.com> (raw)

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


             reply	other threads:[~2026-10-16  4:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  4:11 Liu Chao [this message]
2026-10-16  4:14 ` [PATCH] net: ipv4: ipconfig: fix OOB read in DHCP option parsing netdev-bot+sinfo
2026-10-16  8:18 ` Antoine Tenart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261016041152.2294843-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox