From: "David P. Quigley" <dpquigl@tycho.nsa.gov>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: jmorris@namei.org, gregkh@suse.de, sds@tycho.nsa.gov,
Casey Schaufler <casey@schaufler-ca.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Security/sysfs: Enable security xattrs to be set on sysfs files, directories, and symlinks.
Date: Mon, 13 Jul 2009 15:18:25 -0400 [thread overview]
Message-ID: <1247512705.4398.292.camel@localhost> (raw)
In-Reply-To: <m1zlb8a5n5.fsf@fess.ebiederm.org>
[ Inline Comments...]
On Mon, 2009-07-13 at 09:50 -0700, Eric W. Biederman wrote:
> Taking the conversation back on the list.
>
> "David P. Quigley" <dpquigl@tycho.nsa.gov> writes:
>
> > On Sun, 2009-07-12 at 07:51 -0700, Eric W. Biederman wrote:
> >> "David P. Quigley" <dpquigl@tycho.nsa.gov> writes:
> >>
> >> > This patch adds a setxattr handler to the file, directory, and symlink
> >> > inode_operations structures for sysfs. This handler uses two new LSM hooks. The
> >> > first hook takes the xattr name and value and turns the context into a secid.
> >> > This is embedded into the sysfs_dirent structure so it remains persistent even
> >> > if the inode structures are evicted from the cache. The second hook allows for
> >> > the secid to be taken from the sysfs_dirent and be pushed into the inode
> >> > structure as the actual secid for the inode.
> >> >
> >> > This patch addresses an issue where SELinux was denying KVM access to the PCI
> >> > configuration entries in sysfs. The lack of setxattr handlers for sysfs
> >> > required that a single label be assigned to all entries in sysfs. Granting KVM
> >> > access to every entry in sysfs is not an acceptable solution so fine grained
> >> > labeling of sysfs is required such that individual entries can be labeled
> >> > appropriately.
> >>
> >> You are talking about write access from KVM?
> >>
> >> How can direct hardware access to something that can do arbitrary
> >> DMAs be secure?
> >
> > The bug in question is listed below.
> >
> > https://bugzilla.redhat.com/show_bug.cgi?id=499259
>
> I see a discussion, but no discuss of the security of direct hardware
> access of a DMA capable device.
So after reading through this again the problem isn't with KVM its with
libvirtd and other libvirt related programs.
>
> >> > diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
> >> > index 3fa0d98..732d183 100644
> >> > --- a/fs/sysfs/sysfs.h
> >> > +++ b/fs/sysfs/sysfs.h
> >> > @@ -57,6 +57,7 @@ struct sysfs_dirent {
> >> > ino_t s_ino;
> >> > umode_t s_mode;
> >> > struct iattr *s_iattr;
> >> > + u32 s_secid;
> >> > };
> >>
> >> Could you please expand s_iattr and store the secid there?
> >> That is where all of the rest of the security information is
> >> stored in sysfs.
> >
> > I'm sorry but doing that would make the security labels first class
> > attributes. It was decided a long time ago that security labels are
> > stored in xattrs and as such don't belong in the iattr structure. I
> > tried placing the label in the iattr structure for the Labeled NFS code
> > and Christoph told me to do it another way since he didn't find that
> > approach acceptable. I'm assuming his response will be the same for a
> > secid which is supposed to be very sparingly used outside of the
> > security module.
>
> What I mean is something like:
>
> struct sysfs_iattr {
> struct iattr s_iattr;
> u32 s_secid;
> };
>
> struct sysfs_dirent {
> ...
> ino_t s_ino;
> umode_t s_mode;
> struct sysfs_inode_attr *s_iattr;
> };
>
> The point is to simply allocate all of this optional stuff together,
> and not use two fields in sysfs_dirent.
>
> sysfs by default keeps a very sparse inode because it can assume
> default values for all of the fields, and only bothers to keep
> the extra fields when someone changes things explicitly. Like your
> xattrs, the uid or the gid.
Looking at the sysfs code I can see where the inode gets its default
values for everything but uid and gid. Are those set somewhere higher up
in the vfs on the init_inode path? The approach does seem reasonable but
do we want to have to allocate an entire iattr structure inside the
sysfs_inode_attr structure you propose just to store the secid?
>
> >> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> >> > index 2081055..395c36d 100644
> >> > --- a/security/selinux/hooks.c
> >> > +++ b/security/selinux/hooks.c
> >> > @@ -448,6 +448,10 @@ static int sb_finish_set_opts(struct super_block *sb)
> >> > sbsec->behavior > ARRAY_SIZE(labeling_behaviors))
> >> > sbsec->flags &= ~SE_SBLABELSUPP;
> >> >
> >> > + /* Special handling for sysfs. Is genfs but also has setxattr handler*/
> >> > + if (strncmp(sb->s_type->name, "sysfs", sizeof("sysfs")) == 0)
> >> > + sbsec->flags |= SE_SBLABELSUPP;
> >>
> >> What is this about? My impression is that if we have generic xattr
> >> handling sysfs is not special so why do we have a special case?
> >>
> >> Is this interface appropriate for dealing with xattrs to all
> >> linux virtual filesystmes similar to sysfs that do not currently
> >> implement xattrs. aka debugfs, proc, etc?
> >
> > Even though sysfs has a setxattr handler the labeling behavior with
> > respect to SELinux needs special handling. The idea here is that by
> > default sysfs will be labeled across the board with the same label. The
> > reason we can't use a normal style xattr handler here is because there
> > is no original backing store to pull the label from. Only after a label
> > has been changed is there a semi-persistent value that can be used for
> > reinstantiating the inode in the case that it is pruned from the cache.
> > Otherwise it falls back to the base genfs labeling of sysfs entries as
> > sysfs_t.
>
> Sounds like we want a mount option or the like here. Something explicit
> in sysfs not something explicit in the security module.
>
> I am also a bit dubious about
I don't think a mount option is the best thing here. Labeling behavior
is something that is LSM dependent and even file system dependent within
certain LSMs. Since I don't speak for Casey that the way SELinux handles
sysfs is the way he want's Smack handling sysfs, and we can't tell what
future label based LSMs will do I think leaving it to the module to
decide is best.
>
>
> > Proc also has some special case handling in the SELinux module but I
> > haven't had a chance to look at it and try to understand why. I don't
> > think that this would be a general purpose solution for all pseudo file
> > systems like you mentioned above but it may work for some of them. I'll
> > look into them a bit more and then respond about them.
>
> Sounds good. If we are going to expand the LSM it would be good to design
> something decent instead of adding a nasty add-hoc case.
A quick look over proc and debugfs leads me to believe that a generic
mechanism for all of them short of adding generic xattr support to all
pseudo file systems would be tricky at best and even more add-hoc than
what we already do. There isn't any uniformity in the data structures
that are used in these file systems so even if we came up with a lazy
update mechanism for these attributes it looks like the implementation
would vary greatly depending on the file system. Even then it doesn't
change the add-hoc nature of the functionality as we are only trying to
handle security attributes.
The real solution which is a lot of work and I don't exactly know how I
would go about putting it together is to try to provide a generic xattr
mechanism for pseudo file systems. However I don't have any use cases
for the majority of the xattr name spaces. The only thing we have at the
moment that needs attention and only on sysfs is the security.* name
space. So trying to implement full-blown xattrs on sysfs seems like a
bunch of effort with no clear user for it.
>
> And on a silly note. Rumor has it that selinux has provable security.
> If so what impact does this change make to the proofs?
>
I'm not a formal methods person so you would have to consult with the
people who did that work to find out.
> Eric
next prev parent reply other threads:[~2009-07-13 19:28 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-08 17:28 [PATCH] Security/sysfs: Enable security xattrs to be set on sysfs files, directories, and symlinks David P. Quigley
2009-07-09 1:44 ` Casey Schaufler
2009-07-09 14:05 ` David P. Quigley
2009-07-09 14:49 ` Casey Schaufler
2009-07-09 14:56 ` David P. Quigley
2009-07-09 15:16 ` David P. Quigley
2009-07-09 15:16 ` Greg KH
2009-07-09 14:11 ` David P. Quigley
2009-07-09 17:26 ` David P. Quigley
2009-07-09 17:50 ` Greg KH
2009-07-09 19:32 ` David P. Quigley
2009-07-09 20:13 ` Greg KH
2009-07-10 3:25 ` Casey Schaufler
2009-07-13 15:07 ` David P. Quigley
2009-07-09 15:18 ` Greg KH
2009-07-09 17:13 ` David P. Quigley
2009-07-09 17:52 ` Greg KH
2009-07-09 19:28 ` David P. Quigley
2009-07-09 20:12 ` Greg KH
2009-07-09 20:19 ` David P. Quigley
2009-07-09 20:41 ` Greg KH
2009-07-14 16:37 ` David P. Quigley
2009-07-14 17:50 ` Greg KH
2009-07-14 20:16 ` David P. Quigley
2009-07-14 20:35 ` Greg KH
2009-07-14 20:35 ` David P. Quigley
[not found] ` <m1r5wmnee0.fsf@fess.ebiederm.org>
[not found] ` <1247498399.4398.259.camel@localhost>
2009-07-13 16:50 ` Eric W. Biederman
2009-07-13 19:18 ` David P. Quigley [this message]
2009-07-14 0:29 ` Eric W. Biederman
2009-07-14 13:55 ` David P. Quigley
2009-07-14 3:06 ` Casey Schaufler
-- strict thread matches above, loose matches on Subject: below --
2009-07-15 13:48 David P. Quigley
2009-07-15 14:28 ` David P. Quigley
2009-07-15 14:31 ` David P. Quigley
2009-07-21 16:29 ` David P. Quigley
2009-07-21 16:49 ` Greg KH
2009-07-21 16:34 ` David P. Quigley
2009-07-21 17:01 ` David P. Quigley
2009-07-24 8:13 ` James Morris
2009-07-24 14:34 ` David P. Quigley
2009-07-24 14:54 ` Casey Schaufler
2009-08-14 4:59 ` Casey Schaufler
2009-08-14 12:20 ` Stephen Smalley
2009-08-14 12:40 ` Stephen Smalley
2009-08-15 1:33 ` Casey Schaufler
2009-08-17 12:01 ` Stephen Smalley
2009-08-15 1:19 ` Casey Schaufler
2009-08-17 11:53 ` Stephen Smalley
2009-08-14 22:02 ` Eric W. Biederman
2009-08-15 1:42 ` Casey Schaufler
2009-08-15 2:15 ` Eric W. Biederman
2009-08-15 4:56 ` Casey Schaufler
2009-08-15 6:01 ` Eric W. Biederman
2009-08-16 17:25 ` Casey Schaufler
2009-08-20 13:18 ` David P. Quigley
2009-08-21 3:38 ` Casey Schaufler
2009-09-03 18:25 David P. Quigley
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=1247512705.4398.292.camel@localhost \
--to=dpquigl@tycho.nsa.gov \
--cc=casey@schaufler-ca.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sds@tycho.nsa.gov \
/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