Heap randomisation causes PCH testsuite failures

Bug #660156 reported by Michael Hope
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro GCC
Fix Released
Low
Michael Hope
4.5
Fix Released
Low
Michael Hope
4.6
Fix Released
Low
Michael Hope
gcc
Fix Released
Medium

Bug Description

See the upstream ticket. Logged in Linaro to track the backport.

Related branches

Revision history for this message
In , Pinskia (pinskia) wrote :

Most likely when the linux arm kernel decided to randomize the heap.

Revision history for this message
In , Mikpe (mikpe) wrote :

I assume other Linux archs already randomize the heap. If so, why would that cause PCH failures on ARM? Could it be because there's no TRY_EMPTY_VM_SPACE
definition in gcc/config/host-linux.c for ARM?

Revision history for this message
In , Pinskia (pinskia) wrote :

(In reply to comment #2)
> I assume other Linux archs already randomize the heap.
 Could it be because there's no TRY_EMPTY_VM_SPACE definition in gcc/config/host-linux.c for ARM?

yes, a definition for TRY_EMPTY_VM_SPACE is needed for ARM. I just went through this for MIPS but I have not pushed it because I don't currently have a correct copyright assignment on file.

Revision history for this message
In , Mikpe (mikpe) wrote :

Ok. I'll cook something up for TRY_EMPTY_VM_SPACE on ARM.

Revision history for this message
In , Mikpe (mikpe) wrote :

(In reply to comment #1)
> Most likely when the linux arm kernel decided to randomize the heap.

Confirmed. Bisection of the kernel identified:

From: Nicolas Pitre <email address hidden>
Date: Tue, 15 Jun 2010 01:16:19 +0000 (-0400)
Subject: [ARM] add address randomization to mmap()
X-Git-Tag: v2.6.36-rc1~591^2^2~6^2~2
X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=cc92c28b2db5b406657ecc05235d4ca4e222ae34

[ARM] add address randomization to mmap()

Signed-off-by: Nicolas Pitre <email address hidden>
---

diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index f5abc51..4f5b396 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -7,6 +7,7 @@
 #include <linux/shm.h>
 #include <linux/sched.h>
 #include <linux/io.h>
+#include <linux/random.h>
 #include <asm/cputype.h>
 #include <asm/system.h>

@@ -80,6 +81,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
                start_addr = addr = TASK_UNMAPPED_BASE;
                mm->cached_hole_size = 0;
        }
+ /* 8 bits of randomness in 20 address space bits */
+ if (current->flags & PF_RANDOMIZE)
+ addr += (get_random_int() % (1 << 8)) << PAGE_SHIFT;

 full_search:
        if (do_align)

as the cause of this regression. Still, I think the kernel is Ok and it's really gcc's pch implementation which is broken.

Revision history for this message
In , Mikpe (mikpe) wrote :

Created attachment 22030
define TRY_EMPTY_VM_SPACE for ARM

Preliminary patch which defines TRY_EMPTY_VM_SPACE for ARM and fixes the PCH regressions in a PCH-only test run. I'll submit it after some more testing.

Revision history for this message
Michael Hope (michaelh1) wrote :

See the upstream ticket. Logged in Linaro to track the backport.

Revision history for this message
In , Mikpe (mikpe) wrote :

The patch tested ok and has now been submitted:
http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02252.html

Revision history for this message
Michael Hope (michaelh1) wrote :

Patch sent upstream at:
 http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02252.html

No ping, no acceptance, not in 4.6 as at r166926.

Revision history for this message
Michael Hope (michaelh1) wrote :

Asked the original author if he could ping it, else if we could take it over.

Revision history for this message
Michael Hope (michaelh1) wrote :
Revision history for this message
Michael Hope (michaelh1) wrote :

Currently stuck due to copyright assignment issues. Ubuntu could pull in this patch if they wanted.

Will continue to monitor.

Revision history for this message
In , Ibolton (ibolton) wrote :

Please can you confirm that this is now fixed in trunk, Mikael.

And has it been backported?

Revision history for this message
In , Mikpe (mikpe) wrote :

(In reply to comment #8)
> Please can you confirm that this is now fixed in trunk, Mikael.

No, it has not been fixed on trunk.

> And has it been backported?

Not in the official gcc repository. I do use the fix in my private 4.4 and 4.5 based compilers.

Changed in gcc:
importance: Unknown → Medium
status: Unknown → Incomplete
Revision history for this message
Ira Rosen (irar) wrote : AUTO: Ira Rosen is out of the office. (returning 17/04/2011)

I am out of the office until 17/04/2011.

Note: This is an automated response to your message "[Bug 660156] Re: Heap
randomisation causes PCH testsuite failures" sent on 15/4/2011 5:41:01.

This is the only notification you will receive while this person is away.

Revision history for this message
In , Ramana-gcc (ramana-gcc) wrote :

Author: ramana
Date: Thu May 5 09:52:12 2011
New Revision: 173421

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173421
Log:

For Michael Hope.

2011-05-05 Michael Hope <email address hidden>

       PR pch/45979
       * config/host-linux.c (TRY_EMPTY_VM_SPACE): Define for
       __ARM_EABI__ hosts.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/host-linux.c

Revision history for this message
In , Pinskia (pinskia) wrote :

Fixed.

Changed in gcc:
status: Incomplete → Fix Released
Revision history for this message
In , Michaelh-m (michaelh-m) wrote :

Author: michaelh
Date: Fri Mar 23 02:19:46 2012
New Revision: 185724

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185724
Log:
2012-03-16 Michael Hope <email address hidden>

 Backport from mainline
 2011-05-05 Michael Hope <email address hidden>

 PR pch/45979
 * config/host-linux.c (TRY_EMPTY_VM_SPACE): Define for
 __ARM_EABI__ hosts.

Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/host-linux.c

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.