From: Bradley Morgan <include@grrlz.net>
To: Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
Joern Engel <joern@logfs.org>, Pekka Enberg <penberg@kernel.org>,
Christoph Lameter <cl@linux-foundation.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
Bradley Morgan <include@grrlz.net>
Subject: [PATCH] lib/string: fix memchr_inv() for large ranges
Date: Sun, 21 Jun 2026 12:11:33 +0000 [thread overview]
Message-ID: <20260621121133.16460-1-include@grrlz.net> (raw)
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
next reply other threads:[~2026-06-21 12:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-21 12:11 Bradley Morgan [this message]
2026-06-23 20:54 ` [PATCH] lib/string: fix memchr_inv() for large ranges Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260621121133.16460-1-include@grrlz.net \
--to=include@grrlz.net \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=cl@linux-foundation.org \
--cc=joern@logfs.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox