All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
@ 2022-01-31 20:17 Azat Khuzhin
  2022-01-31 21:30 ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Azat Khuzhin @ 2022-01-31 20:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Azat Khuzhin, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan, H . J . Lu

Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
and this breaks PIE binaries, since after this change data segment
became too nearby the stack:

Before 9630f0d60fec:

    $ strace -febrk /tmp/test-stack |& head
    brk(NULL)                               = 0x555555559000
    $ /tmp/test-stack
    bottom_of_stack = 0x7fffffffc5c0
    recursion depth: 1 (stack diff: 32)
    ...
    recursion depth: 7690 (stack diff: 8365664)
    Segmentation fault (core dumped)

After 9630f0d60fec:

    $ strace -ebrk /tmp/test-stack  |& head
    brk(NULL)                               = 0x7ffff7fff000

    $ /tmp/test-stack
    bottom_of_stack = 0x7fffffffc640
    recursion depth: 1 (stack diff: 32)
    ...
    recursion depth: 146 (stack diff: 157792)
    Segmentation fault (core dumped)

Found this during compiling with clang, that started to randomly
SIGSEGV when it eats some heap.

Reproducer:

    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>

    static int depth = 0;
    static void* bottom_of_stack;

    int inner()
    {
    	char buffer[1024];
    	ptrdiff_t diff;
    	int ret;

    	++depth;
    	diff = bottom_of_stack - __builtin_frame_address(0);

    	fprintf(stderr,
    		"recursion depth: %i (stack diff: %zu)\n",
    		depth, (size_t)diff);

    	for (size_t i = 0; i < 1024; ++i)
    		ret += buffer[i];

    	ret += inner();

    	return ret;
    }

    int main()
    {
    	for (size_t size = 0; size < 128<<20; size += 16<<10)
    		malloc(16<<10);

    	bottom_of_stack = __builtin_frame_address(0);
    	fprintf(stderr, "bottom_of_stack = %p\n", bottom_of_stack);
    	inner();
    }

Fixes: 9630f0d60fec ("fs/binfmt_elf: use PT_LOAD p_align values for static PIE")
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
Cc: Chris Kennelly <ckennelly@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sandeep Patil <sspatil@google.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: H.J. Lu <hjl.tools@gmail.com>
---
 fs/binfmt_elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 605017eb9349..9e11e6f13e83 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1117,7 +1117,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
 			 * without MAP_FIXED nor MAP_FIXED_NOREPLACE).
 			 */
 			alignment = maximum_alignment(elf_phdata, elf_ex->e_phnum);
-			if (alignment > ELF_MIN_ALIGN) {
+			if (interpreter || alignment > ELF_MIN_ALIGN) {
 				load_bias = ELF_ET_DYN_BASE;
 				if (current->flags & PF_RANDOMIZE)
 					load_bias += arch_mmap_rnd();
-- 
2.35.1


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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-01-31 20:17 [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries Azat Khuzhin
@ 2022-01-31 21:30 ` H.J. Lu
  2022-02-01  6:18   ` Azat Khuzhin
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2022-01-31 21:30 UTC (permalink / raw)
  To: Azat Khuzhin
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
>
> Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> and this breaks PIE binaries, since after this change data segment
> became too nearby the stack:
>
> Before 9630f0d60fec:
>
>     $ strace -febrk /tmp/test-stack |& head
>     brk(NULL)                               = 0x555555559000
>     $ /tmp/test-stack
>     bottom_of_stack = 0x7fffffffc5c0
>     recursion depth: 1 (stack diff: 32)
>     ...
>     recursion depth: 7690 (stack diff: 8365664)
>     Segmentation fault (core dumped)
>
> After 9630f0d60fec:
>
>     $ strace -ebrk /tmp/test-stack  |& head
>     brk(NULL)                               = 0x7ffff7fff000
>
>     $ /tmp/test-stack
>     bottom_of_stack = 0x7fffffffc640
>     recursion depth: 1 (stack diff: 32)
>     ...
>     recursion depth: 146 (stack diff: 157792)
>     Segmentation fault (core dumped)
>
> Found this during compiling with clang, that started to randomly
> SIGSEGV when it eats some heap.

How do I reproduce it on x86-64?

> Reproducer:
>
>     #include <stdio.h>
>     #include <stddef.h>
>     #include <stdlib.h>
>
>     static int depth = 0;
>     static void* bottom_of_stack;
>
>     int inner()
>     {
>         char buffer[1024];
>         ptrdiff_t diff;
>         int ret;
>
>         ++depth;
>         diff = bottom_of_stack - __builtin_frame_address(0);
>
>         fprintf(stderr,
>                 "recursion depth: %i (stack diff: %zu)\n",
>                 depth, (size_t)diff);
>
>         for (size_t i = 0; i < 1024; ++i)
>                 ret += buffer[i];
>
>         ret += inner();
>
>         return ret;
>     }
>
>     int main()
>     {
>         for (size_t size = 0; size < 128<<20; size += 16<<10)
>                 malloc(16<<10);
>
>         bottom_of_stack = __builtin_frame_address(0);
>         fprintf(stderr, "bottom_of_stack = %p\n", bottom_of_stack);
>         inner();
>     }
>
> Fixes: 9630f0d60fec ("fs/binfmt_elf: use PT_LOAD p_align values for static PIE")
> Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
> Cc: Chris Kennelly <ckennelly@google.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: Song Liu <songliubraving@fb.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Sandeep Patil <sspatil@google.com>
> Cc: Fangrui Song <maskray@google.com>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: H.J. Lu <hjl.tools@gmail.com>
> ---
>  fs/binfmt_elf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
> index 605017eb9349..9e11e6f13e83 100644
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -1117,7 +1117,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
>                          * without MAP_FIXED nor MAP_FIXED_NOREPLACE).
>                          */
>                         alignment = maximum_alignment(elf_phdata, elf_ex->e_phnum);
> -                       if (alignment > ELF_MIN_ALIGN) {
> +                       if (interpreter || alignment > ELF_MIN_ALIGN) {
>                                 load_bias = ELF_ET_DYN_BASE;
>                                 if (current->flags & PF_RANDOMIZE)
>                                         load_bias += arch_mmap_rnd();
> --
> 2.35.1
>


-- 
H.J.

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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-01-31 21:30 ` H.J. Lu
@ 2022-02-01  6:18   ` Azat Khuzhin
  2022-02-01 13:15     ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Azat Khuzhin @ 2022-02-01  6:18 UTC (permalink / raw)
  To: H.J. Lu
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote:
> On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> >
> > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> > and this breaks PIE binaries, since after this change data segment
> > became too nearby the stack:
> >
> > Before 9630f0d60fec:
> >
> >     $ strace -febrk /tmp/test-stack |& head
> >     brk(NULL)                               = 0x555555559000
> >     $ /tmp/test-stack
> >     bottom_of_stack = 0x7fffffffc5c0
> >     recursion depth: 1 (stack diff: 32)
> >     ...
> >     recursion depth: 7690 (stack diff: 8365664)
> >     Segmentation fault (core dumped)
> >
> > After 9630f0d60fec:
> >
> >     $ strace -ebrk /tmp/test-stack  |& head
> >     brk(NULL)                               = 0x7ffff7fff000
> >
> >     $ /tmp/test-stack
> >     bottom_of_stack = 0x7fffffffc640
> >     recursion depth: 1 (stack diff: 32)
> >     ...
> >     recursion depth: 146 (stack diff: 157792)
> >     Segmentation fault (core dumped)
> >
> > Found this during compiling with clang, that started to randomly
> > SIGSEGV when it eats some heap.
> 
> How do I reproduce it on x86-64?

It fails for me for pretty big C++ unit, so I don't have a simple
reproducer with clang, but the attached reproducer below should show the
problem.

> > Reproducer:
> >
> >     #include <stdio.h>
> >     #include <stddef.h>
> >     #include <stdlib.h>
> >
> >     static int depth = 0;
> >     static void* bottom_of_stack;
> >
> >     int inner()
> >     {
> >         char buffer[1024];
> >         ptrdiff_t diff;
> >         int ret;
> >
> >         ++depth;
> >         diff = bottom_of_stack - __builtin_frame_address(0);
> >
> >         fprintf(stderr,
> >                 "recursion depth: %i (stack diff: %zu)\n",
> >                 depth, (size_t)diff);
> >
> >         for (size_t i = 0; i < 1024; ++i)
> >                 ret += buffer[i];
> >
> >         ret += inner();
> >
> >         return ret;
> >     }
> >
> >     int main()
> >     {
> >         for (size_t size = 0; size < 128<<20; size += 16<<10)
> >                 malloc(16<<10);
> >
> >         bottom_of_stack = __builtin_frame_address(0);
> >         fprintf(stderr, "bottom_of_stack = %p\n", bottom_of_stack);
> >         inner();
> >     }

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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-02-01  6:18   ` Azat Khuzhin
@ 2022-02-01 13:15     ` H.J. Lu
  2022-02-01 13:28       ` Azat Khuzhin
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2022-02-01 13:15 UTC (permalink / raw)
  To: Azat Khuzhin
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Mon, Jan 31, 2022 at 10:18 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
>
> On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote:
> > On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > >
> > > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> > > and this breaks PIE binaries, since after this change data segment
> > > became too nearby the stack:
> > >
> > > Before 9630f0d60fec:
> > >
> > >     $ strace -febrk /tmp/test-stack |& head
> > >     brk(NULL)                               = 0x555555559000
> > >     $ /tmp/test-stack
> > >     bottom_of_stack = 0x7fffffffc5c0
> > >     recursion depth: 1 (stack diff: 32)
> > >     ...
> > >     recursion depth: 7690 (stack diff: 8365664)
> > >     Segmentation fault (core dumped)
> > >
> > > After 9630f0d60fec:
> > >
> > >     $ strace -ebrk /tmp/test-stack  |& head
> > >     brk(NULL)                               = 0x7ffff7fff000
> > >
> > >     $ /tmp/test-stack
> > >     bottom_of_stack = 0x7fffffffc640
> > >     recursion depth: 1 (stack diff: 32)
> > >     ...
> > >     recursion depth: 146 (stack diff: 157792)
> > >     Segmentation fault (core dumped)
> > >
> > > Found this during compiling with clang, that started to randomly
> > > SIGSEGV when it eats some heap.
> >
> > How do I reproduce it on x86-64?
>
> It fails for me for pretty big C++ unit, so I don't have a simple
> reproducer with clang, but the attached reproducer below should show the
> problem.

The reproducer doesn't fail for me under 5.17-rc2 on Fedora 35/x86-64
with 32GB RAM.  Did you turn off PF_RANDOMIZE?

> > > Reproducer:
> > >
> > >     #include <stdio.h>
> > >     #include <stddef.h>
> > >     #include <stdlib.h>
> > >
> > >     static int depth = 0;
> > >     static void* bottom_of_stack;
> > >
> > >     int inner()
> > >     {
> > >         char buffer[1024];
> > >         ptrdiff_t diff;
> > >         int ret;
> > >
> > >         ++depth;
> > >         diff = bottom_of_stack - __builtin_frame_address(0);
> > >
> > >         fprintf(stderr,
> > >                 "recursion depth: %i (stack diff: %zu)\n",
> > >                 depth, (size_t)diff);
> > >
> > >         for (size_t i = 0; i < 1024; ++i)
> > >                 ret += buffer[i];
> > >
> > >         ret += inner();
> > >
> > >         return ret;
> > >     }
> > >
> > >     int main()
> > >     {
> > >         for (size_t size = 0; size < 128<<20; size += 16<<10)
> > >                 malloc(16<<10);
> > >
> > >         bottom_of_stack = __builtin_frame_address(0);
> > >         fprintf(stderr, "bottom_of_stack = %p\n", bottom_of_stack);
> > >         inner();
> > >     }



-- 
H.J.

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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-02-01 13:15     ` H.J. Lu
@ 2022-02-01 13:28       ` Azat Khuzhin
  2022-02-01 13:39         ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Azat Khuzhin @ 2022-02-01 13:28 UTC (permalink / raw)
  To: H.J. Lu
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Tue, Feb 01, 2022 at 05:15:38AM -0800, H.J. Lu wrote:
> On Mon, Jan 31, 2022 at 10:18 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> >
> > On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote:
> > > On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > > >
> > > > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> > > > and this breaks PIE binaries, since after this change data segment
> > > > became too nearby the stack:
> > > >
> > > > Before 9630f0d60fec:
> > > >
> > > >     $ strace -febrk /tmp/test-stack |& head
> > > >     brk(NULL)                               = 0x555555559000
> > > >     $ /tmp/test-stack
> > > >     bottom_of_stack = 0x7fffffffc5c0
> > > >     recursion depth: 1 (stack diff: 32)
> > > >     ...
> > > >     recursion depth: 7690 (stack diff: 8365664)
> > > >     Segmentation fault (core dumped)
> > > >
> > > > After 9630f0d60fec:
> > > >
> > > >     $ strace -ebrk /tmp/test-stack  |& head
> > > >     brk(NULL)                               = 0x7ffff7fff000
> > > >
> > > >     $ /tmp/test-stack
> > > >     bottom_of_stack = 0x7fffffffc640
> > > >     recursion depth: 1 (stack diff: 32)
> > > >     ...
> > > >     recursion depth: 146 (stack diff: 157792)
> > > >     Segmentation fault (core dumped)
> > > >
> > > > Found this during compiling with clang, that started to randomly
> > > > SIGSEGV when it eats some heap.
> > >
> > > How do I reproduce it on x86-64?
> >
> > It fails for me for pretty big C++ unit, so I don't have a simple
> > reproducer with clang, but the attached reproducer below should show the
> > problem.
> 
> The reproducer doesn't fail for me under 5.17-rc2 on Fedora 35/x86-64
> with 32GB RAM.  Did you turn off PF_RANDOMIZE?

Oh, yep, forgot to mention that I have kernel.randomize_va_space=0.

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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-02-01 13:28       ` Azat Khuzhin
@ 2022-02-01 13:39         ` H.J. Lu
  2022-02-03 16:42           ` Azat Khuzhin
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2022-02-01 13:39 UTC (permalink / raw)
  To: Azat Khuzhin
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Tue, Feb 1, 2022 at 5:28 AM Azat Khuzhin <a3at.mail@gmail.com> wrote:
>
> On Tue, Feb 01, 2022 at 05:15:38AM -0800, H.J. Lu wrote:
> > On Mon, Jan 31, 2022 at 10:18 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > >
> > > On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote:
> > > > On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > > > >
> > > > > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> > > > > and this breaks PIE binaries, since after this change data segment
> > > > > became too nearby the stack:
> > > > >
> > > > > Before 9630f0d60fec:
> > > > >
> > > > >     $ strace -febrk /tmp/test-stack |& head
> > > > >     brk(NULL)                               = 0x555555559000
> > > > >     $ /tmp/test-stack
> > > > >     bottom_of_stack = 0x7fffffffc5c0
> > > > >     recursion depth: 1 (stack diff: 32)
> > > > >     ...
> > > > >     recursion depth: 7690 (stack diff: 8365664)
> > > > >     Segmentation fault (core dumped)
> > > > >
> > > > > After 9630f0d60fec:
> > > > >
> > > > >     $ strace -ebrk /tmp/test-stack  |& head
> > > > >     brk(NULL)                               = 0x7ffff7fff000
> > > > >
> > > > >     $ /tmp/test-stack
> > > > >     bottom_of_stack = 0x7fffffffc640
> > > > >     recursion depth: 1 (stack diff: 32)
> > > > >     ...
> > > > >     recursion depth: 146 (stack diff: 157792)
> > > > >     Segmentation fault (core dumped)
> > > > >
> > > > > Found this during compiling with clang, that started to randomly
> > > > > SIGSEGV when it eats some heap.
> > > >
> > > > How do I reproduce it on x86-64?
> > >
> > > It fails for me for pretty big C++ unit, so I don't have a simple
> > > reproducer with clang, but the attached reproducer below should show the
> > > problem.
> >
> > The reproducer doesn't fail for me under 5.17-rc2 on Fedora 35/x86-64
> > with 32GB RAM.  Did you turn off PF_RANDOMIZE?
>
> Oh, yep, forgot to mention that I have kernel.randomize_va_space=0.

PIE with interpreter and PIE with alignment > ELF_MIN_ALIGN
should always be loaded from ELF_ET_DYN_BASE.  Otherwise,
either PIE is loaded at an address which is too low or isn't properly
aligned.

-- 
H.J.

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

* Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
  2022-02-01 13:39         ` H.J. Lu
@ 2022-02-03 16:42           ` Azat Khuzhin
  0 siblings, 0 replies; 7+ messages in thread
From: Azat Khuzhin @ 2022-02-03 16:42 UTC (permalink / raw)
  To: H.J. Lu
  Cc: LKML, Chris Kennelly, Al Viro, Alexey Dobriyan, Song Liu,
	David Rientjes, Ian Rogers, Hugh Dickins, Suren Baghdasaryan,
	Sandeep Patil, Fangrui Song, Nick Desaulniers,
	Kirill A . Shutemov, Mike Kravetz, Shuah Khan

On Tue, Feb 01, 2022 at 05:39:57AM -0800, H.J. Lu wrote:
> On Tue, Feb 1, 2022 at 5:28 AM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> >
> > On Tue, Feb 01, 2022 at 05:15:38AM -0800, H.J. Lu wrote:
> > > On Mon, Jan 31, 2022 at 10:18 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > > >
> > > > On Mon, Jan 31, 2022 at 01:30:38PM -0800, H.J. Lu wrote:
> > > > > On Mon, Jan 31, 2022 at 12:17 PM Azat Khuzhin <a3at.mail@gmail.com> wrote:
> > > > > >
> > > > > > Since 9630f0d60fec ELF_ET_DYN_BASE is not used as a load_bias anymore
> > > > > > and this breaks PIE binaries, since after this change data segment
> > > > > > became too nearby the stack:
> > > > > >
> > > > > > Before 9630f0d60fec:
> > > > > >
> > > > > >     $ strace -febrk /tmp/test-stack |& head
> > > > > >     brk(NULL)                               = 0x555555559000
> > > > > >     $ /tmp/test-stack
> > > > > >     bottom_of_stack = 0x7fffffffc5c0
> > > > > >     recursion depth: 1 (stack diff: 32)
> > > > > >     ...
> > > > > >     recursion depth: 7690 (stack diff: 8365664)
> > > > > >     Segmentation fault (core dumped)
> > > > > >
> > > > > > After 9630f0d60fec:
> > > > > >
> > > > > >     $ strace -ebrk /tmp/test-stack  |& head
> > > > > >     brk(NULL)                               = 0x7ffff7fff000
> > > > > >
> > > > > >     $ /tmp/test-stack
> > > > > >     bottom_of_stack = 0x7fffffffc640
> > > > > >     recursion depth: 1 (stack diff: 32)
> > > > > >     ...
> > > > > >     recursion depth: 146 (stack diff: 157792)
> > > > > >     Segmentation fault (core dumped)
> > > > > >
> > > > > > Found this during compiling with clang, that started to randomly
> > > > > > SIGSEGV when it eats some heap.
> > > > >
> > > > > How do I reproduce it on x86-64?
> > > >
> > > > It fails for me for pretty big C++ unit, so I don't have a simple
> > > > reproducer with clang, but the attached reproducer below should show the
> > > > problem.
> > >
> > > The reproducer doesn't fail for me under 5.17-rc2 on Fedora 35/x86-64
> > > with 32GB RAM.  Did you turn off PF_RANDOMIZE?
> >
> > Oh, yep, forgot to mention that I have kernel.randomize_va_space=0.
> 
> PIE with interpreter and PIE with alignment > ELF_MIN_ALIGN
> should always be loaded from ELF_ET_DYN_BASE.  Otherwise,
> either PIE is loaded at an address which is too low or isn't properly
> aligned.

So, this is what this patch does, right?
Any news on this patch?

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

end of thread, other threads:[~2022-02-03 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 20:17 [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries Azat Khuzhin
2022-01-31 21:30 ` H.J. Lu
2022-02-01  6:18   ` Azat Khuzhin
2022-02-01 13:15     ` H.J. Lu
2022-02-01 13:28       ` Azat Khuzhin
2022-02-01 13:39         ` H.J. Lu
2022-02-03 16:42           ` Azat Khuzhin

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.