From: Eric Biggers <ebiggers3@gmail.com>
To: Matt Brown <matt@nmatt.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
james.l.morris@oracle.com, serge@hallyn.com,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org,
kernel-hardening@lists.openwall.com
Subject: Re: [kernel-hardening] Re: [PATCH v1 1/1] Add Trusted Path Execution as a stackable LSM
Date: Sat, 3 Jun 2017 22:47:46 -0700 [thread overview]
Message-ID: <20170604054746.GC12095@zzz> (raw)
In-Reply-To: <a507374a-e1b9-de56-5d50-825c283111ca@nmatt.com>
On Sun, Jun 04, 2017 at 01:24:13AM -0400, Matt Brown wrote:
> On 06/03/2017 02:33 AM, Al Viro wrote:
> > On Sat, Jun 03, 2017 at 01:53:51AM -0400, Matt Brown wrote:
> >
> > > +static int tpe_bprm_set_creds(struct linux_binprm *bprm)
> > > +{
> > > + struct file *file = bprm->file;
> > > + struct inode *inode = d_backing_inode(file->f_path.dentry->d_parent);
> > > + struct inode *file_inode = d_backing_inode(file->f_path.dentry);
> >
> > Bloody wonderful. Do tell, what *does* prevent a race with rename(2) here,
> > somehow making sure that your 'inode' won't get freed right under you?
> >
>
> Good catch. How does this look:
>
> spin_lock(&inode->i_lock);
> spin_lock(&file_inode->i_lock);
> if (global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
> reason1 = "directory not owned by user";
> else if (inode->i_mode & 0002)
> reason1 = "file in world-writable directory";
> else if ((inode->i_mode & 0020) && global_nonroot_gid(inode->i_gid))
> reason1 = "file in group-writable directory";
> else if (file_inode->i_mode & 0002)
> reason1 = "file is world-writable";
> spin_unlock(&inode->i_lock);
> spin_unlock(&file_inode->i_lock);
>
> and likewise for other places in the code?
No, it needs to take a reference on the parent dentry before using it, using
dget_parent(), I think, and then dropping it later with dput(). Taking i_lock
isn't needed.
Eric
WARNING: multiple messages have this Message-ID (diff)
From: ebiggers3@gmail.com (Eric Biggers)
To: linux-security-module@vger.kernel.org
Subject: [kernel-hardening] Re: [PATCH v1 1/1] Add Trusted Path Execution as a stackable LSM
Date: Sat, 3 Jun 2017 22:47:46 -0700 [thread overview]
Message-ID: <20170604054746.GC12095@zzz> (raw)
In-Reply-To: <a507374a-e1b9-de56-5d50-825c283111ca@nmatt.com>
On Sun, Jun 04, 2017 at 01:24:13AM -0400, Matt Brown wrote:
> On 06/03/2017 02:33 AM, Al Viro wrote:
> > On Sat, Jun 03, 2017 at 01:53:51AM -0400, Matt Brown wrote:
> >
> > > +static int tpe_bprm_set_creds(struct linux_binprm *bprm)
> > > +{
> > > + struct file *file = bprm->file;
> > > + struct inode *inode = d_backing_inode(file->f_path.dentry->d_parent);
> > > + struct inode *file_inode = d_backing_inode(file->f_path.dentry);
> >
> > Bloody wonderful. Do tell, what *does* prevent a race with rename(2) here,
> > somehow making sure that your 'inode' won't get freed right under you?
> >
>
> Good catch. How does this look:
>
> spin_lock(&inode->i_lock);
> spin_lock(&file_inode->i_lock);
> if (global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
> reason1 = "directory not owned by user";
> else if (inode->i_mode & 0002)
> reason1 = "file in world-writable directory";
> else if ((inode->i_mode & 0020) && global_nonroot_gid(inode->i_gid))
> reason1 = "file in group-writable directory";
> else if (file_inode->i_mode & 0002)
> reason1 = "file is world-writable";
> spin_unlock(&inode->i_lock);
> spin_unlock(&file_inode->i_lock);
>
> and likewise for other places in the code?
No, it needs to take a reference on the parent dentry before using it, using
dget_parent(), I think, and then dropping it later with dput(). Taking i_lock
isn't needed.
Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-06-04 5:47 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-03 5:53 [kernel-hardening] [PATCH v1 1/1] Add Trusted Path Execution as a stackable LSM Matt Brown
2017-06-03 5:53 ` Matt Brown
2017-06-03 5:53 ` Matt Brown
2017-06-03 6:33 ` [kernel-hardening] " Al Viro
2017-06-03 6:33 ` Al Viro
2017-06-03 6:33 ` Al Viro
2017-06-04 5:24 ` [kernel-hardening] " Matt Brown
2017-06-04 5:24 ` Matt Brown
2017-06-04 5:24 ` Matt Brown
2017-06-04 5:47 ` Eric Biggers [this message]
2017-06-04 5:47 ` [kernel-hardening] " Eric Biggers
2017-06-04 12:43 ` Matt Brown
2017-06-04 12:43 ` Matt Brown
2017-06-04 6:51 ` Al Viro
2017-06-04 6:51 ` Al Viro
2017-06-04 6:51 ` Al Viro
2017-06-03 10:39 ` [kernel-hardening] " Jann Horn
2017-06-03 10:39 ` Jann Horn
2017-06-03 22:30 ` Matt Brown
2017-06-03 22:30 ` Matt Brown
2017-06-03 15:47 ` Solar Designer
2017-06-03 15:59 ` Greg KH
2017-06-03 16:22 ` Solar Designer
2017-06-03 17:16 ` Daniel Micay
2017-06-03 22:02 ` Nicolas Belouin
2017-06-03 21:55 ` Corey Henderson
2017-06-03 16:13 ` Solar Designer
2017-06-05 14:41 ` Matt Brown
2017-06-05 15:23 ` Solar Designer
2017-06-04 16:43 ` Mickaël Salaün
2017-06-04 22:07 ` Mickaël Salaün
2017-06-05 15:30 ` [kernel-hardening] " Alan Cox
2017-06-05 15:30 ` Alan Cox
2017-06-05 15:30 ` Alan Cox
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=20170604054746.GC12095@zzz \
--to=ebiggers3@gmail.com \
--cc=james.l.morris@oracle.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=matt@nmatt.com \
--cc=serge@hallyn.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.