* [PATCH] elf: fix "start_code" evaluation
@ 2019-05-23 17:57 Alexey Dobriyan
2019-05-23 18:44 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2019-05-23 17:57 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
Only executable ELF program headers should change ->start_code.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
fs/binfmt_elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- 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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf: fix "start_code" evaluation
2019-05-23 17:57 [PATCH] elf: fix "start_code" evaluation Alexey Dobriyan
@ 2019-05-23 18:44 ` Andrew Morton
2019-05-23 19:35 ` Alexey Dobriyan
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2019-05-23 18:44 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel
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? How does it alter runtime behaviour?
How do we know it won't break anything?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf: fix "start_code" evaluation
2019-05-23 18:44 ` Andrew Morton
@ 2019-05-23 19:35 ` Alexey Dobriyan
0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2019-05-23 19:35 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-23 19:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 17:57 [PATCH] elf: fix "start_code" evaluation Alexey Dobriyan
2019-05-23 18:44 ` Andrew Morton
2019-05-23 19:35 ` Alexey Dobriyan
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.