[PATCH 4b/6] analyzer: implement region::untrusted_p in terms of __attribute__((untrusted))

David Malcolm dmalcolm@redhat.com
Sat Nov 13 20:37:30 GMT 2021


gcc/analyzer/ChangeLog:
	* region.cc (region::untrusted_p): Implement in terms of
	__attribute__((untrusted)).

gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/test-uaccess.h: Change from custom_address_space
	pragma to __attribute__((untrusted)).

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/region.cc                       | 19 +++++++++++++++----
 gcc/testsuite/gcc.dg/analyzer/test-uaccess.h |  2 +-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc
index b84504dbe42..52e9fa2d1e6 100644
--- a/gcc/analyzer/region.cc
+++ b/gcc/analyzer/region.cc
@@ -672,10 +672,21 @@ region::symbolic_for_unknown_ptr_p () const
 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;
+  const region *iter = this;
+  while (iter)
+    {
+      if (iter->get_type ())
+	return TYPE_UNTRUSTED (iter->get_type ());
+      switch (iter->get_kind ())
+	{
+	default:
+	  iter = iter->get_parent_region ();
+	  continue;
+	case RK_CAST:
+	  iter = iter->dyn_cast_cast_region ()->get_original_region ();
+	  continue;
+	}
+    }
   return false;
 }
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h
index 0500e20b22b..280f4045418 100644
--- a/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h
+++ b/gcc/testsuite/gcc.dg/analyzer/test-uaccess.h
@@ -2,7 +2,7 @@
 
 /* Adapted from include/linux/compiler.h  */
 
-#pragma GCC custom_address_space(__user)
+#define __user __attribute__((untrusted))
 
 /* Adapted from include/asm-generic/uaccess.h  */
 
-- 
2.26.3



More information about the Gcc-patches mailing list