public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v2] build-id: require program headers to be right after ELF header
Date: Mon, 24 Jun 2024 13:23:00 +0200	[thread overview]
Message-ID: <ZnlXFF2sV-JNjGl2@krava> (raw)
In-Reply-To: <d58bc281-6ca7-467a-9a64-40fa214bd63e@p183>

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))

  reply	other threads:[~2024-06-24 11:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2024-06-25  3:28       ` Andrii Nakryiko

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=ZnlXFF2sV-JNjGl2@krava \
    --to=olsajiri@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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