From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
kernel-team@fb.com, hannes@cmpxchg.org
Subject: Re: [PATCH v2 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address
Date: Tue, 6 Mar 2018 19:25:26 +0100 [thread overview]
Message-ID: <20180306182526.GJ25181@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180306180914.1935350-1-songliubraving@fb.com>
On Tue, Mar 06, 2018 at 10:09:13AM -0800, Song Liu wrote:
> +/* Parse build ID of ELF file mapped to vma */
> +static int stack_map_get_build_id(struct vm_area_struct *vma,
> + unsigned char *build_id)
> +{
> + Elf32_Ehdr *ehdr;
> + struct page *page;
> + int ret;
> +
> + /*
> + * vm_start is user memory, so we need to be careful with it.
> + * We don't want too many copy_from_user to reduce overhead.
> + * Most ELF file is at least one page long, and the build_id
> + * is stored in the first page. Therefore, we limit the search of
> + * build_id to the first page only. This can be made safe with
> + * get_user_pages_fast(). If the file is smaller than PAGE_SIZE,
> + * or the build_id is not in the first page, the look up fails.
> + */
> + if (vma->vm_end - vma->vm_start < PAGE_SIZE ||
> + vma->vm_start & (PAGE_SIZE - 1)) /* page aligned */
> + return -EINVAL;
> +
> + if (get_user_pages_fast(vma->vm_start, 1, 0, &page) != 1)
> + return -EFAULT;
> +
> + ret = -EINVAL;
> + ehdr = (Elf32_Ehdr *)vma->vm_start;
> +
You're still directly accessing a user pointer afaict. This will
insta-fault on SMAP enabled hardware due to the lack of STAC (or PAN on
ARM).
You _really_ cannot just access user pointers without the proper APIs.
Did you maybe mean to use:
ehdr = (Elf32_Ehdr *)page_address(page);
?
> + /* compare magic x7f "ELF" */
> + if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
> + goto out;
> +
> + /* only support executable file and shared object file */
> + if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN)
> + goto out;
> +
> + if (ehdr->e_ident[EI_CLASS] == 1)
> + ret = stack_map_get_build_id_32(vma, build_id);
> + else if (ehdr->e_ident[EI_CLASS] == 2)
> + ret = stack_map_get_build_id_64(vma, build_id);
> +out:
> + put_page(page);
> + return ret;
> +}
next prev parent reply other threads:[~2018-03-06 18:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 18:09 [PATCH v2 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address Song Liu
2018-03-06 18:09 ` [PATCH v2 2/2] bpf: add selftest for stackmap with BPF_F_STACK_BUILD_ID Song Liu
2018-03-06 18:25 ` Peter Zijlstra [this message]
2018-03-06 18:38 ` [PATCH v2 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address Song Liu
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=20180306182526.GJ25181@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
/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