From: Hengqi Chen <hengqi.chen@gmail.com>
To: Florent Revest <revest@chromium.org>, Martin KaFai Lau <kafai@fb.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, kpsingh@kernel.org, jackmanb@google.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next] bpf: Allow bpf_d_path in perf_event_mmap
Date: Mon, 1 Nov 2021 21:17:42 +0800 [thread overview]
Message-ID: <204584e8-7817-f445-1e73-b23552f54c2f@gmail.com> (raw)
In-Reply-To: <CABRcYmLWAp6kYJBA2g+DvNQcg-5NaAz7u51ucBMPfW0dGykZAg@mail.gmail.com>
Hi,
On 2021/10/30 1:02 AM, Florent Revest wrote:
> On Fri, Oct 29, 2021 at 12:47 AM Martin KaFai Lau <kafai@fb.com> wrote:
>>
>> On Thu, Oct 28, 2021 at 06:43:57PM +0200, Florent Revest wrote:
>>> Allow the helper to be called from the perf_event_mmap hook. This is
>>> convenient to lookup vma->vm_file and implement a similar logic as
>>> perf_event_mmap_event in BPF.
>> From struct vm_area_struct:
>> struct file * vm_file; /* File we map to (can be NULL). */
>>
>> Under perf_event_mmap, vm_file won't be NULL or bpf_d_path can handle it?
>
> Thanks Martin, this is a very good point. :) Yes, vm_file can be NULL
> in perf_event_mmap.
> I wonder what would happen (and what we could do about it? :|).
> bpf_d_path is called on &vma->vm_file->f_path So without NULL checks
> (of vm_file) in BPF, the helper wouldn't be called with a NULL pointer
> but rather with an address that is offsetof(struct file, f_path).
>
I tested this patch with the following BCC script:
bpf_text = '''
#include <linux/mm_types.h>
KFUNC_PROBE(perf_event_mmap, struct vm_area_struct *vma)
{
char path[256] = {};
bpf_d_path(&vma->vm_file->f_path, path, sizeof(path));
bpf_trace_printk("perf_event_mmap %s", path);
return 0;
}
'''
b = BPF(text=bpf_text)
print("BPF program loaded")
b.trace_print()
This change causes kernel panic. I think it's because of this NULL pointer.
next prev parent reply other threads:[~2021-11-01 13:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-28 16:43 Florent Revest
2021-10-28 22:46 ` Martin KaFai Lau
2021-10-29 15:17 ` Hengqi Chen
2021-10-29 17:08 ` Florent Revest
2021-10-29 17:02 ` Florent Revest
2021-11-01 13:17 ` Hengqi Chen [this message]
2021-11-01 15:01 ` Florent Revest
2021-11-01 17:31 ` Yonghong Song
2021-11-02 2:53 ` Alexei Starovoitov
2021-11-02 3:16 ` Andrii Nakryiko
2021-11-02 3:20 ` Alexei Starovoitov
2021-11-02 4:05 ` Andrii Nakryiko
2021-11-02 23:03 ` Florent Revest
2021-11-02 23:15 ` Yonghong Song
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=204584e8-7817-f445-1e73-b23552f54c2f@gmail.com \
--to=hengqi.chen@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jackmanb@google.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=revest@chromium.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
all inboxes | Powered by JetHome®