* [PATCH] build-id: require program headers to be right after ELF header
@ 2024-06-21 15:05 Alexey Dobriyan
2024-06-21 17:07 ` Andrew Morton
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2024-06-21 15:05 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, Jiri Olsa
ELF spec doesn't require program header to be placed right after
ELF header, but build-id code very much assumes such placement:
find_get_page(vma->vm_file->f_mapping, 0);
and later check against PAGE_SIZE.
Returns errors for now until someone rewrites build-id parser
to be more correct.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
lib/buildid.c | 6 ++++++
1 file changed, 6 insertions(+)
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -73,6 +73,9 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
Elf32_Phdr *phdr;
int i;
+ if (ehdr->e_phoff != sizeof(Elf32_Ehdr)) {
+ return -EINVAL;
+ }
/* only supports phdr that fits in one page */
if (ehdr->e_phnum >
(PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
@@ -98,6 +101,9 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
Elf64_Phdr *phdr;
int i;
+ if (ehdr->e_phoff != sizeof(Elf64_Ehdr)) {
+ return -EINVAL;
+ }
/* only supports phdr that fits in one page */
if (ehdr->e_phnum >
(PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] build-id: require program headers to be right after ELF header
2024-06-21 15:05 [PATCH] build-id: require program headers to be right after ELF header Alexey Dobriyan
@ 2024-06-21 17:07 ` Andrew Morton
2024-06-21 18:32 ` Alexey Dobriyan
2024-06-21 18:39 ` [PATCH v2] " Alexey Dobriyan
0 siblings, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2024-06-21 17:07 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel, Jiri Olsa
On Fri, 21 Jun 2024 18:05:50 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> ELF spec doesn't require program header to be placed right after
> ELF header, but build-id code very much assumes such placement:
>
> find_get_page(vma->vm_file->f_mapping, 0);
>
> and later check against PAGE_SIZE.
>
> Returns errors for now until someone rewrites build-id parser
> to be more correct.
>
> ...
>
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -73,6 +73,9 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
> Elf32_Phdr *phdr;
> int i;
>
> + if (ehdr->e_phoff != sizeof(Elf32_Ehdr)) {
> + return -EINVAL;
> + }
> /* only supports phdr that fits in one page */
> if (ehdr->e_phnum >
> (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
> @@ -98,6 +101,9 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
> Elf64_Phdr *phdr;
> int i;
>
> + if (ehdr->e_phoff != sizeof(Elf64_Ehdr)) {
> + return -EINVAL;
> + }
> /* only supports phdr that fits in one page */
> if (ehdr->e_phnum >
> (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
Well can we get comments in here eplaining the shortcoming? That way
we're more likely to get a volunteer.
And please drop the braces?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] build-id: require program headers to be right after ELF header
2024-06-21 17:07 ` Andrew Morton
@ 2024-06-21 18:32 ` Alexey Dobriyan
2024-06-21 18:39 ` [PATCH v2] " Alexey Dobriyan
1 sibling, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2024-06-21 18:32 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Jiri Olsa
On Fri, Jun 21, 2024 at 10:07:52AM -0700, Andrew Morton wrote:
> On Fri, 21 Jun 2024 18:05:50 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> > ELF spec doesn't require program header to be placed right after
> > ELF header, but build-id code very much assumes such placement:
> >
> > find_get_page(vma->vm_file->f_mapping, 0);
> >
> > and later check against PAGE_SIZE.
> >
> > Returns errors for now until someone rewrites build-id parser
> > to be more correct.
> >
> > ...
> >
> > --- a/lib/buildid.c
> > +++ b/lib/buildid.c
> > @@ -73,6 +73,9 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
> > Elf32_Phdr *phdr;
> > int i;
> >
> > + if (ehdr->e_phoff != sizeof(Elf32_Ehdr)) {
> > + return -EINVAL;
> > + }
> > /* only supports phdr that fits in one page */
> > if (ehdr->e_phnum >
> > (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
> > @@ -98,6 +101,9 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
> > Elf64_Phdr *phdr;
> > int i;
> >
> > + if (ehdr->e_phoff != sizeof(Elf64_Ehdr)) {
> > + return -EINVAL;
> > + }
> > /* only supports phdr that fits in one page */
> > if (ehdr->e_phnum >
> > (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
>
> Well can we get comments in here eplaining the shortcoming? That way
> we're more likely to get a volunteer.
Sure.
> And please drop the braces?
Bracers are good. It took hundred years to drop -Wdeclaration-after-statement,
I hope to see mandatory bracers by 2050.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] build-id: require program headers to be right after ELF header
2024-06-21 17:07 ` Andrew Morton
2024-06-21 18:32 ` Alexey Dobriyan
@ 2024-06-21 18:39 ` Alexey Dobriyan
2024-06-24 11:23 ` Jiri Olsa
1 sibling, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2024-06-21 18:39 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Jiri Olsa
Neither ELF spec not ELF loader require program header to be placed
right after ELF header, but build-id code very much assumes such placement:
See
find_get_page(vma->vm_file->f_mapping, 0);
line and checks against PAGE_SIZE.
Returns errors for now until someone rewrites build-id parser
to be more inline with load_elf_binary().
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
lib/buildid.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -73,6 +73,13 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
Elf32_Phdr *phdr;
int i;
+ /*
+ * FIXME
+ * Neither ELF spec nor ELF loader require that program headers
+ * start immediately after ELF header.
+ */
+ if (ehdr->e_phoff != sizeof(Elf32_Ehdr))
+ return -EINVAL;
/* only supports phdr that fits in one page */
if (ehdr->e_phnum >
(PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
@@ -98,6 +105,13 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
Elf64_Phdr *phdr;
int i;
+ /*
+ * FIXME
+ * Neither ELF spec nor ELF loader require that program headers
+ * start immediately after ELF header.
+ */
+ if (ehdr->e_phoff != sizeof(Elf64_Ehdr))
+ return -EINVAL;
/* only supports phdr that fits in one page */
if (ehdr->e_phnum >
(PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] build-id: require program headers to be right after ELF header
2024-06-21 18:39 ` [PATCH v2] " Alexey Dobriyan
@ 2024-06-24 11:23 ` Jiri Olsa
2024-06-25 3:28 ` Andrii Nakryiko
0 siblings, 1 reply; 6+ messages in thread
From: Jiri Olsa @ 2024-06-24 11:23 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: Andrew Morton, linux-kernel, bpf
ccing bpf list
On Fri, Jun 21, 2024 at 09:39:33PM +0300, Alexey Dobriyan wrote:
> Neither ELF spec not ELF loader require program header to be placed
> right after ELF header, but build-id code very much assumes such placement:
>
> See
>
> find_get_page(vma->vm_file->f_mapping, 0);
>
> line and checks against PAGE_SIZE.
>
> Returns errors for now until someone rewrites build-id parser
> to be more inline with load_elf_binary().
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
>
> lib/buildid.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -73,6 +73,13 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
> Elf32_Phdr *phdr;
> int i;
>
> + /*
> + * FIXME
nit, FIXME is usually on the same line as the rest of the comment,
otherwise looks good
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirka
> + * Neither ELF spec nor ELF loader require that program headers
> + * start immediately after ELF header.
> + */
> + if (ehdr->e_phoff != sizeof(Elf32_Ehdr))
> + return -EINVAL;
> /* only supports phdr that fits in one page */
> if (ehdr->e_phnum >
> (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
> @@ -98,6 +105,13 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
> Elf64_Phdr *phdr;
> int i;
>
> + /*
> + * FIXME
> + * Neither ELF spec nor ELF loader require that program headers
> + * start immediately after ELF header.
> + */
> + if (ehdr->e_phoff != sizeof(Elf64_Ehdr))
> + return -EINVAL;
> /* only supports phdr that fits in one page */
> if (ehdr->e_phnum >
> (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] build-id: require program headers to be right after ELF header
2024-06-24 11:23 ` Jiri Olsa
@ 2024-06-25 3:28 ` Andrii Nakryiko
0 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2024-06-25 3:28 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Alexey Dobriyan, Andrew Morton, linux-kernel, bpf
On Mon, Jun 24, 2024 at 4:23 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> ccing bpf list
>
> On Fri, Jun 21, 2024 at 09:39:33PM +0300, Alexey Dobriyan wrote:
> > Neither ELF spec not ELF loader require program header to be placed
> > right after ELF header, but build-id code very much assumes such placement:
> >
> > See
> >
> > find_get_page(vma->vm_file->f_mapping, 0);
> >
> > line and checks against PAGE_SIZE.
> >
> > Returns errors for now until someone rewrites build-id parser
> > to be more inline with load_elf_binary().
> >
> > Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> > ---
> >
> > lib/buildid.c | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
LGTM, but let's please route this through the bpf-next/master tree.
Can you please send it to bpf@vger.kernel.org?
Acked-by: Andrii Nakryiko <andrii@kernel.org>
> > --- a/lib/buildid.c
> > +++ b/lib/buildid.c
> > @@ -73,6 +73,13 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
> > Elf32_Phdr *phdr;
> > int i;
> >
> > + /*
> > + * FIXME
>
> nit, FIXME is usually on the same line as the rest of the comment,
> otherwise looks good
>
> Reviewed-by: Jiri Olsa <jolsa@kernel.org>
>
> thanks,
> jirka
>
>
> > + * Neither ELF spec nor ELF loader require that program headers
> > + * start immediately after ELF header.
> > + */
> > + if (ehdr->e_phoff != sizeof(Elf32_Ehdr))
> > + return -EINVAL;
> > /* only supports phdr that fits in one page */
> > if (ehdr->e_phnum >
> > (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
> > @@ -98,6 +105,13 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
> > Elf64_Phdr *phdr;
> > int i;
> >
> > + /*
> > + * FIXME
> > + * Neither ELF spec nor ELF loader require that program headers
> > + * start immediately after ELF header.
> > + */
> > + if (ehdr->e_phoff != sizeof(Elf64_Ehdr))
> > + return -EINVAL;
> > /* only supports phdr that fits in one page */
> > if (ehdr->e_phnum >
> > (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-25 3:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-21 15:05 [PATCH] build-id: require program headers to be right after ELF header Alexey Dobriyan
2024-06-21 17:07 ` Andrew Morton
2024-06-21 18:32 ` Alexey Dobriyan
2024-06-21 18:39 ` [PATCH v2] " Alexey Dobriyan
2024-06-24 11:23 ` Jiri Olsa
2024-06-25 3:28 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox