Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] lib/string: fix memchr_inv() for large ranges
@ 2026-06-21 12:11 Bradley Morgan
  2026-06-23 20:54 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Bradley Morgan @ 2026-06-21 12:11 UTC (permalink / raw)
  To: Andrew Morton, Kees Cook, Andy Shevchenko
  Cc: Akinobu Mita, Joern Engel, Pekka Enberg, Christoph Lameter,
	linux-hardening, linux-kernel, Bradley Morgan

memchr_inv() takes a size_t length but counts 8 byte words in an
unsigned int. At 32GiB that count wraps, so the scan can quietly miss
most of the range.

Use size_t for the word count.

Fixes: 798248206b59 ("lib/string.c: introduce memchr_inv()")
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 lib/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/string.c b/lib/string.c
index 1f9297e9776a..8ea7d4b9f0c0 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -837,7 +837,8 @@ void *memchr_inv(const void *start, int c, size_t bytes)
 {
 	u8 value = c;
 	u64 value64;
-	unsigned int words, prefix;
+	size_t words;
+	unsigned int prefix;
 
 	if (bytes <= 16)
 		return check_bytes8(start, value, bytes);
-- 
2.53.0


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

end of thread, other threads:[~2026-06-23 20:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-21 12:11 [PATCH] lib/string: fix memchr_inv() for large ranges Bradley Morgan
2026-06-23 20:54 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox