[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <16736E00-BE43-46D8-8837-BC9F8EF2A5AA@meta.com>
Date: Wed, 16 Jul 2025 17:12:46 +0000
From: Song Liu <songliubraving@...a.com>
To: Christian Brauner <brauner@...nel.org>
CC: Paul Moore <paul@...l-moore.com>, Al Viro <viro@...iv.linux.org.uk>,
Song
Liu <song@...nel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-security-module@...r.kernel.org"
<linux-security-module@...r.kernel.org>,
"apparmor@...ts.ubuntu.com"
<apparmor@...ts.ubuntu.com>,
"selinux@...r.kernel.org"
<selinux@...r.kernel.org>,
"tomoyo-users_en@...ts.sourceforge.net"
<tomoyo-users_en@...ts.sourceforge.net>,
"tomoyo-users_ja@...ts.sourceforge.net"
<tomoyo-users_ja@...ts.sourceforge.net>,
Kernel Team <kernel-team@...a.com>,
"andrii@...nel.org" <andrii@...nel.org>,
"eddyz87@...il.com"
<eddyz87@...il.com>,
"ast@...nel.org" <ast@...nel.org>,
"daniel@...earbox.net" <daniel@...earbox.net>,
"martin.lau@...ux.dev"
<martin.lau@...ux.dev>,
"jack@...e.cz" <jack@...e.cz>,
"kpsingh@...nel.org"
<kpsingh@...nel.org>,
"mattbobrowski@...gle.com" <mattbobrowski@...gle.com>,
"amir73il@...il.com" <amir73il@...il.com>,
"repnop@...gle.com"
<repnop@...gle.com>,
"jlayton@...nel.org" <jlayton@...nel.org>,
"josef@...icpanda.com" <josef@...icpanda.com>,
"mic@...ikod.net"
<mic@...ikod.net>,
"gnoack@...gle.com" <gnoack@...gle.com>,
"m@...wtm.org"
<m@...wtm.org>,
"john.johansen@...onical.com" <john.johansen@...onical.com>,
"john@...armor.net" <john@...armor.net>,
"stephen.smalley.work@...il.com"
<stephen.smalley.work@...il.com>,
"omosnace@...hat.com"
<omosnace@...hat.com>,
"takedakn@...data.co.jp" <takedakn@...data.co.jp>,
"penguin-kernel@...ove.sakura.ne.jp" <penguin-kernel@...ove.sakura.ne.jp>,
"enlightened@...omium.org" <enlightened@...omium.org>
Subject: Re: [RFC] vfs: security: Parse dev_name before calling
security_sb_mount
> On Jul 16, 2025, at 1:31 AM, Christian Brauner <brauner@...nel.org> wrote:
>
> On Tue, Jul 15, 2025 at 10:31:39PM +0000, Song Liu wrote:
>>
>>> On Jul 15, 2025, at 3:18 AM, Christian Brauner <brauner@...nel.org> wrote:
>>> On Mon, Jul 14, 2025 at 03:10:57PM +0000, Song Liu wrote:
>>
>>
>> [...]
>>
>>>>> If you place a new security hook into __do_loopback() the only thing
>>>>> that I'm not excited about is that we're holding the global namespace
>>>>> semaphore at that point. And I want to have as little LSM hook calls
>>>>> under the namespace semaphore as possible.
>>>>
>>>> do_loopback() changed a bit since [1]. But if we put the new hook
>>>> in do_loopback() before lock_mount(), we don’t have the problem with
>>>> the namespace semaphore, right? Also, this RFC doesn’t seem to have
>>>> this issue either.
>>>
>>> While the mount isn't locked another mount can still be mounted on top
>>> of it. lock_mount() will detect this and lookup the topmost mount and
>>> use that. IOW, the value of old_path->mnt may have changed after
>>> lock_mount().
>>
>> I am probably confused. Do you mean path->mnt (instead of old_path->mnt)
>> may have changed after lock_mount()?
>
> I mean the target path. I forgot that the code uses @old_path to mean
> the source path not the target path. And you're interested in the source
> path, not the target path.
Both security_sb_mount and security_move_mount has the overmount issue
for target path.
[...]
>>
>> It appears to me that do_loopback() has the tricky issue:
>>
>> static int do_loopback(struct path *path, ...)
>> {
>> ...
>> /*
>> * path may still change, so not a good point to add
>> * security hook
>> */
>> mp = lock_mount(path);
>> if (IS_ERR(mp)) {
>> /* ... */
>> }
>> /*
>> * namespace_sem is locked, so not a good point to add
>> * security hook
>> */
>> ...
>> }
>>
>> Basically, without major work with locking, there is no good
>> spot to insert a security hook into do_loopback(). Or, maybe
>> we can add a hook somewhere in lock_mount()?
>
> You can't really because the lookup_mnt() call in lock_mount() happens
> under the namespace semaphore already and if it's the topmost mount it
> won't be dropped again and you can't drop it again without risking
> overmounts again.
We probably have to accept the overmount issue for security_ hooks
that covers the new mount APIs.
> But again, as long as you are interested in the source mount you should
> be fine.
For the source path, we are back to the issue we want to address
in this RFC: to get struct path of dev_name (source path) for bind
mount. Among these proposals:
1. Introduce bpf_kern_path kfunc.
We will probably limit this kfunc to only work on security_sb_mount.
2. Add new hook(s), such as [1].
[1] https://lore.kernel.org/linux-security-module/20250110021008.2704246-1-enlightened@chromium.org/
This is not a complete solution. However, given security_sb_mount
as-is handles so many different cases, we will likely split it in
the future. Therefore, this new hook can be a reasonable incremental
step.
3. Something like this patch.
Does any proposal look acceptable?
Thanks,
Song
Powered by blists - more mailing lists