From: Song Liu <songliubraving@meta.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "Song Liu" <songliubraving@meta.com>,
"Song Liu" <song@kernel.org>, bpf <bpf@vger.kernel.org>,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"LSM List" <linux-security-module@vger.kernel.org>,
"Kernel Team" <kernel-team@meta.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eddy Z" <eddyz87@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>, "KP Singh" <kpsingh@kernel.org>,
"Matt Bobrowski" <mattbobrowski@google.com>,
"Amir Goldstein" <amir73il@gmail.com>,
"repnop@google.com" <repnop@google.com>,
"Jeff Layton" <jlayton@kernel.org>,
"Josef Bacik" <josef@toxicpanda.com>,
"Mickaël Salaün" <mic@digikod.net>,
"gnoack@google.com" <gnoack@google.com>
Subject: Re: [RFC/PATCH v2 bpf-next fanotify 7/7] selftests/bpf: Add test for BPF based fanotify fastpath handler
Date: Fri, 15 Nov 2024 01:10:38 +0000 [thread overview]
Message-ID: <DCE25AB7-E337-4E11-9D57-2880F822BF33@fb.com> (raw)
In-Reply-To: <CAADnVQJ1um9u4cBpAEw83CS8xZJN=iP8WXdG0Ops5oTP-_NDFg@mail.gmail.com>
> On Nov 14, 2024, at 4:41 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Nov 14, 2024 at 3:02 PM Song Liu <songliubraving@meta.com> wrote:
>>
>>
>>
>>> On Nov 14, 2024, at 12:14 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>>>
>>> On Thu, Nov 14, 2024 at 12:44 AM Song Liu <song@kernel.org> wrote:
>>>>
>>>> +
>>>> + if (bpf_is_subdir(dentry, v->dentry))
>>>> + ret = FAN_FP_RET_SEND_TO_USERSPACE;
>>>> + else
>>>> + ret = FAN_FP_RET_SKIP_EVENT;
>>>
>>> It seems to me that all these patches and feature additions
>>> to fanotify, new kfuncs, etc are done just to do the above
>>> filtering by subdir ?
>>>
>>> If so, just hard code this logic as an extra flag to fanotify ?
>>> So it can filter all events by subdir.
>>> bpf programmability makes sense when it needs to express
>>> user space policy. Here it's just a filter by subdir.
>>> bpf hammer doesn't look like the right tool for this use case.
>>
>> Current version is indeed tailored towards the subtree
>> monitoring use case. This is mostly because feedback on v1
>> mostly focused on this use case. V1 itself actually had some
>> other use cases.
>
> like?
samples/fanotify in v1 shows pattern that matches file prefix
(no BPF). selftests/bpf in v1 shows a pattern where we
propagate a flag in inode local storage from parent directory
to newly created children directory.
>
>> In practice, fanotify fastpath can benefit from bpf
>> programmability. For example, with bpf programmability, we
>> can combine fanotify and BPF LSM in some security use cases.
>> If some security rules only applies to a few files, a
>> directory, or a subtree, we can use fanotify to only monitor
>> these files. LSM hooks, such as security_file_open(), are
>> always global. The overhead is higher if we are only
>> interested in a few files.
>>
>> Does this make sense?
>
> Not yet.
> This fanotify bpf filtering only reduces the number of events
> sent to user space.
> How is it supposed to interact with bpf-lsm?
Ah, I didn't explain this part. fanotify+bpf fastpath can
do more reducing number of events sent to user space. It can
also be used in tracing use cases. For example, we can
implement a filetop tool that only monitors a specific
directory, a specific device, or a specific mount point.
It can also reject some file access (fanotify permission
mode). I should have showed these features in a sample
and/or selftest.
> Say, security policy applies to /usr/bin/*
> so lsm suppose to act on all files and subdirs in there.
> How fanotify helps ?
LSM hooks are always global. It is up to the BPF program
to filter out irrelevant events. This filtering is
sometimes expensive (match d_patch) and inaccurate
(maintain a map of target inodes, etc.). OTOH, fanotify
has built-in filtering before the BPF program triggers.
When multiple BPF programs are monitoring open() for
different subdirectories, fanotify based solution will
not trigger all these BPF programs for all the open()
in the system.
Does this answer the questions?
Thanks,
Song
next prev parent reply other threads:[~2024-11-15 1:10 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 8:43 [RFC/PATCH v2 bpf-next fanotify 0/7] Fanotify " Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 1/7] fanotify: Introduce fanotify " Song Liu
2024-11-15 8:51 ` Amir Goldstein
2024-11-15 17:11 ` Song Liu
2024-11-15 17:32 ` Amir Goldstein
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 2/7] samples/fanotify: Add a sample " Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 3/7] bpf: Make bpf inode storage available to tracing programs Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 4/7] bpf: fs: Add three kfuncs Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 5/7] bpf: Allow bpf map hold reference on dentry Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 6/7] fanotify: Enable bpf based fanotify fastpath handler Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 7/7] selftests/bpf: Add test for BPF " Song Liu
2024-11-14 20:14 ` Alexei Starovoitov
2024-11-14 23:02 ` Song Liu
2024-11-15 0:41 ` Alexei Starovoitov
2024-11-15 1:10 ` Song Liu [this message]
2024-11-15 1:31 ` Alexei Starovoitov
2024-11-15 7:01 ` Song Liu
2024-11-15 19:41 ` Alexei Starovoitov
2024-11-15 21:05 ` Song Liu
2024-11-18 20:51 ` Song Liu
2024-11-19 0:10 ` Alexei Starovoitov
2024-11-19 1:10 ` Song Liu
2024-11-19 7:59 ` Amir Goldstein
2024-11-19 8:35 ` Song Liu
2024-11-15 7:26 ` Amir Goldstein
2024-11-15 20:04 ` Alexei Starovoitov
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=DCE25AB7-E337-4E11-9D57-2880F822BF33@fb.com \
--to=songliubraving@meta.com \
--cc=alexei.starovoitov@gmail.com \
--cc=amir73il@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=kpsingh@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=mic@digikod.net \
--cc=repnop@google.com \
--cc=song@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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®