From: Tingmao Wang <m@maowtm.org>
To: "Song Liu" <song@kernel.org>, "Mickaël Salaün" <mic@digikod.net>,
"Christian Brauner" <brauner@kernel.org>
Cc: "Amir Goldstein" <amir73il@gmail.com>,
"Günther Noack" <gnoack@google.com>, "Jan Kara" <jack@suse.cz>,
linux-security-module@vger.kernel.org,
"Matthew Bobrowski" <repnop@google.com>,
linux-fsdevel@vger.kernel.org,
"Tycho Andersen" <tycho@tycho.pizza>,
"Kees Cook" <kees@kernel.org>, "Jeff Xu" <jeffxu@google.com>,
"Mikhail Ivanov" <ivanov.mikhail1@huawei-partners.com>,
"Francis Laniel" <flaniel@linux.microsoft.com>,
"Matthieu Buffet" <matthieu@buffet.re>,
"Paul Moore" <paul@paul-moore.com>,
"Kentaro Takeda" <takedakn@nttdata.co.jp>,
"Tetsuo Handa" <penguin-kernel@i-love.sakura.ne.jp>,
"John Johansen" <john.johansen@canonical.com>
Subject: Re: [RFC PATCH 0/9] Landlock supervise: a mechanism for interactive permission requests
Date: Tue, 11 Mar 2025 22:03:19 +0000 [thread overview]
Message-ID: <c6e67ee5-9f85-44f4-a27c-97e10942ff57@maowtm.org> (raw)
In-Reply-To: <CAPhsuW4YXGFY___8x7my4tUbgyp5N4FHSQpJpKgEDK6r0vphAA@mail.gmail.com>
On 3/11/25 20:58, Song Liu wrote:
> On Tue, Mar 11, 2025 at 12:28 PM Mickaël Salaün <mic@digikod.net> wrote:
>>
>> On Tue, Mar 11, 2025 at 12:42:05AM +0000, Tingmao Wang wrote:
>>> On 3/6/25 17:07, Amir Goldstein wrote:
>>> [...]
>>>>
>>>> w.r.t sharing infrastructure with fanotify, I only looked briefly at
>>>> your patches
>>>> and I have only a vague familiarity with landlock, so I cannot yet form an
>>>> opinion whether this is a good idea, but I wanted to give you a few more
>>>> data points about fanotify that seem relevant.
>>>>
>>>> 1. There is already some intersection of fanotify and audit lsm via the
>>>> fanotify_response_info_audit_rule extension for permission
>>>> events, so it's kind of a precedent of using fanotify to aid an lsm
>>>>
>>>> 2. See this fan_pre_modify-wip branch [1] and specifically commit
>>>> "fanotify: introduce directory entry pre-modify permission events"
>>>> I do have an intention to add create/delete/rename permission events.
>>>> Note that the new fsnotify hooks are added in to do_ vfs helpers, not very
>>>> far from the security_path_ lsm hooks, but not exactly in the same place
>>>> because we want to fsnotify hooks to be before taking vfs locks, to allow
>>>> listener to write to filesystem from event context.
>>>> There are different semantics than just ALLOW/DENY that you need,
>>>> therefore, only if we move the security_path_ hooks outside the
>>>> vfs locks, our use cases could use the same hooks
>>>
>>> Hi Amir,
>>>
>>> (this is a slightly long message - feel free to respond at your convenience,
>>> thank you in advance!)
>>>
>>> Thanks a lot for mentioning this branch, and for the explanation! I've had a
>>> look and realized that the changes you have there will be very useful for
>>> this patch, and in fact, I've already tried a worse attempt of this (not
>>> included in this patch series yet) to create some security_pathname_ hooks
>>> that takes the parent struct path + last name as char*, that will be called
>>> before locking the parent. (We can't have an unprivileged supervisor cause
>>> a directory to be locked indefinitely, which will also block users outside
>>> of the landlock domain)
>>>
>>> I'm not sure if we can move security_path tho, because it takes the dentry
>>> of the child as an argument, and (I think at least for create / mknod /
>>> link) that dentry is only created after locking. Hence the proposal for
>>> separate security_pathname_ hooks. A search shows that currently AppArmor
>>> and TOMOYO (plus Landlock) uses the security_path_ hooks that would need
>>> changing, if we move it (and we will have to understand if the move is ok to
>>> do for the other two LSMs...)
>>>
>>> However, I think it would still make a lot of sense to align with fsnotify
>>> here, as you have already made the changes that I would need to do anyway
>>> should I implement the proposed new hooks. I think a sensible thing might
>>> be to have the extra LSM hooks be called alongside fsnotify_(re)name_perm -
>>> following the pattern of what currently happens with fsnotify_open_perm
>>> (i.e. security_file_open called first, then fsnotify_open_perm right after).
>
> I think there is a fundamental difference between LSM hooks and fsnotify,
> so putting fsnotify behind some LSM hooks might be weird. Specifically,
> LSM hooks are always global. If a LSM attaches to a hook, say
> security_file_open, it will see all the file open calls in the system. On the
> other hand, each fsnotify rule only applies to a group, so that one fanotify
> handler doesn't touch files watched by another fanotify handler. Given this
> difference, I am not sure how fsnotify LSM hooks should look like.
>
> Does this make sense?
To clarify, I wasn't suggesting that we put one hook _behind_ another
("behind" in the sense of one calling the other), just that the place
that calls the new fsnotify_name_perm/fsnotify_rename_perm hook (in
Amir's WIP branch) could also be made to call some new LSM hooks in
addition to fsnotify (i.e. security_pathname_create/delete/rename).
My understanding of the current code is that VFS calls security_... and
fsnotify_... unconditionally, and the fsnotify_... functions figure out
who needs to be notified.
>
>> Yes, I think it would make sense to use the same hooks for fanotify and
>> other security subsystems, or at least to share them. It would improve
>> consistency across different Linux subsystems and simplify changes and
>> maintenance where these hooks are called.
Mickaël - I'm not sure what you mean by "the same hook" - do you mean
the relevant VFS functions could call both fsnotify and LSM hooks?
>
> [...]
>
>>> --
>>>
>>> For Mickaël,
>>>
>>> Would you be on board with changing Landlock to use the new hooks as
>>> mentioned above? My thinking is that it shouldn't make any difference in
>>> terms of security - Landlock permissions for e.g. creating/deleting files
>>> are based on the parent, and in fact except for link and rename, the
>>> hook_path_ functions in Landlock don't even use the dentry argument. If
>>> you're happy with the general direction of this, I can investigate further
>>> and test it out etc. This change might also reduce the impact of Landlock
>>> on non-landlocked processes, if we avoid holding exclusive inode lock while
>>> evaluating rules / traversing paths...? (Just a thought, not measured)
>
> I think the filter for process/thread is usually faster than the filter for
> file/path/subtree? Therefore, it is better for landlock to check the filter for
> process/thread first. Did I miss/misunderstand something?
>
Sorry, I should have clarified that the "impact" I'm talking about here
isn't referring to directly the time it takes for landlock to decide if
an access is allowed or not - in a non-landlocked process, the landlock
hooks already returns really early and fast. However, I'm thinking of a
situation where a landlocked process makes lots of create/delete etc
requests on a directory, and landlock does need to do some work (e.g.
path traversal) to decide those access. Because the
security_path_mknod/unlink/... hooks are called in the VFS from a place
where it is holding an exclusive lock on the directory (for O_CREAT'ing
a child or other directory modification cases), when landlock is working
out an access by the landlocked process, no other tasks will be able to
read/write the directory (they will be blocked on the lock), even if
their access have nothing to do with landlock.
I should add that this is probably just a very minor impact: the user
space can't cause the dir to be blocked for arbitrary amount of time, at
worst slowing everyone else down by a bit if it deliberately creates
lots of layers (max 16) each with lots of rules (the ruleset evaluation
is O(log(#rules) * dir_depth)). I didn't measure it, it's just something
that occurred to me that could be improved by using new hooks that
aren't called with inode locks held.
Kind regards,
Tingmao
> Thanks,
> Song
>
>
>
>
>> This looks reasonable. As long as the semantic does not change it
>> should be good and Landlock tests should pass. That would also require
>> other users of this hook to make sure it works for them too. If it is
>> not the case, I guess we could add an alternative hooks with different
>> properties. However, see the issue and the alternative approach below.
>>
next prev parent reply other threads:[~2025-03-11 22:03 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 1:12 [RFC PATCH 0/9] Landlock supervise: a mechanism for interactive permission requests Tingmao Wang
2025-03-04 1:12 ` [RFC PATCH 1/9] Define the supervisor and event structure Tingmao Wang
2025-03-04 1:12 ` [RFC PATCH 2/9] Refactor per-layer information in rulesets and rules Tingmao Wang
2025-03-04 19:49 ` Mickaël Salaün
2025-03-06 2:58 ` Tingmao Wang
2025-03-08 18:57 ` Mickaël Salaün
2025-03-10 0:38 ` Tingmao Wang
2025-03-04 1:12 ` [RFC PATCH 3/9] Adds a supervisor reference in the per-layer information Tingmao Wang
2025-03-04 1:13 ` [RFC PATCH 4/9] User-space API for creating a supervisor-fd Tingmao Wang
2025-03-05 16:09 ` Mickaël Salaün
2025-03-10 0:41 ` Tingmao Wang
2025-03-11 19:28 ` Mickaël Salaün
2025-03-26 0:06 ` Tingmao Wang
2025-04-11 10:55 ` Mickaël Salaün
2025-03-04 1:13 ` [RFC PATCH 5/9] Define user structure for events and responses Tingmao Wang
2025-03-04 19:49 ` Mickaël Salaün
2025-03-06 3:05 ` Tingmao Wang
2025-03-08 19:07 ` Mickaël Salaün
2025-03-10 0:39 ` Tingmao Wang
2025-03-11 19:29 ` Mickaël Salaün
2025-03-10 0:39 ` Tingmao Wang
2025-03-11 19:28 ` Mickaël Salaün
2025-03-11 23:18 ` Tingmao Wang
2025-03-12 11:49 ` Mickaël Salaün
2025-03-26 0:02 ` Tingmao Wang
2025-03-04 1:13 ` [RFC PATCH 6/9] Creating supervisor events for filesystem operations Tingmao Wang
2025-03-04 19:50 ` Mickaël Salaün
2025-03-10 0:39 ` Tingmao Wang
2025-03-11 19:29 ` Mickaël Salaün
2025-03-04 1:13 ` [RFC PATCH 7/9] Implement fdinfo for ruleset and supervisor fd Tingmao Wang
2025-03-04 1:13 ` [RFC PATCH 8/9] Implement fops for supervisor-fd Tingmao Wang
2025-03-04 1:13 ` [RFC PATCH 9/9] Enhance the sandboxer example to support landlock-supervise Tingmao Wang
2025-03-04 19:48 ` [RFC PATCH 0/9] Landlock supervise: a mechanism for interactive permission requests Mickaël Salaün
2025-03-06 2:57 ` Tingmao Wang
2025-03-06 17:07 ` Amir Goldstein
2025-03-08 19:14 ` Mickaël Salaün
2025-03-11 0:42 ` Tingmao Wang
2025-03-11 19:28 ` Mickaël Salaün
2025-03-11 20:58 ` Song Liu
2025-03-11 22:03 ` Tingmao Wang [this message]
2025-03-11 23:23 ` Song Liu
2025-03-12 11:50 ` Mickaël Salaün
2025-03-12 10:58 ` Jan Kara
2025-03-12 12:26 ` Amir Goldstein
2025-03-08 18:57 ` Mickaël Salaün
2025-03-06 21:04 ` Jan Kara
2025-03-08 19:15 ` Mickaël Salaün
2025-03-12 6:20 ` Tetsuo Handa
2025-03-24 1:58 ` Tingmao Wang
2025-03-24 10:43 ` Tetsuo Handa
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=c6e67ee5-9f85-44f4-a27c-97e10942ff57@maowtm.org \
--to=m@maowtm.org \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=flaniel@linux.microsoft.com \
--cc=gnoack@google.com \
--cc=ivanov.mikhail1@huawei-partners.com \
--cc=jack@suse.cz \
--cc=jeffxu@google.com \
--cc=john.johansen@canonical.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=matthieu@buffet.re \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=repnop@google.com \
--cc=song@kernel.org \
--cc=takedakn@nttdata.co.jp \
--cc=tycho@tycho.pizza \
/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;
as well as URLs for NNTP newsgroup(s).