From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Opus 4.6" <noreply@anthropic.com>
Subject: [PATCH 03/10] net: dhcp: use net_eth_to_udp() for packet parsing
Date: Thu, 02 Apr 2026 08:36:42 +0200 [thread overview]
Message-ID: <20260402-net-eth-do-udp-v1-3-af5d9fd6beec@pengutronix.de> (raw)
In-Reply-To: <20260402-net-eth-do-udp-v1-0-af5d9fd6beec@pengutronix.de>
Replace the separate net_eth_to_udp_payload(), net_eth_to_udphdr() and
net_eth_to_udplen() calls with the new consolidated net_eth_to_udp()
helper. This validates the packet length before accessing any headers.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
net/dhcp.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index e25b64842d..39168a2d53 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -391,16 +391,18 @@ static void dhcp_send_request_packet(struct bootp *bp_offer)
*/
static void dhcp_handler(void *ctx, char *packet, unsigned int len)
{
- char *pkt = net_eth_to_udp_payload(packet);
- struct udphdr *udp = net_eth_to_udphdr(packet);
- struct bootp *bp = (struct bootp *)pkt;
+ struct net_udp_pkt udp;
+ struct bootp *bp;
+
+ if (net_eth_to_udp(packet, len, &udp))
+ return;
- len = net_eth_to_udplen(packet);
+ bp = udp.payload;
- debug("DHCPHandler: got packet: (len=%d) state: %d\n",
- len, dhcp_state);
+ debug("DHCPHandler: got packet: (len=%u) state: %d\n",
+ udp.len, dhcp_state);
- if (bootp_check_packet(pkt, ntohs(udp->uh_sport), len)) /* Filter out pkts we don't want */
+ if (bootp_check_packet(udp.payload, ntohs(udp.udp->uh_sport), udp.len))
return;
switch (dhcp_state) {
--
2.47.3
next prev parent reply other threads:[~2026-04-02 6:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 6:36 [PATCH 00/10] net: prevent buffer overflows in UDP packets Sascha Hauer
2026-04-02 6:36 ` [PATCH 01/10] net: add net_eth_to_udp() helper for validated UDP extraction Sascha Hauer
2026-04-02 6:36 ` [PATCH 02/10] fs: tftp: use net_eth_to_udp() for packet parsing Sascha Hauer
2026-04-02 6:36 ` Sascha Hauer [this message]
2026-04-02 6:36 ` [PATCH 04/10] fs: nfs: " Sascha Hauer
2026-04-02 6:36 ` [PATCH 05/10] net: dns: " Sascha Hauer
2026-04-02 6:36 ` [PATCH 06/10] net: sntp: " Sascha Hauer
2026-04-02 6:36 ` [PATCH 07/10] net: netconsole: " Sascha Hauer
2026-04-02 6:36 ` [PATCH 08/10] net: fastboot: " Sascha Hauer
2026-04-02 6:36 ` [PATCH 09/10] net: fastboot: stop using net_eth_to_udp_payload() for PACKET_SIZE Sascha Hauer
2026-04-02 6:36 ` [PATCH 10/10] net: remove unused net_eth_to_udp{hdr,_payload,len}() helpers 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=20260402-net-eth-do-udp-v1-3-af5d9fd6beec@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.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