From: Pranav Rajendran <pranavkasthuri@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>,
Jerome Forissier <jerome.forissier@arm.com>,
Pranav Rajendran <pranavkasthuri@gmail.com>
Subject: [PATCH v2 1/2] net: bootp: validate DHCP option length before parsing it
Date: Thu, 20 Aug 2026 13:33:14 +0100 [thread overview]
Message-ID: <20260820123315.9272-2-pranavkasthuri@gmail.com> (raw)
In-Reply-To: <20260820123315.9272-1-pranavkasthuri@gmail.com>
dhcp_process_options() reads the option length byte and dereferences
the option payload without checking either is inside [popt, end):
while (popt < end && *popt != 0xff) {
oplen = *(popt + 1);
switch (*popt) {
case 0:
oplen = -1; /* Pad omits len byte */
break;
case 1:
net_copy_ip(&net_netmask, (popt + 2));
...
The loop guard only proves *popt is readable. If a packet ends right
after an option code byte, popt + 1 is already one past the received
data, so oplen = *(popt + 1) reads out of bounds. The pad case (0)
hits this unconditionally, since oplen is read before the switch
even determines the option is a pad.
Once oplen is read, nothing checks that popt + 2 + oplen - the option
header plus its declared payload - is still within end before the
switch dereferences popt + 2 onward (net_copy_ip, memcpy, strlcpy,
the option-52 overload byte, and the PXE config file allocation all
do this). A short final option with an oplen that overruns the buffer
is processed as if the payload were present, so out-of-bounds bytes
are copied into net_netmask, net_root_path, dhcp_option_overload, and
similar globals that go on to influence boot behaviour.
Handle the pad option before touching a second byte, require a length
byte to exist before reading it, and require the full declared option
(header + payload) to fit before entering the switch. A truncated
trailing option now stops parsing instead of reading past the buffer.
This is a prerequisite for bounding dhcp_process_options() by the
received packet length rather than by BOOTP_HDR_SIZE: fixing the outer
limit alone leaves this inner out-of-bounds read reachable whenever a
short reply's last option is cut off before its length or payload
bytes.
Signed-off-by: Pranav Rajendran <pranavkasthuri@gmail.com>
---
v2: New patch, added in response to review feedback on v1 of
"net: bootp: bound DHCP option parsing by the received packet
length" pointing out this inner gap.
net/bootp.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/net/bootp.c b/net/bootp.c
index f0dc329d6e4..eafbe9e3bb4 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -863,11 +863,20 @@ static void dhcp_process_options(uchar *popt, uchar *end)
#endif
while (popt < end && *popt != 0xff) {
+ if (*popt == 0) {
+ /* Pad option: single byte, no length field */
+ popt++;
+ continue;
+ }
+
+ /* Need a length byte, and the payload it describes */
+ if (popt + 1 >= end)
+ break;
oplen = *(popt + 1);
- switch (*popt) {
- case 0:
- oplen = -1; /* Pad omits len byte */
+ if (popt + 2 + oplen > end)
break;
+
+ switch (*popt) {
case 1:
net_copy_ip(&net_netmask, (popt + 2));
break;
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-08-20 12:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 22:08 [PATCH v1] net: bootp: bound DHCP option parsing by the received packet length Pranav Rajendran
2026-08-20 11:49 ` Jerome Forissier
2026-08-20 12:33 ` [PATCH v2 0/2] " Pranav Rajendran
2026-08-20 12:33 ` Pranav Rajendran [this message]
2026-08-20 12:33 ` [PATCH v2 2/2] " Pranav Rajendran
2026-08-20 12:48 ` Pranav R
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=20260820123315.9272-2-pranavkasthuri@gmail.com \
--to=pranavkasthuri@gmail.com \
--cc=jerome.forissier@arm.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.