mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Bradley Morgan <include@grrlz.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	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
Subject: Re: [PATCH] lib/string: fix memchr_inv() for large ranges
Date: Tue, 23 Jun 2026 23:54:55 +0300	[thread overview]
Message-ID: <ajrynyaEVnTNEN13@ashevche-desk.local> (raw)
In-Reply-To: <20260621121133.16460-1-include@grrlz.net>

On Sun, Jun 21, 2026 at 12:11:33PM +0000, Bradley Morgan wrote:
> 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.

Wow! Is it real life use case?

> Use size_t for the word count.

...

> @@ -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;

Perhaps move towards reversed xmas tree while at it?

	unsigned int prefix;
	size_t words;
	u8 value = c;
	u64 value64;

(same lines touched, no extra).

>  	if (bytes <= 16)
>  		return check_bytes8(start, value, bytes);

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-06-23 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-21 12:11 Bradley Morgan
2026-06-23 20:54 ` Andy Shevchenko [this message]

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=ajrynyaEVnTNEN13@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=cl@linux-foundation.org \
    --cc=include@grrlz.net \
    --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

all inboxes | Powered by JetHome®