All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tile: support ASLR fully
@ 2013-08-09 19:45 Tony Lu
  2013-08-10 16:55 ` Jiri Kosina
  0 siblings, 1 reply; 5+ messages in thread
From: Tony Lu @ 2013-08-09 19:45 UTC (permalink / raw)
  To: linux-kernel, Jiri Kosina

With this change, tile Linux now supports address-space layout
randomization for shared objects, stack, heap and vdso.

Signed-off-by: Tony Lu <zlu@tilera.com>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
---
 arch/tile/include/asm/elf.h |  4 ++++
 arch/tile/mm/mmap.c         | 20 ++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
index 31d854f..e1da88e 100644
--- a/arch/tile/include/asm/elf.h
+++ b/arch/tile/include/asm/elf.h
@@ -137,6 +137,10 @@ do { \
 	NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
 } while (0)
 
+struct mm_struct;
+extern unsigned long arch_randomize_brk(struct mm_struct *mm);
+#define arch_randomize_brk arch_randomize_brk
+
 #ifdef CONFIG_COMPAT
 
 #define COMPAT_ELF_PLATFORM "tilegx-m32"
diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
index d67d91e..b3686ce 100644
--- a/arch/tile/mm/mmap.c
+++ b/arch/tile/mm/mmap.c
@@ -58,16 +58,32 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
 #else
 	int is_32bit = 0;
 #endif
+	unsigned long random_factor = 0UL;
+
+	if (current->flags & PF_RANDOMIZE) {
+		random_factor = get_random_int();
+		random_factor = random_factor << PAGE_SHIFT;
+		if (is_32bit)
+			random_factor &= 0xfffffful;
+		else
+			random_factor &= 0xffffffful;
+	}
 
 	/*
 	 * Use standard layout if the expected stack growth is unlimited
 	 * or we are running native 64 bits.
 	 */
-	if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
-		mm->mmap_base = TASK_UNMAPPED_BASE;
+	if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
+		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
 		mm->get_unmapped_area = arch_get_unmapped_area;
 	} else {
 		mm->mmap_base = mmap_base(mm);
 		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
 	}
 }
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+	unsigned long range_end = mm->brk + 0x02000000;
+	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
+}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tile: support ASLR fully
  2013-08-09 19:45 [PATCH] tile: support ASLR fully Tony Lu
@ 2013-08-10 16:55 ` Jiri Kosina
  2013-08-10 17:23   ` richard -rw- weinberger
  2013-08-13 14:45   ` [PATCH v2] " Tony Lu
  0 siblings, 2 replies; 5+ messages in thread
From: Jiri Kosina @ 2013-08-10 16:55 UTC (permalink / raw)
  To: Tony Lu; +Cc: linux-kernel

On Fri, 9 Aug 2013, Tony Lu wrote:

> With this change, tile Linux now supports address-space layout
> randomization for shared objects, stack, heap and vdso.
> 
> Signed-off-by: Tony Lu <zlu@tilera.com>
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
> ---
>  arch/tile/include/asm/elf.h |  4 ++++
>  arch/tile/mm/mmap.c         | 20 ++++++++++++++++++--
>  2 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
> index 31d854f..e1da88e 100644
> --- a/arch/tile/include/asm/elf.h
> +++ b/arch/tile/include/asm/elf.h
> @@ -137,6 +137,10 @@ do { \
>  	NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
>  } while (0)
>  
> +struct mm_struct;
> +extern unsigned long arch_randomize_brk(struct mm_struct *mm);
> +#define arch_randomize_brk arch_randomize_brk
> +
>  #ifdef CONFIG_COMPAT
>  
>  #define COMPAT_ELF_PLATFORM "tilegx-m32"
> diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
> index d67d91e..b3686ce 100644
> --- a/arch/tile/mm/mmap.c
> +++ b/arch/tile/mm/mmap.c
> @@ -58,16 +58,32 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
>  #else
>  	int is_32bit = 0;
>  #endif
> +	unsigned long random_factor = 0UL;
> +
> +	if (current->flags & PF_RANDOMIZE) {
> +		random_factor = get_random_int();
> +		random_factor = random_factor << PAGE_SHIFT;
> +		if (is_32bit)
> +			random_factor &= 0xfffffful;
> +		else
> +			random_factor &= 0xffffffful;
> +	}

Hi Tony,

to me, the used math seems not to be immediatley understandable on a first 
sight. Instead of using full range of get_random_int() and then clamping 
it by anding with 0xffffffUL or fffffffUL, how about just using 
appropriate division reminder to the result of get_random_int()? (for 
inspiration and for understanding of what I mean, please see what 
mmap_rnd() is doing on x86).

>  
>  	/*
>  	 * Use standard layout if the expected stack growth is unlimited
>  	 * or we are running native 64 bits.
>  	 */
> -	if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
> -		mm->mmap_base = TASK_UNMAPPED_BASE;
> +	if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
> +		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
>  		mm->get_unmapped_area = arch_get_unmapped_area;
>  	} else {
>  		mm->mmap_base = mmap_base(mm);
>  		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
>  	}
>  }
> +
> +unsigned long arch_randomize_brk(struct mm_struct *mm)
> +{
> +	unsigned long range_end = mm->brk + 0x02000000;
> +	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
> +}

Otherwise the patch looks good to me, so once you either add some 
explanatory comment to the get_random_int() math, or convert it to use 
division reminder, I'll be happy to Ack it.

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tile: support ASLR fully
  2013-08-10 16:55 ` Jiri Kosina
@ 2013-08-10 17:23   ` richard -rw- weinberger
  2013-08-13 14:45   ` [PATCH v2] " Tony Lu
  1 sibling, 0 replies; 5+ messages in thread
From: richard -rw- weinberger @ 2013-08-10 17:23 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Tony Lu, LKML

On Sat, Aug 10, 2013 at 6:55 PM, Jiri Kosina <jkosina@suse.cz> wrote:
> On Fri, 9 Aug 2013, Tony Lu wrote:
>
>> With this change, tile Linux now supports address-space layout
>> randomization for shared objects, stack, heap and vdso.
>>
>> Signed-off-by: Tony Lu <zlu@tilera.com>
>> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
>> ---
>>  arch/tile/include/asm/elf.h |  4 ++++
>>  arch/tile/mm/mmap.c         | 20 ++++++++++++++++++--
>>  2 files changed, 22 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
>> index 31d854f..e1da88e 100644
>> --- a/arch/tile/include/asm/elf.h
>> +++ b/arch/tile/include/asm/elf.h
>> @@ -137,6 +137,10 @@ do { \
>>       NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
>>  } while (0)
>>
>> +struct mm_struct;
>> +extern unsigned long arch_randomize_brk(struct mm_struct *mm);
>> +#define arch_randomize_brk arch_randomize_brk
>> +
>>  #ifdef CONFIG_COMPAT
>>
>>  #define COMPAT_ELF_PLATFORM "tilegx-m32"
>> diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
>> index d67d91e..b3686ce 100644
>> --- a/arch/tile/mm/mmap.c
>> +++ b/arch/tile/mm/mmap.c
>> @@ -58,16 +58,32 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
>>  #else
>>       int is_32bit = 0;
>>  #endif
>> +     unsigned long random_factor = 0UL;
>> +
>> +     if (current->flags & PF_RANDOMIZE) {
>> +             random_factor = get_random_int();
>> +             random_factor = random_factor << PAGE_SHIFT;
>> +             if (is_32bit)
>> +                     random_factor &= 0xfffffful;
>> +             else
>> +                     random_factor &= 0xffffffful;
>> +     }
>
> Hi Tony,
>
> to me, the used math seems not to be immediatley understandable on a first
> sight. Instead of using full range of get_random_int() and then clamping
> it by anding with 0xffffffUL or fffffffUL, how about just using
> appropriate division reminder to the result of get_random_int()? (for
> inspiration and for understanding of what I mean, please see what
> mmap_rnd() is doing on x86).

Looks like copy&paste from some other arch's implementation.
IMHO it's time to consolidate all the different but still mostly identical
arch_pick_mmap_layout() implementations.

>>
>>       /*
>>        * Use standard layout if the expected stack growth is unlimited
>>        * or we are running native 64 bits.
>>        */
>> -     if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
>> -             mm->mmap_base = TASK_UNMAPPED_BASE;
>> +     if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
>> +             mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
>>               mm->get_unmapped_area = arch_get_unmapped_area;
>>       } else {
>>               mm->mmap_base = mmap_base(mm);
>>               mm->get_unmapped_area = arch_get_unmapped_area_topdown;
>>       }
>>  }
>> +
>> +unsigned long arch_randomize_brk(struct mm_struct *mm)
>> +{
>> +     unsigned long range_end = mm->brk + 0x02000000;
>> +     return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
>> +}
>
> Otherwise the patch looks good to me, so once you either add some
> explanatory comment to the get_random_int() math, or convert it to use
> division reminder, I'll be happy to Ack it.
>
> Thanks,
>
> --
> Jiri Kosina
> SUSE Labs
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] tile: support ASLR fully
  2013-08-10 16:55 ` Jiri Kosina
  2013-08-10 17:23   ` richard -rw- weinberger
@ 2013-08-13 14:45   ` Tony Lu
  2013-08-19 12:01     ` Jiri Kosina
  1 sibling, 1 reply; 5+ messages in thread
From: Tony Lu @ 2013-08-13 14:45 UTC (permalink / raw)
  To: linux-kernel, cmetcalf, Jiri Kosina

With this change, tile Linux now supports address-space layout
randomization for shared objects, stack, heap and vdso.

Signed-off-by: Tony Lu <zlu@tilera.com>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
---
v2: implement Jiri Kosina's suggestion to copy the math in
mmap_rnd() for x86.

 arch/tile/include/asm/elf.h |  4 ++++
 arch/tile/mm/mmap.c         | 24 ++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
index 31d854f..e1da88e 100644
--- a/arch/tile/include/asm/elf.h
+++ b/arch/tile/include/asm/elf.h
@@ -137,6 +137,10 @@ do { \
 	NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
 } while (0)
 
+struct mm_struct;
+extern unsigned long arch_randomize_brk(struct mm_struct *mm);
+#define arch_randomize_brk arch_randomize_brk
+
 #ifdef CONFIG_COMPAT
 
 #define COMPAT_ELF_PLATFORM "tilegx-m32"
diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
index d67d91e..4b99344 100644
--- a/arch/tile/mm/mmap.c
+++ b/arch/tile/mm/mmap.c
@@ -58,16 +58,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
 #else
 	int is_32bit = 0;
 #endif
+	unsigned long random_factor = 0UL;
+
+	/*
+	 *  8 bits of randomness in 32bit mmaps, 24 address space bits
+	 * 12 bits of randomness in 64bit mmaps, 28 address space bits
+	 */
+	if (current->flags & PF_RANDOMIZE) {
+		if (is_32bit)
+			random_factor = get_random_int() % (1<<8);
+		else
+			random_factor = get_random_int() % (1<<12);
+		
+		random_factor <<= PAGE_SHIFT;
+	}
 
 	/*
 	 * Use standard layout if the expected stack growth is unlimited
 	 * or we are running native 64 bits.
 	 */
-	if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
-		mm->mmap_base = TASK_UNMAPPED_BASE;
+	if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
+		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
 		mm->get_unmapped_area = arch_get_unmapped_area;
 	} else {
 		mm->mmap_base = mmap_base(mm);
 		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
 	}
 }
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+	unsigned long range_end = mm->brk + 0x02000000;
+	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
+}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tile: support ASLR fully
  2013-08-13 14:45   ` [PATCH v2] " Tony Lu
@ 2013-08-19 12:01     ` Jiri Kosina
  0 siblings, 0 replies; 5+ messages in thread
From: Jiri Kosina @ 2013-08-19 12:01 UTC (permalink / raw)
  To: Tony Lu; +Cc: linux-kernel, cmetcalf

On Tue, 13 Aug 2013, Tony Lu wrote:

> With this change, tile Linux now supports address-space layout
> randomization for shared objects, stack, heap and vdso.
> 
> Signed-off-by: Tony Lu <zlu@tilera.com>
> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
> ---
> v2: implement Jiri Kosina's suggestion to copy the math in
> mmap_rnd() for x86.

Feel free to add:

	Acked-by: Jiri Kosina <jkosina@suse.cz>

Thanks.

>  arch/tile/include/asm/elf.h |  4 ++++
>  arch/tile/mm/mmap.c         | 24 ++++++++++++++++++++++--
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
> index 31d854f..e1da88e 100644
> --- a/arch/tile/include/asm/elf.h
> +++ b/arch/tile/include/asm/elf.h
> @@ -137,6 +137,10 @@ do { \
>  	NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
>  } while (0)
>  
> +struct mm_struct;
> +extern unsigned long arch_randomize_brk(struct mm_struct *mm);
> +#define arch_randomize_brk arch_randomize_brk
> +
>  #ifdef CONFIG_COMPAT
>  
>  #define COMPAT_ELF_PLATFORM "tilegx-m32"
> diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
> index d67d91e..4b99344 100644
> --- a/arch/tile/mm/mmap.c
> +++ b/arch/tile/mm/mmap.c
> @@ -58,16 +58,36 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
>  #else
>  	int is_32bit = 0;
>  #endif
> +	unsigned long random_factor = 0UL;
> +
> +	/*
> +	 *  8 bits of randomness in 32bit mmaps, 24 address space bits
> +	 * 12 bits of randomness in 64bit mmaps, 28 address space bits
> +	 */
> +	if (current->flags & PF_RANDOMIZE) {
> +		if (is_32bit)
> +			random_factor = get_random_int() % (1<<8);
> +		else
> +			random_factor = get_random_int() % (1<<12);
> +		
> +		random_factor <<= PAGE_SHIFT;
> +	}
>  
>  	/*
>  	 * Use standard layout if the expected stack growth is unlimited
>  	 * or we are running native 64 bits.
>  	 */
> -	if (!is_32bit || rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
> -		mm->mmap_base = TASK_UNMAPPED_BASE;
> +	if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
> +		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
>  		mm->get_unmapped_area = arch_get_unmapped_area;
>  	} else {
>  		mm->mmap_base = mmap_base(mm);
>  		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
>  	}
>  }
> +
> +unsigned long arch_randomize_brk(struct mm_struct *mm)
> +{
> +	unsigned long range_end = mm->brk + 0x02000000;
> +	return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
> +}
> -- 
> 1.8.3.1
> 

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-08-19 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-09 19:45 [PATCH] tile: support ASLR fully Tony Lu
2013-08-10 16:55 ` Jiri Kosina
2013-08-10 17:23   ` richard -rw- weinberger
2013-08-13 14:45   ` [PATCH v2] " Tony Lu
2013-08-19 12:01     ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.