lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 22 Aug 2011 13:52:18 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Akinobu Mita <akinobu.mita@...il.com>
Cc:	linux-kernel@...r.kernel.org, linux-mm@...ck.org,
	Christoph Lameter <cl@...ux-foundation.org>,
	Pekka Enberg <penberg@...nel.org>,
	Matt Mackall <mpm@...enic.com>, Joern Engel <joern@...fs.org>,
	logfs@...fs.org, Marcin Slusarz <marcin.slusarz@...il.com>,
	Eric Dumazet <eric.dumazet@...il.com>,
	linux-arch@...r.kernel.org
Subject: Re: [PATCH 3/4] string: introduce memchr_inv

On Tue, 23 Aug 2011 01:29:07 +0900
Akinobu Mita <akinobu.mita@...il.com> wrote:

> memchr_inv() is mainly used to check whether the whole buffer is filled
> with just a specified byte.
> 
> The function name and prototype are stolen from logfs and the
> implementation is from SLUB.
> 
> ...
>
> +/**
> + * memchr_inv - Find a character in an area of memory.
> + * @s: The memory area
> + * @c: The byte to search for
> + * @n: The size of the area.

This text seems to be stolen from memchr().  I guess it's close enough.

> + * returns the address of the first character other than @c, or %NULL
> + * if the whole buffer contains just @c.
> + */
> +void *memchr_inv(const void *start, int c, size_t bytes)
> +{
> +	u8 value = c;
> +	u64 value64;
> +	unsigned int words, prefix;
> +
> +	if (bytes <= 16)
> +		return check_bytes8(start, value, bytes);
> +
> +	value64 = value | value << 8 | value << 16 | value << 24;
> +	value64 = (value64 & 0xffffffff) | value64 << 32;
> +	prefix = 8 - ((unsigned long)start) % 8;
> +
> +	if (prefix) {
> +		u8 *r = check_bytes8(start, value, prefix);
> +		if (r)
> +			return r;
> +		start += prefix;
> +		bytes -= prefix;
> +	}
> +
> +	words = bytes / 8;
> +
> +	while (words) {
> +		if (*(u64 *)start != value64)

OK, problem.  This will explode if passed a misaligned address on
certain (non-x86) architectures.  This is nasty because people will
develop and test code on x86 and it works.  Much later, the
alpha/ia64/etc guys discover the problem.

One fix would be to use get_unaligned().  This might be slow on some
architectures, I don't know.  Another fix is to restrict the caller's
alignment freedom; document this and add a runtime WARN_ON().

> +			return check_bytes8(start, value, 8);
> +		start += 8;
> +		words--;
> +	}
> +
> +	return check_bytes8(start, value, bytes % 8);
> +}
> +EXPORT_SYMBOL(memchr_inv);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ