Skip to contentSkip to conversation

mac_pton: Don't access memory over expected length

PATCH RESEND Applied Andy Shevchenko 2 participants 2 messages Nov 8, 2022 – Nov 10, 2022

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

PATCH RESEND 1/1 mac_pton: Don't access memory over expected length

The strlen() may go too far when estimating the length of the given string. In some cases it may go over the boundary and crash the system which is the case according to the commit 13a55372b64e ("ARM: orion5x: Revert commit 4904dbda41c8.").

Rectify this by switching to strnlen() for the expected maximum length of the string.

---
v1[resend]: used net-next (Jakub)

 lib/net_utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/net_utils.c +2 -1
index af525353395d..c17201df3d08 100644
@@ -6,10 +6,11 @@
 
 bool mac_pton(const char *s, u8 *mac)
 {
+	size_t maxlen = 3 * ETH_ALEN - 1;
 	int i;
 
 	/* XX:XX:XX:XX:XX:XX */
-	if (strlen(s) < 3 * ETH_ALEN - 1)
+	if (strnlen(s, maxlen) < maxlen)
 		return false;
 
 	/* Don't dirty result unless string is valid MAC. */
Signature · 1 line
2.35.1
#1 lore raw
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 9 lines · On Tue, 8 Nov 2022 16:11:08 +0200 you wrote:

The strlen() may go too far when estimating the length of the given string. In some cases it may go over the boundary and crash the system which is the case according to the commit 13a55372b64e ("ARM: orion5x: Revert commit 4904dbda41c8.").

Rectify this by switching to strnlen() for the expected maximum length of the string.

[...]

Here is the summary with links:
- [resend,net-next,v1,1/1] mac_pton: Don't access memory over expected length

    https://git.kernel.org/netdev/net-next/c/21780f89d658

You are awesome, thank you!

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