NFS/LSM: allow NFS to control all of its own mount options
Subsystems (5)
In the current code (approved by SELinux and NFS people in 2004) SELinux tries to understand NFS's binary mount data. This blows up in the face of things like nohide mounts which don't use struct nfs_mount_data and I assume just looking at the code that things don't work since NFS moved to using nfs_parsed_mount_data as its default binary mount data blob.
This patch moves all of the ownership of the mount options into NFS. It brings the text based mount options capabilities up to the same level of support which existed in version 6 of the old binary mount data from userspace. I am not looking at NFSv4 at the moment and the only mount option this is supporting is context= (just like the old binary support)
Basically this patch causes NFS to make use of the new LSM hooks security_sb_set_mnt_opts() and security_sb_clone_mnt_opts(). We do this in the NFS get_sb() calls so that security settings are set explicitly by NFS before they are set by the generic vfs security hooks which handle filesystems which use text mount data.
We need to push this for 2.6.25 since at the moment SELinux(or SMACK) + nohide mounts cause security_sb_copy_mount_data() to copy one page of mount data starting at the struct nfs_clone_mount_data on the stack. If the stack doesn't span 2 pages we run off the end of the stack and hit a page fault BUG(). Not sure why this didn't happen for me in 2.6.24, but my guess is the stack size is significantly smaller for this operation in 2.6.25 so the window is just bigger.
---
I tested mounting using both the version 6 binary mount data from userspace and using the text mount options in a simple program I wrote to call mount directly. I was able to correctly set the selinux context of my mounts and of clone mounts like those created by nohide exports.
This also fixes the BUG() in SMACK code because of the VFS change. SMACK may want to move to a BUG_ON() like I do in the selinux_sb_copy_data code just to make it clear binary mount data is not expected, but I'll leave that up to you.
fs/nfs/internal.h | 7 ++++++ fs/nfs/super.c | 31 ++++++++++++++++++++++++++-- fs/super.c | 2 +- security/security.c | 3 ++ security/selinux/hooks.c | 48 ++++++++++++++++++++------------------------- 5 files changed, 60 insertions(+), 31 deletions(-)
fs/nfs/internal.h +7 -0
@@ -14,6 +14,9 @@ struct nfs_string;*/ #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) +/* this MUST stay at least as large as the define in nfs_mount.h */ +#define NFS_MAX_INTERNAL_CONTEXT_LEN 256 +struct nfs_clone_mount {const struct super_block *sb;const struct dentry *dentry;
@@ -57,6 +60,10 @@ struct nfs_parsed_mount_data {char *export_path;int protocol; } nfs_server; + +struct { +char context[NFS_MAX_INTERNAL_CONTEXT_LEN +1 ]; + } lsm_opts; };/* client.c */
fs/nfs/super.c +28 -3
@@ -90,7 +90,7 @@ enum {/* Mount options that take string arguments */ Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_addr, Opt_mountaddr, Opt_clientaddr, Opt_context,/* Mount options that are ignored */ Opt_userspace, Opt_deprecated,
@@ -151,6 +151,8 @@ static match_table_t nfs_mount_option_tokens = { { Opt_mounthost, "mounthost=%s" }, { Opt_mountaddr, "mountaddr=%s" }, + { Opt_context, "context=%s" }, + { Opt_err, NULL } };
@@ -1025,7 +1027,15 @@ static int nfs_parse_mount_options(char *raw, &mnt->mount_server.addrlen);kfree (string);break ; - +case Opt_context: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; +/* last byte of the array will be 0 if arg too long */ +strncpy (mnt->lsm_opts.context, string, +NFS_MAX_CONTEXT_LEN ); +kfree (string); +break ;case Opt_userspace:case Opt_deprecated:break ;
@@ -1214,6 +1224,8 @@ static int nfs_validate_mount_data(void *options, args->namlen = data->namlen; args->bsize = data->bsize; args->auth_flavors[0 ] = data->pseudoflavor; +strncpy (args->lsm_opts.context, data->context, +NFS_MAX_CONTEXT_LEN +1 );break ;default : {unsigned int len;
@@ -1518,6 +1530,15 @@ static int nfs_get_sb(struct file_system_type *fs_type, s->s_flags |=MS_ACTIVE ; mnt->mnt_sb = s; mnt->mnt_root = mntroot; + +/* explicitly set lsm options, all we know is context= from SELinux */ +if (data.lsm_opts.context[0 ]) { +char *opt = data.lsm_opts.context; +int opt_num =CONTEXT_MNT ; + error =security_sb_set_mnt_opts (s, &opt, &opt_num,1 ); +if (error) + goto error_splat_root; + } error =0 ; out:
@@ -1528,7 +1549,8 @@ out: out_err_nosb:nfs_free_server (server); goto out; - +error_splat_root: +dput (mnt->mnt_root); error_splat_super:up_write (&s->s_umount);deactivate_super (s);
@@ -1608,6 +1630,9 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, mnt->mnt_sb = s; mnt->mnt_root = mntroot; +/* clone any lsm security options from the parent to the new sb */ +security_sb_clone_mnt_opts (data->sb, s); +dprintk ("<-- nfs_xdev_get_sb() = 0\n" );return 0 ;
fs/super.c +1 -1
@@ -870,7 +870,7 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, voidif (!mnt) goto out; -if (data) { +if (data && !(type->fs_flags &FS_BINARY_MOUNTDATA )) { secdata =alloc_secdata ();if (!secdata) goto out_mnt;
security/security.c +3 -0
@@ -311,6 +311,7 @@ int security_sb_get_mnt_opts(const struct super_block *sb, {return security_ops->sb_get_mnt_opts (sb, mount_options, flags, num_opts); } +EXPORT_SYMBOL (security_sb_get_mnt_opts); int security_sb_set_mnt_opts(struct super_block *sb, char **mount_options,
@@ -318,12 +319,14 @@ int security_sb_set_mnt_opts(struct super_block *sb, {return security_ops->sb_set_mnt_opts (sb, mount_options, flags, num_opts); } +EXPORT_SYMBOL (security_sb_set_mnt_opts);void security_sb_clone_mnt_opts (const struct super_block *oldsb,struct super_block *newsb) { security_ops->sb_clone_mnt_opts (oldsb, newsb); } +EXPORT_SYMBOL (security_sb_clone_mnt_opts);int security_inode_alloc (struct inode *inode) {
security/selinux/hooks.c +21 -27
78 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
A message that is not in the archive (sent off-list or not yet received): 1203457094.2928.113.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
-
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Christoph Hellwig
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
A library helper that looks like what?
Only NFS knows how it is storing that mount option in its blobs. Only NFS knows how to translate its blob into the generic LSM interface needed to set security options. I'd say the solution is going to have to be very much NFS specific.
Both in kernel LSMs already provide methods for dealing with mount options for filesystems that use text strings (see the security_sb_copy_data stuff called from vfs_kern_mount()). How is this 'library' going to deal with anything other than a text string, and if that's all it deals with we already have that. NFS just can't use it because it isn't using a string for mount data. I'm sure I'm just misunderstanding how to design your solution...
-Eric
Quoted 4 lines · --- Christoph Hellwig
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
Smack has options that are filesystem independent (smackfsdef= smackfsroot= smackfsfloor= smackfshat=) instead of the context= SELinux seems happy with. Since there is no reason that a file system even really needs to know what these values are it would be completely unreasonable to teach every filesystem about them. The information is completely controlled and used by the LSM.
Of course, we could use something other than mount options (vfsctl? sorry - only kidding) to set the LSM specific information, and that might be the right approach.
Casey Schaufler
[email protected]
James Morris
maintainerQuoted 4 lines · Christoph Hellwig
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
It's not so much a special case for NFS, just that NFS happens to use binary mount options. So, I guess it could be put into a library for other potential filesystems with binary mount options.
To clarify:
The SELinux options are indeed filesystem independent, and the FS should really not need to be concerned at all with them. For everything except NFS, we parse text options looking for context=, then use that value from within SELinux as the label for all files in the mount.
Previously, as Eric mentions, we were using a method initially approved by the NFS folk, where, for NFS, SELinux was peeking around inside the binary options. We were then asked to change that so that NFS (or other binary-option FS) would obtain the values itself and call into LSM with them. This is what Eric's latest patch enables (a previous patch installed the infrastructure for it).
While this code could be put into a library if desired, there is no need to make any changes for filesystems with text options (i.e. the general case).
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 25 lines · James Morris
Quoted 4 lines · Christoph Hellwig
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
It's not so much a special case for NFS, just that NFS happens to use binary mount options. So, I guess it could be put into a library for other potential filesystems with binary mount options.
To clarify:
The SELinux options are indeed filesystem independent, and the FS should really not need to be concerned at all with them. For everything except NFS, we parse text options looking for context=, then use that value from within SELinux as the label for all files in the mount.
Previously, as Eric mentions, we were using a method initially approved by the NFS folk, where, for NFS, SELinux was peeking around inside the binary options. We were then asked to change that so that NFS (or other binary-option FS) would obtain the values itself and call into LSM with them. This is what Eric's latest patch enables (a previous patch installed the infrastructure for it).
Quoted 3 lines
While this code could be put into a library if desired, there is no need to make any changes for filesystems with text options (i.e. the general case).
And to be clear: this patch fixes a real bug in the nfs/selinux interaction on nohide mounts, a bug that needs to be fixed upstream as soon as possible. A bug that was introduced by changes in nfs, not changes in selinux AFAIK, given that the original approach to context mounts was introduced and approved by nfs folks long ago. So regardless of what happens wrt the text mount options, this patch needs to get merged.
Signature · 2 lines
Stephen Smalley National Security Agency
Quoted 4 lines
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
Hmm, looks like selinux is not showing it's mount options in /proc/mounts. Well, actually there's no infrastructure for it either. Here's a template patch (completely untested).
Selinux guys, please fill in the details and submit, thanks.
fs/namespace.c +1 -0
@@ -385,6 +385,7 @@ static int show_vfsmnt(struct seq_file *if (mnt->mnt_flags & fs_infop->flag)seq_puts (m, fs_infop->str); } +security_sb_show_options (m, mnt->mnt_sb);if (mnt->mnt_sb->s_op->show_options) err = mnt->mnt_sb->s_op->show_options (m, mnt);seq_puts (m," 0 0\n" );
include/linux/security.h +9 -0
@@ -80,6 +80,7 @@ struct xfrm_selector;struct xfrm_policy ;struct xfrm_state ;struct xfrm_user_sec_ctx ; +struct seq_file ;extern int cap_netlink_send (struct sock *sk,struct sk_buff *skb);extern int cap_netlink_recv (struct sk_buff *skb,int cap);
@@ -1226,6 +1227,7 @@ struct security_operations {int (*sb_copy_data)(struct file_system_type *type,void *orig,void *copy);int (*sb_kern_mount) (struct super_block *sb,void *data); +int (*sb_show_options) (struct seq_file *,struct super_block *sb);int (*sb_statfs) (struct dentry *dentry);int (*sb_mount) (char *dev_name,struct nameidata * nd,char *type,unsigned long flags,void *data);
@@ -1487,6 +1489,7 @@ int security_sb_alloc(struct super_blockvoid security_sb_free (struct super_block *sb);int security_sb_copy_data (struct file_system_type *type,void *orig,void *copy);int security_sb_kern_mount (struct super_block *sb,void *data); +int security_sb_show_options (struct seq_file *,struct super_block *sb);int security_sb_statfs (struct dentry *dentry);int security_sb_mount (char *dev_name,struct nameidata *nd,char *type,unsigned long flags,void *data);
@@ -1744,6 +1747,12 @@ static inline int security_sb_kern_mountreturn 0 ; } +static inline int security_sb_show_options (struct seq_file *m, +struct super_block *sb) +{ +return 0 ; +} +static inline int security_sb_statfs (struct dentry *dentry) {return 0 ;
security/security.c +8 -0
@@ -252,6 +252,14 @@ int security_sb_kern_mount(struct super_return security_ops->sb_kern_mount (sb, data); } +int security_sb_show_options (struct seq_file *m,struct super_block *sb) +{ +if (security_ops->sb_show_options) +return security_ops->sb_show_options (m, sb); +else +return 0 ; +} +int security_sb_statfs (struct dentry *dentry) {return security_ops->sb_statfs (dentry);
security/selinux/hooks.c +7 -0
@@ -590,6 +590,12 @@ out:return rc; } +static int selinux_sb_show_options (struct seq_file *m,struct super_block *sb) +{ +/* ... */ +return 0 ; +} +static int superblock_doinit (struct super_block *sb,void *data) {struct superblock_security_struct *sbsec = sb->s_security;
@@ -4797,6 +4803,7 @@ static struct security_operations selinu .sb_free_security = selinux_sb_free_security, .sb_copy_data = selinux_sb_copy_data, .sb_kern_mount = selinux_sb_kern_mount, + .sb_show_options = selinux_sb_show_options, .sb_statfs = selinux_sb_statfs, .sb_mount = selinux_mount, .sb_umount = selinux_umount,
Quoted 8 lines · Miklos Szeredi
Quoted 4 lines
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
Hmm, looks like selinux is not showing it's mount options in
/proc/mounts. Well, actually there's no infrastructure for it either. Here's a template patch (completely untested).
I think the intent is to use the security_sb_get_mnt_opts() hook for this purpose.
Quoted 107 lines
Selinux guys, please fill in the details and submit, thanks.
Signed-off-by Miklos Szeredi <[email protected]>Index:
linux/fs/namespace.c
===================================================================fs/namespace.c +1
-0@@ -385,6 +385,7 @@ static int show_vfsmnt(struct seq_file *if (mnt->mnt_flags & fs_infop->flag)seq_puts (m, fs_infop->str); } +security_sb_show_options (m, mnt->mnt_sb);if (mnt->mnt_sb->s_op->show_options) err = mnt->mnt_sb->s_op->show_options (m, mnt);seq_puts (m," 0 0\n" );Index:
linux/include/linux/security.h
===================================================================include/linux/security.h +9
-0@@ -80,6 +80,7 @@ struct xfrm_selector;struct xfrm_policy ;struct xfrm_state ;struct xfrm_user_sec_ctx ; +struct seq_file ;extern int cap_netlink_send (struct sock *sk,struct sk_buff *skb);extern int cap_netlink_recv (struct sk_buff *skb,int cap);@@ -1226,6 +1227,7 @@ struct security_operations {int (*sb_copy_data)(struct file_system_type *type,void *orig,void *copy);int (*sb_kern_mount) (struct super_block *sb,void *data); +int (*sb_show_options) (struct seq_file *,struct super_block *sb);int (*sb_statfs) (struct dentry *dentry);int (*sb_mount) (char *dev_name,struct nameidata * nd,char *type,unsigned long flags,void *data);@@ -1487,6 +1489,7 @@ int security_sb_alloc(struct super_blockvoid security_sb_free (struct super_block *sb);int security_sb_copy_data (struct file_system_type *type,void *orig,void *copy);int security_sb_kern_mount (struct super_block *sb,void *data); +int security_sb_show_options (struct seq_file *,struct super_block *sb);int security_sb_statfs (struct dentry *dentry);int security_sb_mount (char *dev_name,struct nameidata *nd,char *type,unsigned long flags,void *data);@@ -1744,6 +1747,12 @@ static inline int security_sb_kern_mountreturn 0 ; } +static inline int security_sb_show_options (struct seq_file *m, +struct super_block *sb) +{ +return 0 ; +} +static inline int security_sb_statfs (struct dentry *dentry) {return 0 ;Index:
linux/security/security.c
===================================================================security/security.c +8
-0@@ -252,6 +252,14 @@ int security_sb_kern_mount(struct super_return security_ops->sb_kern_mount (sb, data); } +int security_sb_show_options (struct seq_file *m,struct super_block *sb) +{ +if (security_ops->sb_show_options) +return security_ops->sb_show_options (m, sb); +else +return 0 ; +} +int security_sb_statfs (struct dentry *dentry) {return security_ops->sb_statfs (dentry);Index:
linux/security/selinux/hooks.c
===================================================================security/selinux/hooks.c +7
-1@@ -590,6 +590,12 @@ out:return rc; } +static int selinux_sb_show_options (struct seq_file *m,struct super_block *sb) +{ +/* ... */ +return 0 ; +} +static int superblock_doinit (struct super_block *sb,void *data) {struct superblock_security_struct *sbsec = sb->s_security;@@ -4797,6 +4803,7 @@ static struct security_operations selinu .sb_free_security = selinux_sb_free_security, .sb_copy_data = selinux_sb_copy_data, .sb_kern_mount = selinux_sb_kern_mount, + .sb_show_options = selinux_sb_show_options, .sb_statfs = selinux_sb_statfs, .sb_mount = selinux_mount, .sb_umount = selinux_umount, -To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Stephen Smalley National Security Agency
A message that is not in the archive (sent off-list or not yet received): 1203515410.9902.128.camel-/[email protected]
Quoted 6 lines · Stephen Smalley
Quoted 5 lines · Miklos Szeredi
Quoted 4 lines
Please don't introduce a special case for just nfs. All filesystems should control their mount options, so please provide some library helpers for context= handling and move it into all filesystems that can support selinux.
Quoted 6 lines
Quoted 3 lines
Hmm, looks like selinux is not showing it's mount options in
/proc/mounts. Well, actually there's no infrastructure for it either. Here's a template patch (completely untested).I think the intent is to use the
security_sb_get_mnt_opts()hook for this purpose.
It was. I already knew about this issue and its 'on my list.' Although I guess we need a something ?new LSM hook? which will translate the sb_get_mnt_opts stuff into a single text string. Or I guess really that can be done in you sb_show_options and I can just use sb_get_mnt_opts under the covers. Anyway, unrelated issue that will get fixed as soon as this real BUG() is fixed.
-Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html