[4a/6] analyzer: implement region::untrusted_p in terms of custom address spaces
Commit Message
gcc/analyzer/ChangeLog:
(region::untrusted_p): New.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/test-uaccess.h: New header.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
gcc/analyzer/region.cc | 13 +++++++++++++
gcc/testsuite/gcc.dg/analyzer/test-uaccess.h | 19 +++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/analyzer/test-uaccess.h
@@ -666,6 +666,19 @@ region::symbolic_for_unknown_ptr_p () const
return false;
}
+/* Return true if accessing this region crosses a trust boundary
+ e.g. user-space memory as seen by an OS kernel. */
+
+bool
+region::untrusted_p () const
+{
+ addr_space_t as = get_addr_space ();
+ /* FIXME: treat all non-generic address spaces as untrusted for now. */
+ if (!ADDR_SPACE_GENERIC_P (as))
+ return true;
+ return false;
+}
+
/* region's ctor. */
region::region (complexity c, unsigned id, const region *parent, tree type)
new file mode 100644
@@ -0,0 +1,19 @@
+/* Shared header for testcases for copy_from_user/copy_to_user. */
+
+/* Adapted from include/linux/compiler.h */
+
+#pragma GCC custom_address_space(__user)
+
+/* Adapted from include/asm-generic/uaccess.h */
+
+extern int copy_from_user(void *to, const void __user *from, long n)
+ __attribute__((access (write_only, 1, 3),
+ access (read_only, 2, 3),
+ returns_zero_on_success
+ ));
+
+extern long copy_to_user(void __user *to, const void *from, unsigned long n)
+ __attribute__((access (write_only, 1, 3),
+ access (read_only, 2, 3),
+ returns_zero_on_success
+ ));