linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Paul Moore <paul@paul-moore.com>
Cc: Jann Horn <jannh@google.com>,
	Christian Brauner <brauner@kernel.org>,
	 "Paul E. McKenney" <paulmck@kernel.org>,
	Casey Schaufler <casey@schaufler-ca.com>,
	 Kees Cook <keescook@chromium.org>,
	syzbot <syzbot+5446fbf332b0602ede0b@syzkaller.appspotmail.com>,
	 jmorris@namei.org, linux-kernel@vger.kernel.org,
	 linux-security-module@vger.kernel.org, serge@hallyn.com,
	syzkaller-bugs@googlegroups.com,  linux-fsdevel@vger.kernel.org,
	Mimi Zohar <zohar@linux.ibm.com>,
	 Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [syzbot] [lsm?] general protection fault in hook_inode_free_security
Date: Wed, 10 Jul 2024 15:53:16 +0200	[thread overview]
Message-ID: <20240710.Aephuhain8lu@digikod.net> (raw)
In-Reply-To: <20240710.Hai0Uj3Phaij@digikod.net>

On Wed, Jul 10, 2024 at 02:23:23PM +0200, Mickaël Salaün wrote:
> On Thu, Jun 27, 2024 at 02:28:03PM -0400, Paul Moore wrote:
> > On Thu, Jun 27, 2024 at 9:34 AM Mickaël Salaün <mic@digikod.net> wrote:
> > >
> > > I didn't find specific issues with Landlock's code except the extra
> > > check in hook_inode_free_security().  It looks like inode->i_security is
> > > a dangling pointer, leading to UAF.
> > >
> > > Reading security_inode_free() comments, two things looks weird to me:
> > >
> > > > /**
> > > >  * security_inode_free() - Free an inode's LSM blob
> > > >  * @inode: the inode
> > > >  *
> > > >  * Deallocate the inode security structure and set @inode->i_security to NULL.
> > >
> > > I don't see where i_security is set to NULL.
> > 
> > The function header comments are known to be a bit suspect, a side
> > effect of being detached from the functions for many years, this may
> > be one of those cases.  I tried to fix up the really awful ones when I
> > moved the comments back, back I didn't have time to go through each
> > one in detail.  Patches to correct the function header comments are
> > welcome and encouraged! :)
> > 
> > > >  */
> > > > void security_inode_free(struct inode *inode)
> > > > {
> > >
> > > Shouldn't we add this check here?
> > > if (!inode->i_security)
> > >         return;
> > 
> > Unless I'm remembering something wrong, I believe we *should* always
> > have a valid i_security pointer each time we are called, if not
> > something has gone wrong, e.g. the security_inode_free() hook is no
> > longer being called from the right place.  If we add a NULL check, we
> > should probably have a WARN_ON(), pr_err(), or something similar to
> > put some spew on the console/logs.
> > 
> > All that said, it would be good to hear some confirmation from the VFS
> > folks that the security_inode_free() hook is located in a spot such
> > that once it exits it's current RCU critical section it is safe to
> > release the associated LSM state.
> > 
> > It's also worth mentioning that while we always allocate i_security in
> > security_inode_alloc() right now, I can see a world where we allocate
> > the i_security field based on need using the lsm_blob_size info (maybe
> > that works today?  not sure how kmem_cache handled 0 length blobs?).
> > The result is that there might be a legitimate case where i_security
> > is NULL, yet we still want to call into the LSM using the
> > inode_free_security() implementation hook.
> 
> Looking at existing LSM implementations, even if some helpers (e.g.
> selinux_inode) return NULL if inode->i_security is NULL, this may not be
> handled by the callers.  For instance, SELinux always dereferences the
> blob pointer in the security_inode_permission() hook.  EVM seems to be
> the only one properly handling this case.
> 
> Shouldn't we remove all inode->i_security checks and assume it is always
> set?  This is currently the case anyway, but it would be clearer this
> way and avoid false sense of security (with useless checks).

A patch was sent to do this kind of check:
https://lore.kernel.org/r/20140109101932.0508dec7@gandalf.local.home
but the applied commit 3dc91d4338d6 ("SELinux: Fix possible NULL pointer
dereference in selinux_inode_permission()") didn't include the
i_security check.

Since this commit, the security_inode_free()'s header comment is no
longer correct because i_security is no longer set to NULL.

  reply	other threads:[~2024-07-10 13:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 19:32 [syzbot] [lsm?] general protection fault in hook_inode_free_security syzbot
2024-05-10  0:01 ` Paul Moore
2024-05-15 15:12   ` Mickaël Salaün
2024-05-16  7:31     ` Mickaël Salaün
2024-05-16 13:07       ` Mathieu Desnoyers
2024-06-27 13:33         ` Mickaël Salaün
2024-06-27 13:34       ` Mickaël Salaün
2024-06-27 18:12         ` Kees Cook
2024-06-27 18:45           ` Paul E. McKenney
2024-06-27 19:29           ` Paul Moore
2024-07-08 14:02           ` Mickaël Salaün
2024-07-08 19:25             ` Kees Cook
2024-07-09  5:12             ` Christian Brauner
2024-06-27 18:28         ` Paul Moore
2024-07-08 14:11           ` Mickaël Salaün
2024-07-08 22:32             ` Paul Moore
2024-07-09  5:46             ` Christian Brauner
2024-07-09 23:13               ` Paul Moore
2024-07-10  5:52             ` Christian Brauner
2024-07-10 12:23           ` Mickaël Salaün
2024-07-10 13:53             ` Mickaël Salaün [this message]
2024-07-10 21:22             ` Paul Moore
2024-07-11  0:30           ` Tetsuo Handa
2024-07-11 14:06             ` Paul Moore

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=20240710.Aephuhain8lu@digikod.net \
    --to=mic@digikod.net \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=jannh@google.com \
    --cc=jmorris@namei.org \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=paulmck@kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=syzbot+5446fbf332b0602ede0b@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=zohar@linux.ibm.com \
    /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).