This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PING v2][PATCH] Support for BIT_FIELD_REF in asan.c



On 10/03/2014 10:47 AM, Marat Zakirov wrote:

On 09/26/2014 12:55 PM, Marat Zakirov wrote:
Hi all!

Here's a patch which instruments byte-aligned BIT_FIELD_REFs. During GCC asan-bootstrap and Linux kernel build I didn't find any cases where BIT_FIELD_REF is not 8 bits aligned. But I do not have sufficient confidence to replace current return if BIT_FIELD_REF is misaligned to assert.

Ok to commit?

--Marat


gcc/ChangeLog:

2014-09-19  Marat Zakirov  <m.zakirov@samsung.com>

	* asan.c (instrument_derefs): BIT_FIELD_REF added.

gcc/testsuite/ChangeLog:

2014-09-19  Marat Zakirov  <m.zakirov@samsung.com>

	* c-c++-common/asan/bitfield-5.c: New test.

diff --git a/gcc/asan.c b/gcc/asan.c
index cf5de27..451af33 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1705,6 +1705,7 @@ instrument_derefs (gimple_stmt_iterator *iter, tree t,
     case INDIRECT_REF:
     case MEM_REF:
     case VAR_DECL:
+    case BIT_FIELD_REF:
       break;
       /* FALLTHRU */
     default:
diff --git a/gcc/testsuite/c-c++-common/asan/bitfield-5.c b/gcc/testsuite/c-c++-common/asan/bitfield-5.c
new file mode 100644
index 0000000..eb5e9e9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/bitfield-5.c
@@ -0,0 +1,24 @@
+/* Check BIT_FIELD_REF.  */
+
+/* { dg-do run } */
+/* { dg-shouldfail "asan" } */
+
+struct A
+{
+  int y : 20;
+  int x : 13;
+};
+
+int __attribute__ ((noinline, noclone))
+f (void *p) {
+  return ((struct A *)p)->x != 0;
+}
+
+int
+main ()
+{
+  int a = 0;
+  return f (&a);
+}
+
+/* { dg-output "ERROR: AddressSanitizer: stack-buffer-overflow" } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]