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  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:	Sat, 29 May 2010 20:42:56 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Cesar Eduardo Barros <cesarb@...arb.net>
Cc:	linux-mm@...ck.org, linux-kernel@...r.kernel.org,
	Russell King <linux@....linux.org.uk>,
	Ralf Baechle <ralf@...ux-mips.org>,
	David Howells <dhowells@...hat.com>,
	Koichi Yasutake <yasutake.koichi@...panasonic.com>,
	Benjamin Herrenschmidt <benh@...nel.crashing.org>,
	Paul Mackerras <paulus@...ba.org>,
	"David S. Miller" <davem@...emloft.net>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
	Arnd Bergmann <arnd@...db.de>,
	Rusty Russell <rusty@...tcorp.com.au>
Subject: Re: [PATCH] Make kunmap_atomic() harder to misuse

On Fri, 28 May 2010 07:53:13 -0300 Cesar Eduardo Barros <cesarb@...arb.net> wrote:

> kunmap_atomic() is currently at level -4 on Rusty's "Hard To Misuse"
> list[1] ("Follow common convention and you'll get it wrong"), except in
> some architectures when CONFIG_DEBUG_HIGHMEM is set[2][3].
> 
> kunmap() takes a pointer to a struct page; kunmap_atomic(), however,
> takes takes a pointer to within the page itself. This seems to once in a
> while trip people up (the convention they are following is the one from
> kunmap()).
> 
> Make it much harder to misuse, by moving it to level 9 on Rusty's
> list[4] ("The compiler/linker won't let you get it wrong"). This is done
> by refusing to build if the pointer passed to it is convertible to a
> struct page * but it is not a void * (verified by trying to convert it
> to a pointer to a dummy struct).
> 
> The real kunmap_atomic() is renamed to kunmap_atomic_notypecheck()
> (which is what you would call in case for some strange reason calling it
> with a pointer to a struct page is not incorrect in your code).
> 

Fair enough, that's a 99% fix.  A long time ago I made kmap_atomic()
return a char * (iirc) and kunmap_atomic() is passed a char*.  It
worked, but I ended up throwing it away.  I don't precisely remember
why - I think it was intrusiveness and general hassle rather than
anything fundamental.

>
> ...
>
> +/* Prevent people trying to call kunmap_atomic() as if it were kunmap() */
> +struct __kunmap_atomic_dummy {};
> +#define kunmap_atomic(addr, idx) do { \
> +		BUILD_BUG_ON( \
> +			__builtin_types_compatible_p(typeof(addr), struct page *) && \
> +			!__builtin_types_compatible_p(typeof(addr), struct __kunmap_atomic_dummy *)); \
> +		kunmap_atomic_notypecheck((addr), (idx)); \
> +	} while (0)

<looks around>

OK, it seems that __builtin_types_compatible_p() is supported on all
approved gcc versions.

We have a little __same_type() helper for this.  __must_be_array()
should be using it, too.

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