From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6 (1M context)" <noreply@anthropic.com>
Subject: Re: [PATCH v2 3/3] net: dhcp: cap DHCP option string length to 255 bytes
Date: Fri, 17 Apr 2026 11:49:54 +0200 [thread overview]
Message-ID: <9ab4089e-f8ae-45e0-96d0-0bba9d7cb4b8@pengutronix.de> (raw)
In-Reply-To: <20260402-net-dhcp-buffer-overflows-v2-3-fe4ca7c4b718@pengutronix.de>
On 4/2/26 8:59 AM, Sascha Hauer wrote:
> dhcp_set_string_options() stores the string length in a u8 field but
> uses the full strlen() value for memcpy(). If a user sets a DHCP
> option string (hostname, vendor_id, etc.) longer than 255 bytes, the
> length field silently truncates while memcpy() copies the full string,
> writing past the expected region in the packet buffer.
>
> Cap str_len at 255 to match the maximum DHCP option length defined by
> RFC2132, ensuring the length field and memcpy are consistent.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> net/dhcp.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/dhcp.c b/net/dhcp.c
> index f4e4033351..21d48cfcf2 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.c
> @@ -173,6 +173,10 @@ static int dhcp_set_string_options(int option, const char *str, u8 *e)
> if (!str_len)
> return 0;
>
> + /* DHCP option length field is a single byte per RFC2132 */
> + if (str_len > 255)
> + str_len = 255;
> +
> *e++ = option;
> *e++ = str_len;
> memcpy(e, str, str_len);
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-04-17 9:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 6:59 [PATCH v2 0/3] net: dhcp: fix buffer overflows Sascha Hauer
2026-04-02 6:59 ` [PATCH v2 1/3] net: dhcp: add bounds checking to DHCP option parsing Sascha Hauer
2026-04-17 9:46 ` Ahmad Fatoum
2026-04-02 6:59 ` [PATCH v2 2/3] net: dhcp: use xstrndup for bp_file to prevent read past field Sascha Hauer
2026-04-17 9:47 ` Ahmad Fatoum
2026-04-02 6:59 ` [PATCH v2 3/3] net: dhcp: cap DHCP option string length to 255 bytes Sascha Hauer
2026-04-17 9:49 ` Ahmad Fatoum [this message]
2026-04-17 10:40 ` [PATCH v2 0/3] net: dhcp: fix buffer overflows Sascha Hauer
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=9ab4089e-f8ae-45e0-96d0-0bba9d7cb4b8@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
--cc=s.hauer@pengutronix.de \
/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