From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Christian Brauner <brauner@kernel.org>
Cc: "Ard Biesheuvel" <ardb@kernel.org>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Ryan Lee" <ryan.lee@canonical.com>,
"Malte Schröder" <malte.schroeder@tnxip.de>,
linux-security-module@vger.kernel.org,
apparmor <apparmor@lists.ubuntu.com>,
linux-efi@vger.kernel.org,
"John Johansen" <john.johansen@canonical.com>,
"jk@ozlabs.org" <jk@ozlabs.org>,
linux-fsdevel@vger.kernel.org
Subject: Re: [RFC 1/1] fix NULL mnt [was Re: apparmor NULL pointer dereference on resume [efivarfs]]
Date: Sun, 16 Mar 2025 10:26:12 -0400 [thread overview]
Message-ID: <b2086c64d47463a019ac9fc9e5d7ee7f70becc8d.camel@HansenPartnership.com> (raw)
In-Reply-To: <20250316-vergibt-hausrat-b23d525a1d24@brauner>
On Sun, 2025-03-16 at 07:46 +0100, Christian Brauner wrote:
> On Sat, Mar 15, 2025 at 02:41:43PM -0400, James Bottomley wrote:
[...]
> > However, there's another problem: the mntput after kernel_file_open
> > may synchronously call cleanup_mnt() (and thus deactivate_super())
> > if the open fails because it's marked MNT_INTERNAL, which is caused
> > by SB_KERNMOUNT. I fixed this just by not passing the SB_KERNMOUNT
> > flag, which feels a bit hacky.
>
> It actually isn't. We know that vfs_kern_mount() will always
> resurface the single superblock that's exposed to userspace because
> we've just taken a reference to it earlier in efivarfs_pm_notify().
> So that SB_KERNMOUNT flag is ignored because no new superblock is
> allocated. It would only matter if we'd end up allocating a new
> superblock which we never do.
I agree with the above: fc->sb_flags never propagates to the existing
superblock. However, nothing propagates the superblock flags back to
fc->sb_flags either. The check in vfs_create_mount() is on fc-
>sb_flags. Since the code is a bit hard to follow I added a printk on
the path.mnt flags and sure enough it comes back with MNT_INTERNAL when
SB_KERNMOUNT is set.
> And if we did it would be a bug because the superblock we allocate
> could be reused at any time if a userspace task mounts efivarfs
> before efivarfs_pm_notify() has destroyed it (or the respective
> workqueue). But that superblock would then have SB_KERNMOUNT for
> something that's not supposed to be one.
True, but the flags don't propagate to the superblock, so no bug.
> And whether or not that helper mount has MNT_INTERNAL is immaterial
> to what you're doing here afaict.
I think the problem is the call chain mntput() -> mntput_no_expire()
which directly calls cleanup_mnt() -> deactivate_super() if that flag
is set. Though I don't see that kernel_file_open() could ever fail
except for some catastrophic reason like out of memory, so perhaps it
isn't worth quibbling about.
> So not passing the SB_KERNMOUNT flag is the right thing (see devtmpfs
> as well). You could slap a comment in here explaining that we never
> allocate a new superblock so it's clear to people not familiar with
> this particular code.
OK, so you agree that the code as written looks correct? Even if we
don't necessarily quite agree on why.
Regards,
James
next prev parent reply other threads:[~2025-03-16 14:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 19:04 apparmor NULL pointer dereference on resume Malte Schröder
2025-03-05 19:22 ` Ryan Lee
2025-03-05 21:47 ` Malte Schröder
2025-03-10 19:57 ` Ryan Lee
2025-03-10 21:49 ` apparmor NULL pointer dereference on resume [efivarfs] James Bottomley
2025-03-11 7:16 ` Ard Biesheuvel
2025-03-11 8:45 ` Christian Brauner
2025-03-11 13:01 ` James Bottomley
2025-03-11 15:55 ` Christian Brauner
2025-03-11 16:19 ` Christian Brauner
2025-03-11 16:20 ` James Bottomley
2025-03-11 17:15 ` Al Viro
2025-03-11 17:46 ` James Bottomley
2025-03-14 14:59 ` [RFC 1/1] fix NULL mnt [was Re: apparmor NULL pointer dereference on resume [efivarfs]] James Bottomley
2025-03-15 10:04 ` Christian Brauner
2025-03-15 18:41 ` James Bottomley
2025-03-16 6:46 ` Christian Brauner
2025-03-16 14:26 ` James Bottomley [this message]
2025-03-16 19:19 ` Ard Biesheuvel
2025-03-17 8:56 ` Christian Brauner
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=b2086c64d47463a019ac9fc9e5d7ee7f70becc8d.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=apparmor@lists.ubuntu.com \
--cc=ardb@kernel.org \
--cc=brauner@kernel.org \
--cc=jk@ozlabs.org \
--cc=john.johansen@canonical.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=malte.schroeder@tnxip.de \
--cc=ryan.lee@canonical.com \
--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