LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] elf: fix "start_code" evaluation
Date: Thu, 23 May 2019 22:35:05 +0300	[thread overview]
Message-ID: <20190523193505.GA8475@avx2> (raw)
In-Reply-To: <20190523114417.f99d781754ed22950115c64a@linux-foundation.org>

On Thu, May 23, 2019 at 11:44:17AM -0700, Andrew Morton wrote:
> On Thu, 23 May 2019 20:57:36 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > Only executable ELF program headers should change ->start_code.
> > 
> > ...
> >
> > --- a/fs/binfmt_elf.c
> > +++ b/fs/binfmt_elf.c
> > @@ -1026,7 +1026,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
> >  			}
> >  		}
> >  		k = elf_ppnt->p_vaddr;
> > -		if (k < start_code)
> > +		if ((elf_ppnt->p_flags & PF_X) && k < start_code)
> >  			start_code = k;
> >  		if (start_data < k)
> >  			start_data = k;
> 
> What problem does this solve?

It is a bug. Look at the ->end_code update:

	if ((elf_ppnt->p_flags & PF_X) && end_code < k)
		end_code = k;

> How does it alter runtime behaviour?

It makes "VmExe" and "VmLib" accounting more accurate for common case.

> How do we know it won't break anything?

We don't. Some distros are unaffected because they ship binaries with
first PT_LOAD segment being executable (Debian 8). Some don't.

Regardless, these fields are lies: ELF binary can have multiple disjoint
PT_LOAD segments, but all those ->start and ->end fields assume everything
is mapped together.

Hopefully nobody actually uses them for anything serious.

      reply	other threads:[~2019-05-23 19:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 17:57 Alexey Dobriyan
2019-05-23 18:44 ` Andrew Morton
2019-05-23 19:35   ` Alexey Dobriyan [this message]

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=20190523193505.GA8475@avx2 \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] elf: fix "start_code" evaluation' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).