mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Azat Khuzhin <a3at.mail@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Chris Kennelly <ckennelly@google.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Song Liu <songliubraving@fb.com>,
	David Rientjes <rientjes@google.com>,
	Ian Rogers <irogers@google.com>, Hugh Dickins <hughd@google.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Sandeep Patil <sspatil@google.com>,
	Fangrui Song <maskray@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Shuah Khan <shuah@kernel.org>
Subject: Re: [PATCH] fs/binfmt_elf: use ELF_ET_DYN_BASE for PIE (ET_DYN with INTERP) binaries
Date: Tue, 1 Feb 2022 05:15:38 -0800	[thread overview]
Message-ID: <CAMe9rOptn2vpY90yY3HuGmmMdj4Hpaba2PRhp4d033XBDgL_5w@mail.gmail.com> (raw)
In-Reply-To: <20220201061832.yatgwglxvi7ho4yr@carbon.azat>

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.

  reply	other threads:[~2022-02-01 13:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 20:17 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 [this message]
2022-02-01 13:28       ` Azat Khuzhin
2022-02-01 13:39         ` H.J. Lu
2022-02-03 16:42           ` Azat Khuzhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOptn2vpY90yY3HuGmmMdj4Hpaba2PRhp4d033XBDgL_5w@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=a3at.mail@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=ckennelly@google.com \
    --cc=hughd@google.com \
    --cc=irogers@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maskray@google.com \
    --cc=mike.kravetz@oracle.com \
    --cc=ndesaulniers@google.com \
    --cc=rientjes@google.com \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=sspatil@google.com \
    --cc=surenb@google.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®