netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] mac_pton: Don't access memory over expected length
@ 2022-10-05 16:43 Andy Shevchenko
  2022-10-06  3:37 ` Jakub Kicinski
  2022-10-10 20:19 ` Andrew Lunn
  0 siblings, 2 replies; 9+ messages in thread
From: Andy Shevchenko @ 2022-10-05 16:43 UTC (permalink / raw)
  To: Andy Shevchenko, netdev, linux-kernel
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Andrew Morton

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/net_utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/net_utils.c b/lib/net_utils.c
index af525353395d..c17201df3d08 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -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. */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-11-08 13:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-05 16:43 [PATCH v1 1/1] mac_pton: Don't access memory over expected length Andy Shevchenko
2022-10-06  3:37 ` Jakub Kicinski
2022-10-10 20:19 ` Andrew Lunn
2022-10-10 20:29   ` Andy Shevchenko
2022-10-10 20:45     ` Andrew Lunn
2022-11-08 13:55       ` Andy Shevchenko
2022-10-11  0:38   ` Jakub Kicinski
2022-11-08 13:51     ` Andy Shevchenko
2022-11-08 13:55       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).