aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@infradead.org>2009-09-26 08:33:01 -0400
committerIngo Molnar <mingo@elte.hu>2009-09-26 10:25:41 -0400
commit9f0cf4adb6aa0bfccf675c938124e68f7f06349d (patch)
tree2045a8fa0b207a8adb288eb144c593db7d1f2f0b /include
parent704daf55c7297e727021063cb5d8ba1c55b84426 (diff)
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>
Diffstat (limited to 'include')
-rw-r--r--include/linux/compiler-gcc4.h2
-rw-r--r--include/linux/compiler.h4
2 files changed, 6 insertions, 0 deletions
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
index 450fa597c94d..a3aef5d55dba 100644
--- a/include/linux/compiler-gcc4.h
+++ b/include/linux/compiler-gcc4.h
@@ -37,3 +37,5 @@
37#define __cold __attribute__((__cold__)) 37#define __cold __attribute__((__cold__))
38 38
39#endif 39#endif
40
41#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 04fb5135b4e1..8e54108688f9 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -266,6 +266,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
266# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 266# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
267#endif 267#endif
268 268
269/* Compile time object size, -1 for unknown */
270#ifndef __compiletime_object_size
271# define __compiletime_object_size(obj) -1
272#endif
269/* 273/*
270 * Prevent the compiler from merging or refetching accesses. The compiler 274 * Prevent the compiler from merging or refetching accesses. The compiler
271 * is also forbidden from reordering successive instances of ACCESS_ONCE(), 275 * is also forbidden from reordering successive instances of ACCESS_ONCE(),