]> git.baikalelectronics.ru Git - kernel.git/commit
x86: Use __builtin_object_size() to validate the buffer size for copy_from_user()
authorArjan van de Ven <arjan@infradead.org>
Sat, 26 Sep 2009 12:33:01 +0000 (14:33 +0200)
committerIngo Molnar <mingo@elte.hu>
Sat, 26 Sep 2009 14:25:41 +0000 (16:25 +0200)
commit3bc606696a8a1a6fe249de1554d390c24001c9e0
tree2045a8fa0b207a8adb288eb144c593db7d1f2f0b
parent1d3e773c6d1cb8a6191bffbfd3bb41eae78e6761
x86: Use __builtin_object_size() to validate the buffer size for copy_from_user()

gcc (4.x) supports the __builtin_object_size() builtin, which
reports the size of an object that a pointer point to, when known
at compile time. If the buffer size is not known at compile time, a
constant -1 is returned.

This patch uses this feature to add a sanity check to
copy_from_user(); if the target buffer is known to be smaller than
the copy size, the copy is aborted and a WARNing is emitted in
memory debug mode.

These extra checks compile away when the object size is not known,
or if both the buffer size and the copy length are constants.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
LKML-Reference: <20090926143301.2c396b94@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/uaccess_32.h
arch/x86/include/asm/uaccess_64.h
arch/x86/kernel/x8664_ksyms_64.c
arch/x86/lib/copy_user_64.S
arch/x86/lib/usercopy_32.c
include/linux/compiler-gcc4.h
include/linux/compiler.h