LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH] fs, elf: Make sure to page align bss in load_elf_library
@ 2018-07-05 14:55 osalvador
  2018-07-05 15:44 ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: osalvador @ 2018-07-05 14:55 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-mm, linux-kernel, mhocko, penguin-kernel, keescook,
	nicolas.pitre, Oscar Salvador

From: Oscar Salvador <osalvador@suse.de>

The current code does not make sure to page align bss before calling
vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate()
due to the requested lenght not being correctly aligned.

Let us make sure to align it properly.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Reported-by: syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com
---
 fs/binfmt_elf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 0ac456b52bdd..816cc921cf36 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1259,9 +1259,8 @@ static int load_elf_library(struct file *file)
 		goto out_free_ph;
 	}
 
-	len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
-			    ELF_MIN_ALIGN - 1);
-	bss = eppnt->p_memsz + eppnt->p_vaddr;
+	len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
+	bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
 	if (bss > len) {
 		error = vm_brk(len, bss - len);
 		if (error)
-- 
2.13.6


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

* Re: [PATCH] fs, elf: Make sure to page align bss in load_elf_library
  2018-07-05 14:55 [PATCH] fs, elf: Make sure to page align bss in load_elf_library osalvador
@ 2018-07-05 15:44 ` Kees Cook
  2018-07-06  7:13   ` Oscar Salvador
  2018-07-06 22:55   ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Kees Cook @ 2018-07-05 15:44 UTC (permalink / raw)
  To: osalvador
  Cc: linux-fsdevel, Linux-MM, LKML, Michal Hocko, Tetsuo Handa,
	Nicolas Pitre, Oscar Salvador

On Thu, Jul 5, 2018 at 7:55 AM,  <osalvador@techadventures.net> wrote:
> From: Oscar Salvador <osalvador@suse.de>
>
> The current code does not make sure to page align bss before calling
> vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate()
> due to the requested lenght not being correctly aligned.
>
> Let us make sure to align it properly.
>
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
> Reported-by: syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com

Wow. CONFIG_USELIB? I'm surprised distros are still using this. 32-bit
only, and libc5 and earlier only.

Regardless, this appears to match the current bss alignment logic in
the main elf loader, so:

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  fs/binfmt_elf.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
> index 0ac456b52bdd..816cc921cf36 100644
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -1259,9 +1259,8 @@ static int load_elf_library(struct file *file)
>                 goto out_free_ph;
>         }
>
> -       len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
> -                           ELF_MIN_ALIGN - 1);
> -       bss = eppnt->p_memsz + eppnt->p_vaddr;
> +       len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
> +       bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
>         if (bss > len) {
>                 error = vm_brk(len, bss - len);
>                 if (error)
> --
> 2.13.6
>



-- 
Kees Cook
Pixel Security

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

* Re: [PATCH] fs, elf: Make sure to page align bss in load_elf_library
  2018-07-05 15:44 ` Kees Cook
@ 2018-07-06  7:13   ` Oscar Salvador
  2018-07-06 19:23     ` Kees Cook
  2018-07-06 22:55   ` Andrew Morton
  1 sibling, 1 reply; 5+ messages in thread
From: Oscar Salvador @ 2018-07-06  7:13 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-fsdevel, Linux-MM, LKML, Michal Hocko, Tetsuo Handa,
	Nicolas Pitre, Oscar Salvador, Andrew Morton

On Thu, Jul 05, 2018 at 08:44:18AM -0700, Kees Cook wrote:
> On Thu, Jul 5, 2018 at 7:55 AM,  <osalvador@techadventures.net> wrote:
> > From: Oscar Salvador <osalvador@suse.de>
> >
> > The current code does not make sure to page align bss before calling
> > vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate()
> > due to the requested lenght not being correctly aligned.
> >
> > Let us make sure to align it properly.
> >
> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> > Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
> > Reported-by: syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com
> 
> Wow. CONFIG_USELIB? I'm surprised distros are still using this. 32-bit
> only, and libc5 and earlier only.
> 
> Regardless, this appears to match the current bss alignment logic in
> the main elf loader, so:
> 
> Acked-by: Kees Cook <keescook@chromium.org>
> 
> -Kees
> 
> > ---
> >  fs/binfmt_elf.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
> > index 0ac456b52bdd..816cc921cf36 100644
> > --- a/fs/binfmt_elf.c
> > +++ b/fs/binfmt_elf.c
> > @@ -1259,9 +1259,8 @@ static int load_elf_library(struct file *file)
> >                 goto out_free_ph;
> >         }
> >
> > -       len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
> > -                           ELF_MIN_ALIGN - 1);
> > -       bss = eppnt->p_memsz + eppnt->p_vaddr;
> > +       len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
> > +       bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
> >         if (bss > len) {
> >                 error = vm_brk(len, bss - len);
> >                 if (error)
> > --
> > 2.13.6
> >
CC Andrew

Hi Andrew,

in case this patch gets accepted, does it have to go through your tree?
Or is it for someone else to take it?

Thanks
-- 
Oscar Salvador
SUSE L3

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

* Re: [PATCH] fs, elf: Make sure to page align bss in load_elf_library
  2018-07-06  7:13   ` Oscar Salvador
@ 2018-07-06 19:23     ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2018-07-06 19:23 UTC (permalink / raw)
  To: Oscar Salvador
  Cc: linux-fsdevel, Linux-MM, LKML, Michal Hocko, Tetsuo Handa,
	Nicolas Pitre, Oscar Salvador, Andrew Morton

On Fri, Jul 6, 2018 at 12:13 AM, Oscar Salvador
<osalvador@techadventures.net> wrote:
> On Thu, Jul 05, 2018 at 08:44:18AM -0700, Kees Cook wrote:
>> On Thu, Jul 5, 2018 at 7:55 AM,  <osalvador@techadventures.net> wrote:
>> > From: Oscar Salvador <osalvador@suse.de>
>> >
>> > The current code does not make sure to page align bss before calling
>> > vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate()
>> > due to the requested lenght not being correctly aligned.
>> >
>> > Let us make sure to align it properly.
>> >
>> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
>> > Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
>> > Reported-by: syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com
>>
>> Wow. CONFIG_USELIB? I'm surprised distros are still using this. 32-bit
>> only, and libc5 and earlier only.
>>
>> Regardless, this appears to match the current bss alignment logic in
>> the main elf loader, so:
>>
>> Acked-by: Kees Cook <keescook@chromium.org>
>>
>> -Kees
>>
>> > ---
>> >  fs/binfmt_elf.c | 5 ++---
>> >  1 file changed, 2 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
>> > index 0ac456b52bdd..816cc921cf36 100644
>> > --- a/fs/binfmt_elf.c
>> > +++ b/fs/binfmt_elf.c
>> > @@ -1259,9 +1259,8 @@ static int load_elf_library(struct file *file)
>> >                 goto out_free_ph;
>> >         }
>> >
>> > -       len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
>> > -                           ELF_MIN_ALIGN - 1);
>> > -       bss = eppnt->p_memsz + eppnt->p_vaddr;
>> > +       len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
>> > +       bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
>> >         if (bss > len) {
>> >                 error = vm_brk(len, bss - len);
>> >                 if (error)
>> > --
>> > 2.13.6
>> >
> CC Andrew
>
> Hi Andrew,
>
> in case this patch gets accepted, does it have to go through your tree?
> Or is it for someone else to take it?

(FWIW, binfmt_elf changes have traditionally gone through -mm, yes.)

-Kees

-- 
Kees Cook
Pixel Security

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

* Re: [PATCH] fs, elf: Make sure to page align bss in load_elf_library
  2018-07-05 15:44 ` Kees Cook
  2018-07-06  7:13   ` Oscar Salvador
@ 2018-07-06 22:55   ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2018-07-06 22:55 UTC (permalink / raw)
  To: Kees Cook
  Cc: osalvador, linux-fsdevel, Linux-MM, LKML, Michal Hocko,
	Tetsuo Handa, Nicolas Pitre, Oscar Salvador

On Thu, 5 Jul 2018 08:44:18 -0700 Kees Cook <keescook@chromium.org> wrote:

> On Thu, Jul 5, 2018 at 7:55 AM,  <osalvador@techadventures.net> wrote:
> > From: Oscar Salvador <osalvador@suse.de>
> >
> > The current code does not make sure to page align bss before calling
> > vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate()
> > due to the requested lenght not being correctly aligned.
> >
> > Let us make sure to align it properly.
> >
> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> > Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
> > Reported-by: syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com
> 
> Wow. CONFIG_USELIB? I'm surprised distros are still using this. 32-bit
> only, and libc5 and earlier only.

Presumably doesn't happen much, but people who *are* enabling this will
want the fix, so I added the cc:stable.


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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-05 14:55 [PATCH] fs, elf: Make sure to page align bss in load_elf_library osalvador
2018-07-05 15:44 ` Kees Cook
2018-07-06  7:13   ` Oscar Salvador
2018-07-06 19:23     ` Kees Cook
2018-07-06 22:55   ` Andrew Morton

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox