Skip to contentSkip to conversation

net: prestera: validate firmware header length

PATCH Applied Pengpeng Hou 3 participants 3 messages Jul 31 – Aug 6

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: prestera: validate firmware header length

prestera_fw_hdr_parse() reads the firmware header before checking that the firmware image contains that header.

Reject images shorter than struct prestera_fw_header before decoding the magic and version fields.

---
Changes since v1: https://lore.kernel.org/all/[email protected]/
- target the net tree in the Subject as requested by Andrew Lunn
- rebase onto the current tree

 drivers/net/ethernet/marvell/prestera/prestera_pci.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_pci.c +3 -0
index 2989a77e3b42..1ad0e62a8433 100644
@@ -684,6 +684,9 @@ static int prestera_fw_hdr_parse(struct prestera_fw *fw)
 	struct prestera_fw_header *hdr;
 	u32 magic;
 
+	if (fw->bin->size < sizeof(*hdr))
+		return -EINVAL;
+
 	hdr = (struct prestera_fw_header *)fw->bin->data;
 
 	magic = be32_to_cpu(hdr->magic_number);
Signature · 1 line
2.50.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 38 lines

From: Pengpeng Hou <[email protected]>
Sent: Friday, July 31, 2026 5:19 PM
To: Elad Nachman <[email protected]>
Cc: Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; [email protected]; Pengpeng Hou <[email protected]>
Subject: [EXTERNAL] [PATCH net v2] net: prestera: validate firmware header length

prestera_fw_hdr_parse() reads the firmware header before checking that the firmware image contains that header.

Reject images shorter than struct prestera_fw_header before decoding the magic and version fields.

---
Changes since v1
- target the net tree in the Subject as requested by Andrew Lunn
- rebase onto the current tree

 drivers/net/ethernet/marvell/prestera/prestera_pci.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_pci.c +3 -1
index 2989a77e3b42..1ad0e62a8433 100644
@@ -684,6 +684,9 @@ static int prestera_fw_hdr_parse(struct prestera_fw *fw)
      struct prestera_fw_header *hdr;
      u32 magic;
 
+     if (fw->bin->size < sizeof(*hdr))
+             return -EINVAL;
+
      hdr = (struct prestera_fw_header *)fw->bin->data;
 
      magic = be32_to_cpu(hdr->magic_number);
--
Quoted 2 lines

2.50.1

#2 lore raw
In reply to Pengpeng Hou
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 31 Jul 2026 22:19:06 +0800 you wrote:

prestera_fw_hdr_parse() reads the firmware header before checking that the firmware image contains that header.

Reject images shorter than struct prestera_fw_header before decoding the magic and version fields.

[...]

Here is the summary with links:
- [net,v2] net: prestera: validate firmware header length

    https://git.kernel.org/netdev/net/c/8ae344eb540a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html