* [PATCH] fix mmap random address range on x86 (try2)
@ 2011-02-28 14:53 Ludwig Nussel
2011-02-28 16:42 ` Randy Dunlap
0 siblings, 1 reply; 3+ messages in thread
From: Ludwig Nussel @ 2011-02-28 14:53 UTC (permalink / raw)
To: linux-kernel
Cc: Ludwig Nussel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE...
On x86 casting the unsigned int result of get_random_int() to long
may result in a negative value. On x86 the range of mmap_rnd()
therefore was -255 to 255. The 32bit mode on x86_64 used 0 to 255 as
intended.
The bug was introduced by commit 675a081 in January 2008.
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
arch/x86/mm/mmap.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index 1dab519..f927429 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -87,9 +87,9 @@ static unsigned long mmap_rnd(void)
*/
if (current->flags & PF_RANDOMIZE) {
if (mmap_is_ia32())
- rnd = (long)get_random_int() % (1<<8);
+ rnd = get_random_int() % (1<<8);
else
- rnd = (long)(get_random_int() % (1<<28));
+ rnd = get_random_int() % (1<<28);
}
return rnd << PAGE_SHIFT;
}
--
1.7.3.4
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] fix mmap random address range on x86 (try2)
2011-02-28 14:53 [PATCH] fix mmap random address range on x86 (try2) Ludwig Nussel
@ 2011-02-28 16:42 ` Randy Dunlap
2011-03-01 8:21 ` Ludwig Nussel
0 siblings, 1 reply; 3+ messages in thread
From: Randy Dunlap @ 2011-02-28 16:42 UTC (permalink / raw)
To: Ludwig Nussel
Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE...
On Mon, 28 Feb 2011 15:53:03 +0100 Ludwig Nussel wrote:
> On x86 casting the unsigned int result of get_random_int() to long
> may result in a negative value. On x86 the range of mmap_rnd()
> therefore was -255 to 255. The 32bit mode on x86_64 used 0 to 255 as
> intended.
>
> The bug was introduced by commit 675a081 in January 2008.
>
> Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
> ---
> arch/x86/mm/mmap.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
> index 1dab519..f927429 100644
> --- a/arch/x86/mm/mmap.c
> +++ b/arch/x86/mm/mmap.c
> @@ -87,9 +87,9 @@ static unsigned long mmap_rnd(void)
> */
> if (current->flags & PF_RANDOMIZE) {
> if (mmap_is_ia32())
> - rnd = (long)get_random_int() % (1<<8);
> + rnd = get_random_int() % (1<<8);
> else
> - rnd = (long)(get_random_int() % (1<<28));
> + rnd = get_random_int() % (1<<28);
> }
> return rnd << PAGE_SHIFT;
> }
> --
Is there a test case for this?
Can it be tested/checked/observed?
thanks,
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] fix mmap random address range on x86 (try2)
2011-02-28 16:42 ` Randy Dunlap
@ 2011-03-01 8:21 ` Ludwig Nussel
0 siblings, 0 replies; 3+ messages in thread
From: Ludwig Nussel @ 2011-03-01 8:21 UTC (permalink / raw)
To: Randy Dunlap
Cc: linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE...
[-- Attachment #1: Type: Text/Plain, Size: 1635 bytes --]
Randy Dunlap wrote:
> On Mon, 28 Feb 2011 15:53:03 +0100 Ludwig Nussel wrote:
> > On x86 casting the unsigned int result of get_random_int() to long
> > may result in a negative value. On x86 the range of mmap_rnd()
> > therefore was -255 to 255. The 32bit mode on x86_64 used 0 to 255 as
> > intended.
> >
> > The bug was introduced by commit 675a081 in January 2008.
> >
> > Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
> > ---
> > arch/x86/mm/mmap.c | 4 ++--
> > 1 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
> > index 1dab519..f927429 100644
> > --- a/arch/x86/mm/mmap.c
> > +++ b/arch/x86/mm/mmap.c
> > @@ -87,9 +87,9 @@ static unsigned long mmap_rnd(void)
> > */
> > if (current->flags & PF_RANDOMIZE) {
> > if (mmap_is_ia32())
> > - rnd = (long)get_random_int() % (1<<8);
> > + rnd = get_random_int() % (1<<8);
> > else
> > - rnd = (long)(get_random_int() % (1<<28));
> > + rnd = get_random_int() % (1<<28);
> > }
> > return rnd << PAGE_SHIFT;
> > }
>
> Is there a test case for this?
> Can it be tested/checked/observed?
Sure. The attached program prints the address of the main function
to stdout. Compile it for i586, run it several times in a loop and
count the number of distinct addresses.
x86_64:
$ gcc -g -O2 -Wall -fpie -pie -m32 -o mainaddr mainaddr.c && for ((i=0;i<5000;++i)); do ./mainaddr; done | sort -u | wc -l
256
On native i586 without the patch the result is 511
cu
Ludwig
--
(o_ Ludwig Nussel
//\
V_/_ http://www.suse.de/
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)
[-- Attachment #2: mainaddr.c --]
[-- Type: text/x-csrc, Size: 108 bytes --]
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%lu\n", (unsigned long)main);
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-01 8:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 14:53 [PATCH] fix mmap random address range on x86 (try2) Ludwig Nussel
2011-02-28 16:42 ` Randy Dunlap
2011-03-01 8:21 ` Ludwig Nussel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®