Skip to contentSkip to conversation

mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next()

PATCH Applied Nikita Zhandarovich 3 participants 3 messages Apr 17, 2023 – Apr 18, 2023

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

PATCH 1/1 mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next()

Function mlxfw_mfa2_tlv_multi_get() returns NULL if 'tlv' in question does not pass checks in mlxfw_mfa2_tlv_payload_get(). This behaviour may lead to NULL pointer dereference in 'multi->total_len'. Fix this issue by testing mlxfw_mfa2_tlv_multi_get()'s return value against NULL.

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 410ed13cae39 ("Add the mlxfw module for Mellanox firmware flash process")
---
 drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlxfw/mlxfw_mfa2_tlv_multi.c +2 -0
index 017d68f1e123..972c571b4158 100644
@@ -31,6 +31,8 @@ mlxfw_mfa2_tlv_next(const struct mlxfw_mfa2_file *mfa2_file,
 
 	if (tlv->type == MLXFW_MFA2_TLV_MULTI_PART) {
 		multi = mlxfw_mfa2_tlv_multi_get(mfa2_file, tlv);
+		if (!multi)
+			return NULL;
 		tlv_len = NLA_ALIGN(tlv_len + be16_to_cpu(multi->total_len));
 	}
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Nikita Zhandarovich

Function mlxfw_mfa2_tlv_multi_get() returns NULL if 'tlv' in question does not pass checks in mlxfw_mfa2_tlv_payload_get(). This behaviour may lead to NULL pointer dereference in 'multi->total_len'. Fix this issue by testing mlxfw_mfa2_tlv_multi_get()'s return value against NULL.

Quoted 6 lines

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

Fixes 410ed13cae39 ("Add the mlxfw module for Mellanox firmware flash process")
#2 lore raw
In reply to Nikita Zhandarovich
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

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

Quoted 10 lines · On Mon, 17 Apr 2023 05:07:18 -0700 you wrote:

Function mlxfw_mfa2_tlv_multi_get() returns NULL if 'tlv' in question does not pass checks in mlxfw_mfa2_tlv_payload_get(). This behaviour may lead to NULL pointer dereference in 'multi->total_len'. Fix this issue by testing mlxfw_mfa2_tlv_multi_get()'s return value against NULL.

Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE.

[...]

Here is the summary with links:
- [net] mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next()

    https://git.kernel.org/netdev/net/c/c0e73276f0fc

You are awesome, thank you!

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