diff mbox series

testsuite: Correct check_effective_target_hwaddress_exec

Message ID AM6PR08MB315791AD74E9CAA9162B4FE7E0F80@AM6PR08MB3157.eurprd08.prod.outlook.com
State New
Headers show
Series testsuite: Correct check_effective_target_hwaddress_exec | expand

Commit Message

Matthew Malcomson Nov. 27, 2020, 6:46 p.m. UTC
Hello,

-----

This test should ensure that we can compile with hwasan, that such a compiled
binary runs as expected, *and* that we're running on a kernel which implements
the capability to ignore the top bytes of pointers in syscalls.

It was expected that a basic test of `int main(void) { return 0; }` would check
this, since there is a check called during `__hwasan_init` in libhwasan to
ensure that the kernel we're running on provides a `prctl` to request the
relaxed ABI.

Unfortunately, the check in libhwasan has a bug in it, and does not correctly
fail when the kernel feature is not around.  This means that check is not
automatically provided by the runtime.

The sanitizer runtime will be fixed but would like to install this fix here in
case fixing the library is not quick enough for the release (and so that people
running the testsuite do not see spurious errors in the meantime).

Tested by running testsuite on an AArch64 machine with and without the required
kernel.
Observed that the test does indeed fail when the kernel feature is unavailable
and pass when the feature is available.

Note that this test is directly targetting AArch64 by using `prctl` numbers
specific to it.  That's unfortunate, but once the runtime fix has gone in we
will be able to remove that requirement.

Ok for trunk?

gcc/testsuite/ChangeLog:

	* lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix
	check for correct kernel version.



###############     Attachment also inlined for ease of reply    ###############
diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
index 892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2 100644
--- a/gcc/testsuite/lib/hwasan-dg.exp
+++ b/gcc/testsuite/lib/hwasan-dg.exp
@@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} {
 
 proc check_effective_target_hwaddress_exec {} {
     if ![check_runtime hwaddress_exec {
-	int main (void) { return 0; }
+	#ifdef __cplusplus
+	extern "C" {
+	#endif
+	extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long);
+	#ifdef __cplusplus
+	}
+	#endif
+	int main (void) {
+	#define PR_SET_TAGGED_ADDR_CTRL 55
+	#define PR_GET_TAGGED_ADDR_CTRL 56
+	#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+	  if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1)
+	    return 1;
+	  if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1
+	      || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))
+	    return 1;
+	  return 0;
+	}
     }] {
 	return 0;
     }

Comments

Jeff Law Nov. 30, 2020, 1:25 a.m. UTC | #1
On 11/27/20 11:46 AM, Matthew Malcomson via Gcc-patches wrote:
> Hello,
>
> -----
>
> This test should ensure that we can compile with hwasan, that such a compiled
> binary runs as expected, *and* that we're running on a kernel which implements
> the capability to ignore the top bytes of pointers in syscalls.
>
> It was expected that a basic test of `int main(void) { return 0; }` would check
> this, since there is a check called during `__hwasan_init` in libhwasan to
> ensure that the kernel we're running on provides a `prctl` to request the
> relaxed ABI.
>
> Unfortunately, the check in libhwasan has a bug in it, and does not correctly
> fail when the kernel feature is not around.  This means that check is not
> automatically provided by the runtime.
>
> The sanitizer runtime will be fixed but would like to install this fix here in
> case fixing the library is not quick enough for the release (and so that people
> running the testsuite do not see spurious errors in the meantime).
>
> Tested by running testsuite on an AArch64 machine with and without the required
> kernel.
> Observed that the test does indeed fail when the kernel feature is unavailable
> and pass when the feature is available.
>
> Note that this test is directly targetting AArch64 by using `prctl` numbers
> specific to it.  That's unfortunate, but once the runtime fix has gone in we
> will be able to remove that requirement.
>
> Ok for trunk?
>
> gcc/testsuite/ChangeLog:
>
> 	* lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix
> 	check for correct kernel version.
OK
jeff
Christophe Lyon Dec. 1, 2020, 10:56 a.m. UTC | #2
On Fri, 27 Nov 2020 at 19:46, Matthew Malcomson
<matthew.malcomson@arm.com> wrote:
>
> Hello,
>
> -----
>
> This test should ensure that we can compile with hwasan, that such a compiled
> binary runs as expected, *and* that we're running on a kernel which implements
> the capability to ignore the top bytes of pointers in syscalls.
>
> It was expected that a basic test of `int main(void) { return 0; }` would check
> this, since there is a check called during `__hwasan_init` in libhwasan to
> ensure that the kernel we're running on provides a `prctl` to request the
> relaxed ABI.
>
> Unfortunately, the check in libhwasan has a bug in it, and does not correctly
> fail when the kernel feature is not around.  This means that check is not
> automatically provided by the runtime.
>
> The sanitizer runtime will be fixed but would like to install this fix here in
> case fixing the library is not quick enough for the release (and so that people
> running the testsuite do not see spurious errors in the meantime).
>
> Tested by running testsuite on an AArch64 machine with and without the required
> kernel.
> Observed that the test does indeed fail when the kernel feature is unavailable
> and pass when the feature is available.
>
> Note that this test is directly targetting AArch64 by using `prctl` numbers
> specific to it.  That's unfortunate, but once the runtime fix has gone in we
> will be able to remove that requirement.
>
> Ok for trunk?
>
> gcc/testsuite/ChangeLog:
>
>         * lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix
>         check for correct kernel version.
>

Hi Matthew,

Thanks for the patch: I could test it in my validation environment and it makes
the offending tests unsupported, which will prevent spurious regression reports.

Thanks

Christophe

>
>
> ###############     Attachment also inlined for ease of reply    ###############
>
>
> diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
> index 892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2 100644
> --- a/gcc/testsuite/lib/hwasan-dg.exp
> +++ b/gcc/testsuite/lib/hwasan-dg.exp
> @@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} {
>
>  proc check_effective_target_hwaddress_exec {} {
>      if ![check_runtime hwaddress_exec {
> -       int main (void) { return 0; }
> +       #ifdef __cplusplus
> +       extern "C" {
> +       #endif
> +       extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long);
> +       #ifdef __cplusplus
> +       }
> +       #endif
> +       int main (void) {
> +       #define PR_SET_TAGGED_ADDR_CTRL 55
> +       #define PR_GET_TAGGED_ADDR_CTRL 56
> +       #define PR_TAGGED_ADDR_ENABLE (1UL << 0)
> +         if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1)
> +           return 1;
> +         if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1
> +             || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))
> +           return 1;
> +         return 0;
> +       }
>      }] {
>         return 0;
>      }
>
diff mbox series

Patch

diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
index 892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2 100644
--- a/gcc/testsuite/lib/hwasan-dg.exp
+++ b/gcc/testsuite/lib/hwasan-dg.exp
@@ -41,7 +41,24 @@  proc check_effective_target_fsanitize_hwaddress {} {
 
 proc check_effective_target_hwaddress_exec {} {
     if ![check_runtime hwaddress_exec {
-	int main (void) { return 0; }
+	#ifdef __cplusplus
+	extern "C" {
+	#endif
+	extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long);
+	#ifdef __cplusplus
+	}
+	#endif
+	int main (void) {
+	#define PR_SET_TAGGED_ADDR_CTRL 55
+	#define PR_GET_TAGGED_ADDR_CTRL 56
+	#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+	  if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1)
+	    return 1;
+	  if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1
+	      || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))
+	    return 1;
+	  return 0;
+	}
     }] {
 	return 0;
     }