nfs: 3.9-rc3 release (v2)
Subsystems (5)
cover nfs: 3.9-rc3 release (v2)
From: Steve Dickson <[email protected]>
A bug was found in the READDIR code with v4.1 and v4.2 mounts which caused the client to request an attribute it did not support. Only v4.0 mounts were tested at Connectathon.
The v4.2 enabling code will be coming in the next few days. It just needs a little more testing.
Dave Quigley (2):
NFS:Add labels to client function prototypes
NFS: Add label lifecycle management
David Quigley (10):
Security: Add hook to calculate context based on a negative dentry.
Security: Add Hook to test if the particular xattr is part of a MAC
model.
LSM: Add flags field to security_sb_set_mnt_opts for in kernel mount
data.
SELinux: Add new labeling type native labels
NFSv4: Add label recommended attribute and NFSv4 flags
NFSv4: Introduce new label structure
NFSv4: Extend fattr bitmaps to support all 3 words
NFS: Client implementation of Labeled-NFS
NFS: Extend NFS xattr handlers to accept the security namespace
NFSD: Server implementation of MAC Labeling
Steve Dickson (2):
Kconfig: Add Kconfig entry for Labeled NFS V4 client
Kconfig: Add Kconfig entry for Labeled NFS V4 server
fs/nfs/Kconfig | 18 ++ fs/nfs/client.c | 2 +- fs/nfs/dir.c | 46 ++- fs/nfs/getroot.c | 2 +- fs/nfs/inode.c | 129 +++++++-- fs/nfs/namespace.c | 2 +- fs/nfs/nfs3acl.c | 4 +- fs/nfs/nfs3proc.c | 41 +-- fs/nfs/nfs4_fs.h | 8 +- fs/nfs/nfs4namespace.c | 2 +- fs/nfs/nfs4proc.c | 563 ++++++++++++++++++++++++++++++++---- fs/nfs/nfs4xdr.c | 188 +++++++++--- fs/nfs/proc.c | 15 +- fs/nfs/super.c | 17 +- fs/nfsd/Kconfig | 16 + fs/nfsd/nfs4proc.c | 41 +++ fs/nfsd/nfs4xdr.c | 116 +++++++- fs/nfsd/nfsd.h | 6 +- fs/nfsd/vfs.c | 29 ++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 + include/linux/nfs4.h | 8 + include/linux/nfs_fs.h | 30 +- include/linux/nfs_fs_sb.h | 10 +- include/linux/nfs_xdr.h | 30 +- include/linux/security.h | 57 +++- include/uapi/linux/nfs4.h | 2 +- security/capability.c | 19 +- security/security.c | 24 +- security/selinux/hooks.c | 92 +++++- security/selinux/include/security.h | 2 + security/selinux/ss/policydb.c | 5 +- security/smack/smack_lsm.c | 11 + 33 files changed, 1328 insertions(+), 212 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/14 Security: Add hook to calculate context based on a negative dentry.
From: David Quigley <[email protected]>
There is a time where we need to calculate a context without the inode having been created yet. To do this we take the negative dentry and calculate a context based on the process and the parent directory contexts.
--- include/linux/security.h | 27 +++++++++++++++++++++++++++ security/capability.c | 8 ++++++++ security/security.c | 10 ++++++++++ security/selinux/hooks.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+)
include/linux/security.h +27 -0
@@ -26,6 +26,7 @@#include <linux/capability.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/string.h> struct linux_binprm ;struct cred ;
@@ -306,6 +307,15 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* Parse a string of security data filling in the opts structure * @options string containing all mount options known by the LSM * @opts binary data structure usable by the LSM +* @dentry_init_security: +* Compute a context for a dentry as the inode is not yet available +* since NFSv4 has no label backed by an EA anyway. +* @dentry dentry to use in calculating the context. +* @mode mode used to determine resource type. +* @name name of the last path component used to create file +* @ctx pointer to place the pointer to the resulting context in. +* @ctxlen point to place the length of the resulting context. +* * * Security hooks for inode operations. *
@@ -1439,6 +1449,10 @@ struct security_operations {void (*sb_clone_mnt_opts) (const struct super_block *oldsb,struct super_block *newsb);int (*sb_parse_opts_str) (char *options,struct security_mnt_opts *opts); +int (*dentry_init_security) (struct dentry *dentry,int mode, +struct qstr *name,void **ctx, +u32 *ctxlen); +#ifdef CONFIG_SECURITY_PATH int (*path_unlink) (struct path *dir,struct dentry *dentry);
@@ -1724,6 +1738,9 @@ int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *ovoid security_sb_clone_mnt_opts (const struct super_block *oldsb,struct super_block *newsb);int security_sb_parse_opts_str (char *options,struct security_mnt_opts *opts); +int security_dentry_init_security (struct dentry *dentry,int mode, +struct qstr *name,void **ctx, +u32 *ctxlen);int security_inode_alloc (struct inode *inode);void security_inode_free (struct inode *inode);
@@ -2028,6 +2045,16 @@ static inline int security_inode_alloc(struct inode *inode)static inline void security_inode_free (struct inode *inode) { } +static inline int security_dentry_init_security (struct dentry *dentry, +int mode, +struct qstr *name, +void **ctx, +u32 *ctxlen) +{ +return -EOPNOTSUPP ; +} + + static inline int security_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr,
security/capability.c +8 -0
@@ -108,6 +108,13 @@ static int cap_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)return 0 ; } +static int cap_dentry_init_security (struct dentry *dentry,int mode, +struct qstr *name,void **ctx, +u32 *ctxlen) +{ +return 0 ; +} +static int cap_inode_alloc_security (struct inode *inode) {return 0 ;
@@ -925,6 +932,7 @@ void __init security_fixup_ops(struct security_operations *ops)set_to_cap_if_null (ops, sb_set_mnt_opts);set_to_cap_if_null (ops, sb_clone_mnt_opts);set_to_cap_if_null (ops, sb_parse_opts_str); +set_to_cap_if_null (ops, dentry_init_security);set_to_cap_if_null (ops, inode_alloc_security);set_to_cap_if_null (ops, inode_free_security);set_to_cap_if_null (ops, inode_init_security);
security/security.c +10 -0
@@ -12,6 +12,7 @@*/ #include <linux/capability.h> +#include <linux/dcache.h> #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h>
@@ -324,6 +325,15 @@ void security_inode_free(struct inode *inode) security_ops->inode_free_security (inode); } +int security_dentry_init_security (struct dentry *dentry,int mode, +struct qstr *name,void **ctx, +u32 *ctxlen) +{ +return security_ops->dentry_init_security (dentry, mode, name, + ctx, ctxlen); +} +EXPORT_SYMBOL (security_dentry_init_security); +int security_inode_init_security (struct inode *inode,struct inode *dir,const struct qstr *qstr,const initxattrs initxattrs,void *fs_data)
security/selinux/hooks.c +35 -0
@@ -2483,6 +2483,40 @@ static void selinux_inode_free_security(struct inode *inode)inode_free_security (inode); } +static int selinux_dentry_init_security (struct dentry *dentry,int mode, +struct qstr *name,void **ctx, +u32 *ctxlen) +{ +const struct cred *cred =current_cred (); +struct task_security_struct *tsec; +struct inode_security_struct *dsec; +struct superblock_security_struct *sbsec; +struct inode *dir = dentry->d_parent->d_inode; +u32 newsid; +int rc; + + tsec = cred->security; + dsec = dir->i_security; + sbsec = dir->i_sb->s_security; + +if (tsec->create_sid && sbsec->behavior !=SECURITY_FS_USE_MNTPOINT ) { + newsid = tsec->create_sid; + }else { + rc =security_transition_sid (tsec->sid, dsec->sid, +inode_mode_to_security_class (mode), + name, + &newsid); +if (rc) { +printk (KERN_WARNING +"%s: security_transition_sid failed, rc=%d\n" , + __func__, -rc); +return rc; + } + } + +return security_sid_to_context (newsid, (char **)ctx, ctxlen); +} +static int selinux_inode_init_security (struct inode *inode,struct inode *dir,const struct qstr *qstr,char **name,void **value,size_t *len)
@@ -5525,6 +5559,7 @@ static struct security_operations selinux_ops = { .sb_clone_mnt_opts = selinux_sb_clone_mnt_opts, .sb_parse_opts_str = selinux_parse_opts_str, + .dentry_init_security = selinux_dentry_init_security, .inode_alloc_security = selinux_inode_alloc_security, .inode_free_security = selinux_inode_free_security,
Signature · 1 line
1.8.1.4
PATCH 2/14 Security: Add Hook to test if the particular xattr is part of a MAC model.
In reply to Steve DicksonFrom: David Quigley <[email protected]>
The interface to request security labels from user space is the xattr interface. When requesting the security label from an NFS server it is important to make sure the requested xattr actually is a MAC label. This allows us to make sure that we get the desired semantics from the attribute instead of something else such as capabilities or a time based LSM.
--- include/linux/security.h | 14 ++++++++++++++ security/capability.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ security/smack/smack_lsm.c | 11 +++++++++++ 5 files changed, 43 insertions(+)
include/linux/security.h +14 -0
@@ -1319,6 +1319,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @pages contains the number of pages. * Return 0 if permission is granted. * +* @ismaclabel: +* Check if the extended attribute specified by @name +* represents a MAC label. Returns 0 if name is a MAC +* attribute otherwise returns non-zero. +* @name full extended attribute name to check against +* LSM as a MAC label. +* * @secid_to_secctx: * Convert secid to security context. If secdata is NULL the length of * the result will be returned in seclen, but no secdata will be returned.
@@ -1600,6 +1607,7 @@ struct security_operations {int (*getprocattr) (struct task_struct *p,char *name,char **value);int (*setprocattr) (struct task_struct *p,char *name,void *value,size_t size); +int (*ismaclabel) (const char *name);int (*secid_to_secctx) (u32 secid,char **secdata,u32 *seclen);int (*secctx_to_secid) (const char *secdata,u32 seclen,u32 *secid);void (*release_secctx) (char *secdata,u32 seclen);
@@ -1852,6 +1860,7 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode);int security_getprocattr (struct task_struct *p,char *name,char **value);int security_setprocattr (struct task_struct *p,char *name,void *value,size_t size);int security_netlink_send (struct sock *sk,struct sk_buff *skb); +int security_ismaclabel (const char *name);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen);int security_secctx_to_secid (const char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen);
@@ -2540,6 +2549,11 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)return cap_netlink_send (sk, skb); } +static inline int security_ismaclabel (const char *name) +{ +return 0 ; +} +static inline int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;
security/capability.c +6 -0
@@ -817,6 +817,11 @@ static int cap_setprocattr(struct task_struct *p, char *name, void *value,return -EINVAL ; } +static int cap_ismaclabel (const char *name) +{ +return 0 ; +} +static int cap_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;
@@ -1036,6 +1041,7 @@ void __init security_fixup_ops(struct security_operations *ops)set_to_cap_if_null (ops, d_instantiate);set_to_cap_if_null (ops, getprocattr);set_to_cap_if_null (ops, setprocattr); +set_to_cap_if_null (ops, ismaclabel);set_to_cap_if_null (ops, secid_to_secctx);set_to_cap_if_null (ops, secctx_to_secid);set_to_cap_if_null (ops, release_secctx);
security/security.c +6 -0
@@ -1057,6 +1057,12 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb)return security_ops->netlink_send (sk, skb); } +int security_ismaclabel (const char *name) +{ +return security_ops->ismaclabel (name); +} +EXPORT_SYMBOL (security_ismaclabel); +int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_ops->secid_to_secctx (secid, secdata, seclen);
security/selinux/hooks.c +6 -0
@@ -5417,6 +5417,11 @@ abort_change:return error; } +static int selinux_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SELINUX_SUFFIX ) ==0 ); +} +static int selinux_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_sid_to_context (secid, secdata, seclen);
@@ -5655,6 +5660,7 @@ static struct security_operations selinux_ops = { .getprocattr = selinux_getprocattr, .setprocattr = selinux_setprocattr, + .ismaclabel = selinux_ismaclabel, .secid_to_secctx = selinux_secid_to_secctx, .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx,
security/smack/smack_lsm.c +11 -0
@@ -3329,6 +3329,16 @@ static void smack_audit_rule_free(void *vrule)#endif /* CONFIG_AUDIT */ /** +* smack_ismaclabel - check if xattr @name references a smack MAC label +* @name: Full xattr name to check. +*/ +static int smack_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SMACK_SUFFIX ) ==0 ); +} + + +/** * smack_secid_to_secctx - return the smack label for a secid * @secid: incoming integer * @secdata: destination
@@ -3524,6 +3534,7 @@ struct security_operations smack_ops = { .audit_rule_free = smack_audit_rule_free,#endif /* CONFIG_AUDIT */ + .ismaclabel = smack_ismaclabel, .secid_to_secctx = smack_secid_to_secctx, .secctx_to_secid = smack_secctx_to_secid, .release_secctx = smack_release_secctx,
Signature · 1 line
1.8.1.4
Re: [PATCH 02/14] Security: Add Hook to test if the particular xattr is part of a MAC model.
Quoted 25 lines · Steve Dickson
From: David Quigley <[email protected]>
The interface to request security labels from user space is the xattr interface. When requesting the security label from an NFS server it is important to make sure the requested xattr actually is a MAC label. This allows us to make sure that we get the desired semantics from the attribute instead of something else such as capabilities or a time based LSM.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- include/linux/security.h | 14 ++++++++++++++ security/capability.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ security/smack/smack_lsm.c | 11 +++++++++++ 5 files changed, 43 insertions(+)include/linux/security.h +0
-0
include/linux/security.h static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · line 1325
Quoted 7 lines
include/linux/security.h +4
-0@@ -1319,6 +1319,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @pages contains the number of pages. * Return 0 if permission is granted. * +* @ismaclabel: +* Check if the extended attribute specified by @name +* represents a MAC label. Returns 0 if name is a MAC +* attribute otherwise returns non-zero.
Sorry, the comment doesn't match the code.
Mimi
Quoted 130 lines
include/linux/security.h +3
-0+* @name full extended attribute name to check against +* LSM as a MAC label. +* * @secid_to_secctx: * Convert secid to security context. If secdata is NULL the length of
* the result will be returned in seclen, but no secdata will be returned.include/linux/security.h +7
-0@@ -1600,6 +1607,7 @@ struct security_operations {int (*getprocattr) (struct task_struct *p,char *name,char **value);int (*setprocattr) (struct task_struct *p,char *name,void *value,size_t size); +int (*ismaclabel) (const char *name);int (*secid_to_secctx) (u32 secid,char **secdata,u32 *seclen);int (*secctx_to_secid) (const char *secdata,u32 seclen,u32 *secid);void (*release_secctx) (char *secdata,u32 seclen);@@ -1852,6 +1860,7 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode);int security_getprocattr (struct task_struct *p,char *name,char **value);int security_setprocattr (struct task_struct *p,char *name,void *value,size_t size);int security_netlink_send (struct sock *sk,struct sk_buff *skb); +int security_ismaclabel (const char *name);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen);int security_secctx_to_secid (const char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen);@@ -2540,6 +2549,11 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)return cap_netlink_send (sk, skb); } +static inline int security_ismaclabel (const char *name) +{ +return 0 ; +} +static inline int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;security/capability.c +6
-0@@ -817,6 +817,11 @@ static int cap_setprocattr(struct task_struct *p, char *name, void *value,return -EINVAL ; } +static int cap_ismaclabel (const char *name) +{ +return 0 ; +} +static int cap_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;@@ -1036,6 +1041,7 @@ void __init security_fixup_ops(struct security_operations *ops)set_to_cap_if_null (ops, d_instantiate);set_to_cap_if_null (ops, getprocattr);set_to_cap_if_null (ops, setprocattr); +set_to_cap_if_null (ops, ismaclabel);set_to_cap_if_null (ops, secid_to_secctx);set_to_cap_if_null (ops, secctx_to_secid);set_to_cap_if_null (ops, release_secctx);security/security.c +6
-0@@ -1057,6 +1057,12 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb)return security_ops->netlink_send (sk, skb); } +int security_ismaclabel (const char *name) +{ +return security_ops->ismaclabel (name); +} +EXPORT_SYMBOL (security_ismaclabel); +int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_ops->secid_to_secctx (secid, secdata, seclen);security/selinux/hooks.c +6
-0@@ -5417,6 +5417,11 @@ abort_change:return error; } +static int selinux_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SELINUX_SUFFIX ) ==0 ); +} +static int selinux_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_sid_to_context (secid, secdata, seclen);@@ -5655,6 +5660,7 @@ static struct security_operations selinux_ops = { .getprocattr = selinux_getprocattr, .setprocattr = selinux_setprocattr, + .ismaclabel = selinux_ismaclabel, .secid_to_secctx = selinux_secid_to_secctx, .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx,security/smack/smack_lsm.c +11
-0@@ -3329,6 +3329,16 @@ static void smack_audit_rule_free(void *vrule)#endif /* CONFIG_AUDIT */ /** +* smack_ismaclabel - check if xattr @name references a smack MAC label +* @name: Full xattr name to check. +*/ +static int smack_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SMACK_SUFFIX ) ==0 ); +} + + +/** * smack_secid_to_secctx - return the smack label for a secid * @secid: incoming integer * @secdata: destination @@ -3524,6 +3534,7 @@ struct security_operations smack_ops = { .audit_rule_free = smack_audit_rule_free,#endif /* CONFIG_AUDIT */ + .ismaclabel = smack_ismaclabel, .secid_to_secctx = smack_secid_to_secctx, .secctx_to_secid = smack_secctx_to_secid, .release_secctx = smack_release_secctx,
Re: [PATCH 02/14] Security: Add Hook to test if the particular xattr is part of a MAC model.
Quoted 21 lines · Mimi Zohar
Quoted 20 lines · Steve Dickson
From: David Quigley <[email protected]>
The interface to request security labels from user space is the xattr interface. When requesting the security label from an NFS server it is important to make sure the requested xattr actually is a MAC label. This allows us to make sure that we get the desired semantics from the attribute instead of something else such as capabilities or a time based LSM.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- include/linux/security.h | 14 ++++++++++++++ security/capability.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ security/smack/smack_lsm.c | 11 +++++++++++ 5 files changed, 43 insertions(+)
Quoted 14 lines
include/linux/security.h static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · line 1325
Quoted 12 lines
include/linux/security.h +4
-0@@ -1319,6 +1319,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @pages contains the number of pages. * Return 0 if permission is granted. * +* @ismaclabel: +* Check if the extended attribute specified by @name +* represents a MAC label. Returns 0 if name is a MAC +* attribute otherwise returns non-zero. Sorry, the comment doesn't match the code.
Yeah, that looks backwards. Confirmed by looking at an implementation:
Quoted 5 lines
include/linux/security.h static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · line 1330
Quoted 5 lines
include/linux/security.h +5
-0+static int selinux_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SELINUX_SUFFIX ) ==0 ); +} +
Could we also make the return value bool to make it even less ambiguous?
--b.
Re: [PATCH 02/14] Security: Add Hook to test if the particular xattr is part of a MAC model.
In reply to Mimi ZoharQuoted 21 lines · Mimi Zohar
Quoted 20 lines · Steve Dickson
From: David Quigley <[email protected]>
The interface to request security labels from user space is the xattr interface. When requesting the security label from an NFS server it is important to make sure the requested xattr actually is a MAC label. This allows us to make sure that we get the desired semantics from the attribute instead of something else such as capabilities or a time based LSM.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- include/linux/security.h | 14 ++++++++++++++ security/capability.c | 6 ++++++ security/security.c | 6 ++++++ security/selinux/hooks.c | 6 ++++++ security/smack/smack_lsm.c | 11 +++++++++++ 5 files changed, 43 insertions(+)
Quoted 14 lines
include/linux/security.h static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · line 1325
Quoted 12 lines
include/linux/security.h +4
-0@@ -1319,6 +1319,13 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @pages contains the number of pages. * Return 0 if permission is granted. * +* @ismaclabel: +* Check if the extended attribute specified by @name +* represents a MAC label. Returns 0 if name is a MAC +* attribute otherwise returns non-zero. Sorry, the comment doesn't match the code.
Nice catch! thanks!
steved.
Quoted 136 lines
Mimi
Quoted 130 lines
include/linux/security.h +3
-0+* @name full extended attribute name to check against +* LSM as a MAC label. +* * @secid_to_secctx: * Convert secid to security context. If secdata is NULL the length of
* the result will be returned in seclen, but no secdata will be returned.include/linux/security.h +7
-0@@ -1600,6 +1607,7 @@ struct security_operations {int (*getprocattr) (struct task_struct *p,char *name,char **value);int (*setprocattr) (struct task_struct *p,char *name,void *value,size_t size); +int (*ismaclabel) (const char *name);int (*secid_to_secctx) (u32 secid,char **secdata,u32 *seclen);int (*secctx_to_secid) (const char *secdata,u32 seclen,u32 *secid);void (*release_secctx) (char *secdata,u32 seclen);@@ -1852,6 +1860,7 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode);int security_getprocattr (struct task_struct *p,char *name,char **value);int security_setprocattr (struct task_struct *p,char *name,void *value,size_t size);int security_netlink_send (struct sock *sk,struct sk_buff *skb); +int security_ismaclabel (const char *name);int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen);int security_secctx_to_secid (const char *secdata,u32 seclen,u32 *secid);void security_release_secctx (char *secdata,u32 seclen);@@ -2540,6 +2549,11 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)return cap_netlink_send (sk, skb); } +static inline int security_ismaclabel (const char *name) +{ +return 0 ; +} +static inline int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;security/capability.c +6
-0@@ -817,6 +817,11 @@ static int cap_setprocattr(struct task_struct *p, char *name, void *value,return -EINVAL ; } +static int cap_ismaclabel (const char *name) +{ +return 0 ; +} +static int cap_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;@@ -1036,6 +1041,7 @@ void __init security_fixup_ops(struct security_operations *ops)set_to_cap_if_null (ops, d_instantiate);set_to_cap_if_null (ops, getprocattr);set_to_cap_if_null (ops, setprocattr); +set_to_cap_if_null (ops, ismaclabel);set_to_cap_if_null (ops, secid_to_secctx);set_to_cap_if_null (ops, secctx_to_secid);set_to_cap_if_null (ops, release_secctx);security/security.c +6
-0@@ -1057,6 +1057,12 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb)return security_ops->netlink_send (sk, skb); } +int security_ismaclabel (const char *name) +{ +return security_ops->ismaclabel (name); +} +EXPORT_SYMBOL (security_ismaclabel); +int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_ops->secid_to_secctx (secid, secdata, seclen);security/selinux/hooks.c +6
-0@@ -5417,6 +5417,11 @@ abort_change:return error; } +static int selinux_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SELINUX_SUFFIX ) ==0 ); +} +static int selinux_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return security_sid_to_context (secid, secdata, seclen);@@ -5655,6 +5660,7 @@ static struct security_operations selinux_ops = { .getprocattr = selinux_getprocattr, .setprocattr = selinux_setprocattr, + .ismaclabel = selinux_ismaclabel, .secid_to_secctx = selinux_secid_to_secctx, .secctx_to_secid = selinux_secctx_to_secid, .release_secctx = selinux_release_secctx,security/smack/smack_lsm.c +11
-0@@ -3329,6 +3329,16 @@ static void smack_audit_rule_free(void *vrule)#endif /* CONFIG_AUDIT */ /** +* smack_ismaclabel - check if xattr @name references a smack MAC label +* @name: Full xattr name to check. +*/ +static int smack_ismaclabel (const char *name) +{ +return (strcmp (name,XATTR_SMACK_SUFFIX ) ==0 ); +} + + +/** * smack_secid_to_secctx - return the smack label for a secid * @secid: incoming integer * @secdata: destination @@ -3524,6 +3534,7 @@ struct security_operations smack_ops = { .audit_rule_free = smack_audit_rule_free,#endif /* CONFIG_AUDIT */ + .ismaclabel = smack_ismaclabel, .secid_to_secctx = smack_secid_to_secctx, .secctx_to_secid = smack_secctx_to_secid, .release_secctx = smack_release_secctx,
PATCH 3/14 LSM: Add flags field to security_sb_set_mnt_opts for in kernel mount data.
In reply to Steve DicksonFrom: David Quigley <[email protected]>
There is no way to differentiate if a text mount option is passed from user space or the kernel. A flags field is being added to the security_sb_set_mnt_opts hook to allow for in kernel security flags to be sent to the LSM for processing in addition to the text options received from mount. This patch also updated existing code to fix compilation errors.
--- fs/nfs/super.c | 3 ++- include/linux/security.h | 13 ++++++++++--- security/capability.c | 5 ++++- security/security.c | 7 +++++-- security/selinux/hooks.c | 12 ++++++++++-- 5 files changed, 31 insertions(+), 9 deletions(-)
fs/nfs/super.c +2 -1
@@ -2373,7 +2373,8 @@ static int nfs_bdi_register(struct nfs_server *server)int nfs_set_sb_security (struct super_block *s,struct dentry *mntroot,struct nfs_mount_info *mount_info) { -return security_sb_set_mnt_opts (s, &mount_info->parsed->lsm_opts); +return security_sb_set_mnt_opts (s, &mount_info->parsed->lsm_opts, +0 ,NULL ); }EXPORT_SYMBOL_GPL (nfs_set_sb_security);
include/linux/security.h +10 -3
@@ -1452,7 +1452,9 @@ struct security_operations {int (*sb_pivotroot) (struct path *old_path,struct path *new_path);int (*sb_set_mnt_opts) (struct super_block *sb, -struct security_mnt_opts *opts); +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags);void (*sb_clone_mnt_opts) (const struct super_block *oldsb,struct super_block *newsb);int (*sb_parse_opts_str) (char *options,struct security_mnt_opts *opts);
@@ -1742,7 +1744,10 @@ int security_sb_mount(const char *dev_name, struct path *path, const char *type, unsigned long flags, void *data);int security_sb_umount (struct vfsmount *mnt,int flags);int security_sb_pivotroot (struct path *old_path,struct path *new_path); -int security_sb_set_mnt_opts (struct super_block *sb,struct security_mnt_opts *opts); +int security_sb_set_mnt_opts (struct super_block *sb, +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags);void security_sb_clone_mnt_opts (const struct super_block *oldsb,struct super_block *newsb);int security_sb_parse_opts_str (char *options,struct security_mnt_opts *opts);
@@ -2032,7 +2037,9 @@ static inline int security_sb_pivotroot(struct path *old_path, }static inline int security_sb_set_mnt_opts (struct super_block *sb, -struct security_mnt_opts *opts) +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags) {return 0 ; }
security/capability.c +4 -1
@@ -91,7 +91,10 @@ static int cap_sb_pivotroot(struct path *old_path, struct path *new_path) }static int cap_sb_set_mnt_opts (struct super_block *sb, -struct security_mnt_opts *opts) +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags) + {if (unlikely (opts->num_mnt_opts))return -EOPNOTSUPP ;
security/security.c +5 -2
@@ -294,9 +294,12 @@ int security_sb_pivotroot(struct path *old_path, struct path *new_path) }int security_sb_set_mnt_opts (struct super_block *sb, -struct security_mnt_opts *opts) +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags) { -return security_ops->sb_set_mnt_opts (sb, opts); +return security_ops->sb_set_mnt_opts (sb, opts, kern_flags, + set_kern_flags); }EXPORT_SYMBOL (security_sb_set_mnt_opts);
security/selinux/hooks.c +10 -2
@@ -551,7 +551,9 @@ static int bad_option(struct superblock_security_struct *sbsec, char flag,* labeling information. */ static int selinux_set_mnt_opts (struct super_block *sb, -struct security_mnt_opts *opts) +struct security_mnt_opts *opts, +unsigned long kern_flags, +unsigned long *set_kern_flags) {const struct cred *cred =current_cred ();int rc =0 , i;
@@ -579,6 +581,12 @@ static int selinux_set_mnt_opts(struct super_block *sb, "before the security server is initialized\n"); goto out; } +if (kern_flags && !set_kern_flags) { +/* Specifying internal flags without providing a place to +* place the results is not allowed */ + rc = -EINVAL ; + goto out; + }/* * Binary mount data FS will come through this function twice. Once
@@ -948,7 +956,7 @@ static int superblock_doinit(struct super_block *sb, void *data) goto out_err; out: - rc =selinux_set_mnt_opts (sb, &opts); + rc =selinux_set_mnt_opts (sb, &opts,0 ,NULL ); out_err:security_free_mnt_opts (&opts);
Signature · 1 line
1.8.1.4
PATCH 4/14 SELinux: Add new labeling type native labels
In reply to Steve DicksonFrom: David Quigley <[email protected]>
There currently doesn't exist a labeling type that is adequate for use with labeled NFS. Since NFS doesn't really support xattrs we can't use the use xattr labeling behavior. For this we developed a new labeling type. The native labeling type is used solely by NFS to ensure NFS inodes are labeled at runtime by the NFS code instead of relying on the SELinux security server on the client end.
--- include/linux/security.h | 3 +++ security/selinux/hooks.c | 35 ++++++++++++++++++++++++++--------- security/selinux/include/security.h | 2 ++ security/selinux/ss/policydb.c | 5 ++++- 4 files changed, 35 insertions(+), 10 deletions(-)
include/linux/security.h +3 -0
@@ -61,6 +61,9 @@ struct mm_struct;#define SECURITY_CAP_NOAUDIT 0#define SECURITY_CAP_AUDIT 1 +/* LSM Agnostic defines for sb_set_mnt_opts */ +#define SECURITY_LSM_NATIVE_LABELS 1 +struct ctl_table ;struct audit_krule ;struct user_namespace ;
security/selinux/hooks.c +26 -9
@@ -80,6 +80,7 @@#include <linux/syslog.h> #include <linux/user_namespace.h> #include <linux/export.h> +#include <linux/security.h> #include <linux/msg.h> #include <linux/shm.h>
@@ -283,13 +284,14 @@ static void superblock_free_security(struct super_block *sb)/* The file system's label must be initialized prior to use. */ -static const char *labeling_behaviors[6 ] = { +static const char *labeling_behaviors[7 ] = {"uses xattr" ,"uses transition SIDs" ,"uses task SIDs" ,"uses genfs_contexts" ,"not configured for labeling" ,"uses mountpoint labeling" , +"uses native labeling" , };static int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry);
@@ -677,14 +679,21 @@ static int selinux_set_mnt_opts(struct super_block *sb,if (strcmp (sb->s_type->name,"proc" ) ==0 ) sbsec->flags |=SE_SBPROC ; -/* Determine the labeling behavior to use for this filesystem type. */ - rc =security_fs_use ((sbsec->flags &SE_SBPROC ) ?"proc" : sb->s_type->name, &sbsec->behavior, &sbsec->sid); -if (rc) { -printk (KERN_WARNING "%s: security_fs_use(%s) returned %d\n" , - __func__, sb->s_type->name, rc); - goto out; +if (!sbsec->behavior) { +/* +* Determine the labeling behavior to use for this +* filesystem type. +*/ + rc =security_fs_use ((sbsec->flags &SE_SBPROC ) ? +"proc" : sb->s_type->name, + &sbsec->behavior, &sbsec->sid); +if (rc) { +printk (KERN_WARNING +"%s: security_fs_use(%s) returned %d\n" , + __func__, sb->s_type->name, rc); + goto out; + } } -/* sets the context of the superblock for the fs being mounted. */ if (fscontext_sid) { rc =may_context_mount_sb_relabel (fscontext_sid, sbsec, cred);
@@ -699,6 +708,11 @@ static int selinux_set_mnt_opts(struct super_block *sb,* sets the label used on all file below the mountpoint, and will set * the superblock context if not already set. */ +if (kern_flags &SECURITY_LSM_NATIVE_LABELS && !context_sid) { + sbsec->behavior =SECURITY_FS_USE_NATIVE ; + *set_kern_flags |=SECURITY_LSM_NATIVE_LABELS ; + } +if (context_sid) {if (!fscontext_sid) { rc = may_context_mount_sb_relabel(context_sid, sbsec,
@@ -730,7 +744,8 @@ static int selinux_set_mnt_opts(struct super_block *sb, }if (defcontext_sid) { -if (sbsec->behavior !=SECURITY_FS_USE_XATTR ) { +if (sbsec->behavior !=SECURITY_FS_USE_XATTR && + sbsec->behavior !=SECURITY_FS_USE_NATIVE ) { rc = -EINVAL ;printk (KERN_WARNING "SELinux: defcontext option is " "invalid for this filesystem type\n" );
@@ -1198,6 +1213,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent }switch (sbsec->behavior) { +case SECURITY_FS_USE_NATIVE : +break ;case SECURITY_FS_USE_XATTR :if (!inode->i_op->getxattr) { isec->sid = sbsec->def_sid;
security/selinux/include/security.h +2 -0
@@ -169,6 +169,8 @@ int security_get_allow_unknown(void);#define SECURITY_FS_USE_GENFS 4/* use the genfs support */ #define SECURITY_FS_USE_NONE 5/* no labeling support */ #define SECURITY_FS_USE_MNTPOINT 6/* use mountpoint labeling */ +#define SECURITY_FS_USE_NATIVE 7/* use native label support */ +#define SECURITY_FS_USE_MAX 7/* Highest SECURITY_FS_USE_XXX */ int security_fs_use (const char *fstype,unsigned int *behavior,u32 *sid);
security/selinux/ss/policydb.c +4 -1
@@ -2168,7 +2168,10 @@ static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, rc = -EINVAL ; c->v.behavior =le32_to_cpu (buf[0 ]); -if (c->v.behavior >SECURITY_FS_USE_NONE ) +/* Determined at runtime, not in policy DB. */ +if (c->v.behavior ==SECURITY_FS_USE_MNTPOINT ) + goto out; +if (c->v.behavior >SECURITY_FS_USE_MAX ) goto out; rc = -ENOMEM ;
Signature · 1 line
1.8.1.4
PATCH 5/14 NFSv4: Add label recommended attribute and NFSv4 flags
In reply to Steve DicksonFrom: David Quigley <[email protected]>
This patch adds several new flags to allow the NFS client and server to determine if this attribute is supported and if it is being sent over the wire.
--- include/linux/nfs4.h | 1 + include/linux/nfs_fs_sb.h | 1 + include/linux/nfs_xdr.h | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-)
include/linux/nfs4.h +1 -0
@@ -377,6 +377,7 @@ enum lock_type4 {#define FATTR4_WORD1_MOUNTED_ON_FILEID (1UL << 23)#define FATTR4_WORD1_FS_LAYOUT_TYPES (1UL << 30)#define FATTR4_WORD2_LAYOUT_BLKSIZE (1UL << 1) +#define FATTR4_WORD2_SECURITY_LABEL (1UL << 17)#define FATTR4_WORD2_MDSTHRESHOLD (1UL << 4)/* MDS threshold bitmap bits */
include/linux/nfs_fs_sb.h +1 -0
@@ -197,5 +197,6 @@ struct nfs_server {#define NFS_CAP_MTIME (1U << 13)#define NFS_CAP_POSIX_LOCK (1U << 14)#define NFS_CAP_UIDGID_NOMAP (1U << 15) +#define NFS_CAP_SECURITY_LABEL (1U << 16)#endif
include/linux/nfs_xdr.h +3 -1
@@ -104,6 +104,7 @@ struct nfs_fattr {#define NFS_ATTR_FATTR_MOUNTED_ON_FILEID (1U << 22)#define NFS_ATTR_FATTR_OWNER_NAME (1U << 23)#define NFS_ATTR_FATTR_GROUP_NAME (1U << 24) +#define NFS_ATTR_FATTR_V4_SECURITY_LABEL (1U << 25)#define NFS_ATTR_FATTR (NFS_ATTR_FATTR_TYPE \ | NFS_ATTR_FATTR_MODE \
@@ -123,7 +124,8 @@ struct nfs_fattr {#define NFS_ATTR_FATTR_V3 (NFS_ATTR_FATTR \ | NFS_ATTR_FATTR_SPACE_USED)#define NFS_ATTR_FATTR_V4 (NFS_ATTR_FATTR \ - | NFS_ATTR_FATTR_SPACE_USED) + | NFS_ATTR_FATTR_SPACE_USED \ + | NFS_ATTR_FATTR_V4_SECURITY_LABEL)/* * Info on the file system
Signature · 1 line
1.8.1.4
PATCH 6/14 NFSv4: Introduce new label structure
In reply to Steve DicksonFrom: David Quigley <[email protected]>
In order to mimic the way that NFSv4 ACLs are implemented we have created a structure to be used to pass label data up and down the call chain. This patch adds the new structure and new members to the required NFSv4 call structures.
--- fs/nfs/inode.c | 24 ++++++++++++++++++++++++ include/linux/nfs4.h | 7 +++++++ include/linux/nfs_fs.h | 18 ++++++++++++++++++ include/linux/nfs_xdr.h | 21 +++++++++++++++++++++ include/uapi/linux/nfs4.h | 2 +- 5 files changed, 71 insertions(+), 1 deletion(-)
fs/nfs/inode.c +24 -0
@@ -257,6 +257,30 @@ nfs_init_locked(struct inode *inode, void *opaque)return 0 ; } +#ifdef CONFIG_NFS_V4_SECURITY_LABEL +struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags) +{ +struct nfs4_label *label =NULL ; + +if (!(server->caps &NFS_CAP_SECURITY_LABEL )) +return label; + + label =kzalloc (sizeof (struct nfs4_label ), flags); +if (label ==NULL ) +return ERR_PTR (-ENOMEM ); + + label->label =kzalloc (NFS4_MAXLABELLEN , flags); +if (label->label ==NULL ) { +kfree (label); +return ERR_PTR (-ENOMEM ); + } + label->len =NFS4_MAXLABELLEN ; + +return label; +} +EXPORT_SYMBOL_GPL (nfs4_label_alloc); +#endif +/* * This is our front-end to iget that looks up inodes by file handle * instead of inode number.
include/linux/nfs4.h +7 -0
@@ -32,6 +32,13 @@ struct nfs4_acl {struct nfs4_ace aces[0 ]; }; +struct nfs4_label { +uint32_t lfs; +uint32_t pi; +u32 len; +char *label; +}; +typedef struct {char data[NFS4_VERIFIER_SIZE ]; }nfs4_verifier ;struct nfs_stateid4 {
include/linux/nfs_fs.h +18 -0
@@ -489,6 +489,24 @@ extern int nfs_mountpoint_expiry_timeout;extern void nfs_release_automount_timer (void );/* +* linux/fs/nfs/nfs4proc.c +*/ +#ifdef CONFIG_NFS_V4_SECURITY_LABEL +extern struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags); +static inline void nfs4_label_free (struct nfs4_label *label) +{ +if (label) { +kfree (label->label); +kfree (label); + } +return ; +} +#else +static inline struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags) {return NULL ; } +static inline void nfs4_label_free (void *label) {} +#endif + +/* * linux/fs/nfs/unlink.c */ extern void nfs_complete_unlink (struct dentry *dentry,struct inode *);
include/linux/nfs_xdr.h +21 -0
@@ -351,6 +351,7 @@ struct nfs_openargs {const u32 * bitmask;const u32 * open_bitmap;__u32 claim; +const struct nfs4_label *label; };struct nfs_openres {
@@ -360,6 +361,7 @@ struct nfs_openres {struct nfs4_change_info cinfo;__u32 rflags;struct nfs_fattr * f_attr; +struct nfs4_label *f_label;struct nfs_seqid * seqid;const struct nfs_server *server;fmode_t delegation_type;
@@ -404,6 +406,7 @@ struct nfs_closeres {struct nfs4_sequence_res seq_res;nfs4_stateid stateid;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs_seqid * seqid;const struct nfs_server *server; };
@@ -477,6 +480,7 @@ struct nfs4_delegreturnargs {struct nfs4_delegreturnres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;const struct nfs_server *server; };
@@ -497,6 +501,7 @@ struct nfs_readargs {struct nfs_readres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;__u32 count;int eof; };
@@ -565,6 +570,7 @@ struct nfs_removeres {struct nfs4_sequence_res seq_res;const struct nfs_server *server;struct nfs_fattr *dir_attr; +struct nfs4_label *dir_label;struct nfs4_change_info cinfo; };
@@ -577,6 +583,8 @@ struct nfs_renameargs {const struct nfs_fh *new_dir;const struct qstr *old_name;const struct qstr *new_name; +const struct nfs4_label *old_label; +const struct nfs4_label *new_label; };struct nfs_renameres {
@@ -584,8 +592,10 @@ struct nfs_renameres {const struct nfs_server *server;struct nfs4_change_info old_cinfo;struct nfs_fattr *old_fattr; +struct nfs4_label *old_label;struct nfs4_change_info new_cinfo;struct nfs_fattr *new_fattr; +struct nfs4_label *new_label; };/*
@@ -600,6 +610,7 @@ struct nfs_entry {int eof;struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label;unsigned char d_type;struct nfs_server * server; };
@@ -632,6 +643,7 @@ struct nfs_setattrargs {struct iattr * iap;const struct nfs_server * server;/* Needed for name mapping */ const u32 * bitmask; +const struct nfs4_label *label; };struct nfs_setaclargs {
@@ -667,6 +679,7 @@ struct nfs_getaclres {struct nfs_setattrres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;const struct nfs_server * server; };
@@ -712,6 +725,7 @@ struct nfs3_setaclargs {struct nfs_diropok {struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label; };struct nfs_readlinkargs {
@@ -842,6 +856,7 @@ struct nfs4_accessres {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label;u32 supported;u32 access; };
@@ -864,6 +879,7 @@ struct nfs4_create_arg {const struct iattr * attrs;const struct nfs_fh * dir_fh;const u32 * bitmask; +const struct nfs4_label *label; };struct nfs4_create_res {
@@ -871,6 +887,7 @@ struct nfs4_create_res {const struct nfs_server * server;struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs4_change_info dir_cinfo; };
@@ -895,6 +912,7 @@ struct nfs4_getattr_res {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label; };struct nfs4_link_arg {
@@ -909,8 +927,10 @@ struct nfs4_link_res {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs4_change_info cinfo;struct nfs_fattr * dir_attr; +struct nfs4_label *dir_label; };
@@ -926,6 +946,7 @@ struct nfs4_lookup_res {const struct nfs_server * server;struct nfs_fattr * fattr;struct nfs_fh * fh; +struct nfs4_label *label; };struct nfs4_lookup_root_arg {
include/uapi/linux/nfs4.h +1 -1
@@ -25,7 +25,7 @@#define NFS4_MAXNAMLEN NAME_MAX#define NFS4_OPAQUE_LIMIT 1024#define NFS4_MAX_SESSIONID_LEN 16 - +#define NFS4_MAXLABELLEN 128#define NFS4_ACCESS_READ 0x0001#define NFS4_ACCESS_LOOKUP 0x0002#define NFS4_ACCESS_MODIFY 0x0004
Signature · 1 line
1.8.1.4
Re: [PATCH 06/14] NFSv4: Introduce new label structure
Quoted 34 lines · Steve Dickson
From: David Quigley <[email protected]>
In order to mimic the way that NFSv4 ACLs are implemented we have created a structure to be used to pass label data up and down the call chain. This patch adds the new structure and new members to the required NFSv4 call structures.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfs/inode.c | 24 ++++++++++++++++++++++++ include/linux/nfs4.h | 7 +++++++ include/linux/nfs_fs.h | 18 ++++++++++++++++++ include/linux/nfs_xdr.h | 21 +++++++++++++++++++++ include/uapi/linux/nfs4.h | 2 +- 5 files changed, 71 insertions(+), 1 deletion(-)fs/nfs/inode.c +8
-0@@ -257,6 +257,30 @@ nfs_init_locked(struct inode *inode, void *opaque)return 0 ; } +#ifdef CONFIG_NFS_V4_SECURITY_LABEL +struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags) +{ +struct nfs4_label *label =NULL ; + +if (!(server->caps &NFS_CAP_SECURITY_LABEL )) +return label; +
fs/nfs/inode.c nfs_init_locked(struct inode *inode, void *opaque) · line 277
Quoted 10 lines
fs/nfs/inode.c +10
-0+ label =kzalloc (sizeof (struct nfs4_label ), flags); +if (label ==NULL ) +return ERR_PTR (-ENOMEM ); + + label->label =kzalloc (NFS4_MAXLABELLEN , flags); +if (label->label ==NULL ) { +kfree (label); +return ERR_PTR (-ENOMEM ); + } + label->len =NFS4_MAXLABELLEN ;
So on getting a label the xdr decoder copies into this preallocated label->label, and on setting one we declare a struct nfs4_label on the stack and initialize it to point to the label we were called with. And NFS4_MAXLABELLEN is now down to 128. OK.
--b.
Quoted 227 lines
fs/nfs/inode.c +6
-0+ + return label; +} +EXPORT_SYMBOL_GPL (nfs4_label_alloc); +#endif +/* * This is our front-end to iget that looks up inodes by file handle * instead of inode number. include/linux/nfs4.h +7
-0@@ -32,6 +32,13 @@ struct nfs4_acl {struct nfs4_ace aces[0 ]; }; +struct nfs4_label { +uint32_t lfs; +uint32_t pi; +u32 len; +char *label; +}; +typedef struct {char data[NFS4_VERIFIER_SIZE ]; }nfs4_verifier ;struct nfs_stateid4 {include/linux/nfs_fs.h +18
-0@@ -489,6 +489,24 @@ extern int nfs_mountpoint_expiry_timeout;extern void nfs_release_automount_timer (void );/* +* linux/fs/nfs/nfs4proc.c +*/ +#ifdef CONFIG_NFS_V4_SECURITY_LABEL +extern struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags); +static inline void nfs4_label_free (struct nfs4_label *label) +{ +if (label) { +kfree (label->label); +kfree (label); + } +return ; +} +#else +static inline struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags) {return NULL ; } +static inline void nfs4_label_free (void *label) {} +#endif + +/* * linux/fs/nfs/unlink.c */ extern void nfs_complete_unlink (struct dentry *dentry,struct inode *);include/linux/nfs_xdr.h +21
-0@@ -351,6 +351,7 @@ struct nfs_openargs {const u32 * bitmask;const u32 * open_bitmap;__u32 claim; +const struct nfs4_label *label; };struct nfs_openres {@@ -360,6 +361,7 @@ struct nfs_openres {struct nfs4_change_info cinfo;__u32 rflags;struct nfs_fattr * f_attr; +struct nfs4_label *f_label;struct nfs_seqid * seqid;const struct nfs_server *server;fmode_t delegation_type;@@ -404,6 +406,7 @@ struct nfs_closeres {struct nfs4_sequence_res seq_res;nfs4_stateid stateid;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs_seqid * seqid;const struct nfs_server *server; };@@ -477,6 +480,7 @@ struct nfs4_delegreturnargs {struct nfs4_delegreturnres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;const struct nfs_server *server; };@@ -497,6 +501,7 @@ struct nfs_readargs {struct nfs_readres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;__u32 count;int eof; };@@ -565,6 +570,7 @@ struct nfs_removeres {struct nfs4_sequence_res seq_res;const struct nfs_server *server;struct nfs_fattr *dir_attr; +struct nfs4_label *dir_label;struct nfs4_change_info cinfo; };@@ -577,6 +583,8 @@ struct nfs_renameargs {const struct nfs_fh *new_dir;const struct qstr *old_name;const struct qstr *new_name; +const struct nfs4_label *old_label; +const struct nfs4_label *new_label; };struct nfs_renameres {@@ -584,8 +592,10 @@ struct nfs_renameres {const struct nfs_server *server;struct nfs4_change_info old_cinfo;struct nfs_fattr *old_fattr; +struct nfs4_label *old_label;struct nfs4_change_info new_cinfo;struct nfs_fattr *new_fattr; +struct nfs4_label *new_label; };/* @@ -600,6 +610,7 @@ struct nfs_entry {int eof;struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label;unsigned char d_type;struct nfs_server * server; };@@ -632,6 +643,7 @@ struct nfs_setattrargs {struct iattr * iap;const struct nfs_server * server;/* Needed for name mapping */ const u32 * bitmask; +const struct nfs4_label *label; };struct nfs_setaclargs {@@ -667,6 +679,7 @@ struct nfs_getaclres {struct nfs_setattrres {struct nfs4_sequence_res seq_res;struct nfs_fattr * fattr; +struct nfs4_label *label;const struct nfs_server * server; };@@ -712,6 +725,7 @@ struct nfs3_setaclargs {struct nfs_diropok {struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label; };struct nfs_readlinkargs {@@ -842,6 +856,7 @@ struct nfs4_accessres {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label;u32 supported;u32 access; };@@ -864,6 +879,7 @@ struct nfs4_create_arg {const struct iattr * attrs;const struct nfs_fh * dir_fh;const u32 * bitmask; +const struct nfs4_label *label; };struct nfs4_create_res {@@ -871,6 +887,7 @@ struct nfs4_create_res {const struct nfs_server * server;struct nfs_fh * fh;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs4_change_info dir_cinfo; };@@ -895,6 +912,7 @@ struct nfs4_getattr_res {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label; };struct nfs4_link_arg {@@ -909,8 +927,10 @@ struct nfs4_link_res {struct nfs4_sequence_res seq_res;const struct nfs_server * server;struct nfs_fattr * fattr; +struct nfs4_label *label;struct nfs4_change_info cinfo;struct nfs_fattr * dir_attr; +struct nfs4_label *dir_label; };@@ -926,6 +946,7 @@ struct nfs4_lookup_res {const struct nfs_server * server;struct nfs_fattr * fattr;struct nfs_fh * fh; +struct nfs4_label *label; };struct nfs4_lookup_root_arg {include/uapi/linux/nfs4.h +1
-1@@ -25,7 +25,7 @@#define NFS4_MAXNAMLEN NAME_MAX#define NFS4_OPAQUE_LIMIT 1024#define NFS4_MAX_SESSIONID_LEN 16 - +#define NFS4_MAXLABELLEN 128#define NFS4_ACCESS_READ 0x0001#define NFS4_ACCESS_LOOKUP 0x0002#define NFS4_ACCESS_MODIFY 0x0004Signature · 1 line
1.8.1.4
PATCH 7/14 NFSv4: Extend fattr bitmaps to support all 3 words
In reply to Steve DicksonFrom: David Quigley <[email protected]>
The fattr handling bitmap code only uses the first two fattr words sofar. This patch adds the 3rd word to being sent but doesn't populate it yet.
--- fs/nfs/nfs4_fs.h | 6 +++--- fs/nfs/nfs4proc.c | 10 +++++----- fs/nfs/nfs4xdr.c | 20 ++++++++++++-------- fs/nfs/super.c | 1 + include/linux/nfs_fs_sb.h | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-)
fs/nfs/nfs4_fs.h +3 -3
@@ -295,10 +295,10 @@ is_ds_client(struct nfs_client *clp)extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[];extern const u32 nfs4_fattr_bitmap[3 ]; -extern const u32 nfs4_statfs_bitmap[2 ]; -extern const u32 nfs4_pathconf_bitmap[2 ]; +extern const u32 nfs4_statfs_bitmap[3 ]; +extern const u32 nfs4_pathconf_bitmap[3 ];extern const u32 nfs4_fsinfo_bitmap[3 ]; -extern const u32 nfs4_fs_locations_bitmap[2 ]; +extern const u32 nfs4_fs_locations_bitmap[3 ];void nfs4_free_client (struct nfs_client *);
fs/nfs/nfs4proc.c +5 -5
@@ -159,7 +159,7 @@ static const u32 nfs4_open_noattr_bitmap[3] = { | FATTR4_WORD0_FILEID, }; -const u32 nfs4_statfs_bitmap[2 ] = { +const u32 nfs4_statfs_bitmap[3 ] = {FATTR4_WORD0_FILES_AVAIL |FATTR4_WORD0_FILES_FREE |FATTR4_WORD0_FILES_TOTAL ,
@@ -168,7 +168,7 @@ const u32 nfs4_statfs_bitmap[2] = { | FATTR4_WORD1_SPACE_TOTAL }; -const u32 nfs4_pathconf_bitmap[2 ] = { +const u32 nfs4_pathconf_bitmap[3 ] = {FATTR4_WORD0_MAXLINK |FATTR4_WORD0_MAXNAME ,0
@@ -183,7 +183,7 @@ const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZEFATTR4_WORD2_LAYOUT_BLKSIZE }; -const u32 nfs4_fs_locations_bitmap[2 ] = { +const u32 nfs4_fs_locations_bitmap[3 ] = {FATTR4_WORD0_TYPE |FATTR4_WORD0_CHANGE |FATTR4_WORD0_SIZE
@@ -199,7 +199,7 @@ const u32 nfs4_fs_locations_bitmap[2] = { | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_METADATA | FATTR4_WORD1_TIME_MODIFY - | FATTR4_WORD1_MOUNTED_ON_FILEID + | FATTR4_WORD1_MOUNTED_ON_FILEID, }; static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
@@ -5135,7 +5135,7 @@ static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, struct page *page) {struct nfs_server *server =NFS_SERVER (dir); -u32 bitmask[2 ] = { +u32 bitmask[3 ] = { [0 ] =FATTR4_WORD0_FSID |FATTR4_WORD0_FS_LOCATIONS , };struct nfs4_fs_locations_arg args = {
fs/nfs/nfs4xdr.c +12 -8
@@ -983,15 +983,16 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, constint len;uint32_t bmval0 =0 ;uint32_t bmval1 =0 ; +uint32_t bmval2 =0 ;/* * We reserve enough space to write the entire attribute buffer at once. * In the worst-case, this would be -* 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) -* = 36 bytes, plus any contribution from variable-length fields +* 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime) +* = 40 bytes, plus any contribution from variable-length fields * such as owner/group. */ - len =16 ; + len =20 ;/* Sigh */ if (iap->ia_valid &ATTR_SIZE )
@@ -1035,9 +1036,9 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const* We write the bitmap length now, but leave the bitmap and the attribute * buffer length to be backfilled at the end of this routine. */ - *p++ =cpu_to_be32 (2 ); + *p++ =cpu_to_be32 (3 ); q = p; - p +=3 ; + p +=4 ;if (iap->ia_valid &ATTR_SIZE ) { bmval0 |=FATTR4_WORD0_SIZE ;
@@ -1086,9 +1087,10 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const len, ((char *)p - (char *)q) + 4);BUG (); } - len = (char *)p - (char *)q -12 ; + len = (char *)p - (char *)q -16 ; *q++ =htonl (bmval0); *q++ =htonl (bmval1); + *q++ =htonl (bmval2); *q =htonl (len);/* out: */
@@ -1194,8 +1196,10 @@ encode_getattr_three(struct xdr_stream *xdr,static void encode_getfattr (struct xdr_stream *xdr,const u32 * bitmask,struct compound_hdr *hdr) { -encode_getattr_two (xdr, bitmask[0 ] & nfs4_fattr_bitmap[0 ], - bitmask[1 ] & nfs4_fattr_bitmap[1 ], hdr); +encode_getattr_three (xdr, bitmask[0 ] & nfs4_fattr_bitmap[0 ], + bitmask[1 ] & nfs4_fattr_bitmap[1 ], + bitmask[2 ] & nfs4_fattr_bitmap[2 ], + hdr); } static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
fs/nfs/super.c +1 -0
@@ -832,6 +832,7 @@ int nfs_show_stats(struct seq_file *m, struct dentry *root)seq_printf (m,"\n\tnfsv4:\t" );seq_printf (m,"bm0=0x%x" , nfss->attr_bitmask[0 ]);seq_printf (m,",bm1=0x%x" , nfss->attr_bitmask[1 ]); +seq_printf (m,",bm2=0x%x" , nfss->attr_bitmask[2 ]);seq_printf (m,",acl=0x%x" , nfss->acl_bitmask);show_sessions (m, nfss);show_pnfs (m, nfss);
include/linux/nfs_fs_sb.h +1 -1
@@ -145,7 +145,7 @@ struct nfs_server {u32 attr_bitmask[3 ];/* V4 bitmask representing the set of attributes supported on this filesystem */ -u32 cache_consistency_bitmask[2 ]; +u32 cache_consistency_bitmask[3 ];/* V4 bitmask representing the subset of change attribute, size, ctime and mtime attributes supported by
Signature · 1 line
1.8.1.4
PATCH 8/14 NFS:Add labels to client function prototypes
In reply to Steve DicksonFrom: Dave Quigley <[email protected]>
Quoted 1 line
From David Quigley <[email protected]>
After looking at all of the nfsv4 operations the label structure has been added to the prototypes of the functions which can transmit label data.
--- fs/nfs/client.c | 2 +- fs/nfs/dir.c | 23 +++++----- fs/nfs/getroot.c | 2 +- fs/nfs/inode.c | 33 +++++++------- fs/nfs/namespace.c | 2 +- fs/nfs/nfs3acl.c | 4 +- fs/nfs/nfs3proc.c | 41 ++++++++--------- fs/nfs/nfs4_fs.h | 2 +- fs/nfs/nfs4namespace.c | 2 +- fs/nfs/nfs4proc.c | 117 +++++++++++++++++++++++++++++++----------------- fs/nfs/proc.c | 15 ++++--- include/linux/nfs_fs.h | 9 ++-- include/linux/nfs_xdr.h | 5 ++- 13 files changed, 149 insertions(+), 108 deletions(-)
fs/nfs/client.c +1 -1
@@ -1074,7 +1074,7 @@ struct nfs_server *nfs_create_server(struct nfs_mount_info *mount_info, }if (!(fattr->valid &NFS_ATTR_FATTR )) { - error = nfs_mod->rpc_ops->getattr (server, mount_info->mntfh, fattr); + error = nfs_mod->rpc_ops->getattr (server, mount_info->mntfh, fattr,NULL );if (error <0 ) {dprintk ("nfs_create_server: getattr error = %d\n" , -error); goto error;
fs/nfs/dir.c +13 -10
@@ -447,7 +447,7 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) dentry =d_lookup (parent, &filename);if (dentry !=NULL ) {if (nfs_same_file (dentry, entry)) { -nfs_refresh_inode (dentry->d_inode, entry->fattr); +nfs_refresh_inode (dentry->d_inode, entry->fattr, entry->label); goto out; }else {if (d_invalidate (dentry) !=0 )
@@ -460,7 +460,7 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)if (dentry ==NULL )return ; - inode =nfs_fhget (dentry->d_sb, entry->fh, entry->fattr); + inode =nfs_fhget (dentry->d_sb, entry->fh, entry->fattr, entry->label);if (IS_ERR (inode)) goto out;
@@ -1040,6 +1040,7 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)struct dentry *parent;struct nfs_fh *fhandle =NULL ;struct nfs_fattr *fattr =NULL ; +struct nfs4_label *label =NULL ;int error;if (flags &LOOKUP_RCU )
@@ -1082,12 +1083,12 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)if (fhandle ==NULL || fattr ==NULL ) goto out_error; - error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr); + error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr, label);if (error) goto out_bad;if (nfs_compare_fh (NFS_FH (inode), fhandle)) goto out_bad; -if ((error =nfs_refresh_inode (inode, fattr)) !=0 ) +if ((error =nfs_refresh_inode (inode, fattr, label)) !=0 ) goto out_bad;nfs_free_fattr (fattr);
@@ -1256,6 +1257,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned instruct inode *inode =NULL ;struct nfs_fh *fhandle =NULL ;struct nfs_fattr *fattr =NULL ; +struct nfs4_label *label =NULL ;int error; dfprintk(VFS, "NFS: lookup(%s/%s)\n",
@@ -1285,14 +1287,14 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in parent = dentry->d_parent;/* Protect against concurrent sillydeletes */ nfs_block_sillyrename (parent); - error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr); + error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr, label);if (error == -ENOENT ) goto no_entry;if (error <0 ) { res =ERR_PTR (error); goto out_unblock_sillyrename; } - inode =nfs_fhget (dentry->d_sb, fhandle, fattr); + inode =nfs_fhget (dentry->d_sb, fhandle, fattr, label); res =ERR_CAST (inode);if (IS_ERR (res)) goto out_unblock_sillyrename;
@@ -1526,7 +1528,8 @@ no_open:* Code common to create, mkdir, and mknod. */ int nfs_instantiate (struct dentry *dentry,struct nfs_fh *fhandle, -struct nfs_fattr *fattr) +struct nfs_fattr *fattr, +struct nfs4_label *label) {struct dentry *parent =dget_parent (dentry);struct inode *dir = parent->d_inode;
@@ -1539,18 +1542,18 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,if (dentry->d_inode) goto out;if (fhandle->size ==0 ) { - error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr); + error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr,NULL );if (error) goto out_error; }nfs_set_verifier (dentry,nfs_save_change_attribute (dir));if (!(fattr->valid &NFS_ATTR_FATTR )) {struct nfs_server *server =NFS_SB (dentry->d_sb); - error = server->nfs_client->rpc_ops->getattr (server, fhandle, fattr); + error = server->nfs_client->rpc_ops->getattr (server, fhandle, fattr,NULL );if (error <0 ) goto out_error; } - inode =nfs_fhget (dentry->d_sb, fhandle, fattr); + inode =nfs_fhget (dentry->d_sb, fhandle, fattr, label); error =PTR_ERR (inode);if (IS_ERR (inode)) goto out_error;
fs/nfs/getroot.c +1 -1
@@ -95,7 +95,7 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh, goto out; } - inode =nfs_fhget (sb, mntfh, fsinfo.fattr); + inode =nfs_fhget (sb, mntfh, fsinfo.fattr,NULL );if (IS_ERR (inode)) {dprintk ("nfs_get_root: get root inode failed\n" ); ret =ERR_CAST (inode);
fs/nfs/inode.c +17 -16
@@ -61,7 +61,7 @@static bool enable_ino64 =NFS_64_BIT_INODE_NUMBERS_ENABLED ;static void nfs_invalidate_inode (struct inode *); -static int nfs_update_inode (struct inode *,struct nfs_fattr *); +static int nfs_update_inode (struct inode *,struct nfs_fattr *,struct nfs4_label *);static struct kmem_cache * nfs_inode_cachep;
@@ -286,7 +286,7 @@ EXPORT_SYMBOL_GPL(nfs4_label_alloc);* instead of inode number. */ struct inode * -nfs_fhget (struct super_block *sb,struct nfs_fh *fh,struct nfs_fattr *fattr) +nfs_fhget (struct super_block *sb,struct nfs_fh *fh,struct nfs_fattr *fattr,struct nfs4_label *label) {struct nfs_find_desc desc = { .fh = fh,
@@ -416,7 +416,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)unlock_new_inode (inode); }else -nfs_refresh_inode (inode, fattr); +nfs_refresh_inode (inode, fattr, label); dprintk("NFS: nfs_fhget(%s/%Ld fh_crc=0x%08x ct=%d)\n", inode->i_sb->s_id, (long long)NFS_FILEID(inode),
@@ -473,7 +473,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)NFS_PROTO (inode)->return_delegation (inode); error =NFS_PROTO (inode)->setattr (dentry, fattr, attr);if (error ==0 ) -nfs_refresh_inode (inode, fattr); +nfs_refresh_inode (inode, fattr,NULL );nfs_free_fattr (fattr); out:return error;
@@ -812,6 +812,7 @@ int __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) { int status = -ESTALE; +struct nfs4_label *label =NULL ;struct nfs_fattr *fattr =NULL ;struct nfs_inode *nfsi =NFS_I (inode);
@@ -829,7 +830,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) goto out;nfs_inc_stats (inode,NFSIOS_INODEREVALIDATE ); - status =NFS_PROTO (inode)->getattr (server,NFS_FH (inode), fattr); + status =NFS_PROTO (inode)->getattr (server,NFS_FH (inode), fattr, label);if (status !=0 ) { dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n", inode->i_sb->s_id,
@@ -842,7 +843,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) goto out; } - status =nfs_refresh_inode (inode, fattr); + status =nfs_refresh_inode (inode, fattr, label);if (status) { dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n", inode->i_sb->s_id,
@@ -1199,10 +1200,10 @@ static int nfs_inode_attrs_need_update(const struct inode *inode, const struct n ((long )nfsi->attr_gencount - (long )nfs_read_attr_generation_counter () >0 ); } -static int nfs_refresh_inode_locked (struct inode *inode,struct nfs_fattr *fattr) +static int nfs_refresh_inode_locked (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *label) {if (nfs_inode_attrs_need_update (inode, fattr)) -return nfs_update_inode (inode, fattr); +return nfs_update_inode (inode, fattr, label);return nfs_check_inode_attributes (inode, fattr); }
@@ -1216,21 +1217,21 @@ static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr* safe to do a full update of the inode attributes, or whether just to * call nfs_check_inode_attributes. */ -int nfs_refresh_inode (struct inode *inode,struct nfs_fattr *fattr) +int nfs_refresh_inode (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *label) {int status;if ((fattr->valid &NFS_ATTR_FATTR ) ==0 )return 0 ;spin_lock (&inode->i_lock); - status =nfs_refresh_inode_locked (inode, fattr); + status =nfs_refresh_inode_locked (inode, fattr, label);spin_unlock (&inode->i_lock);return status; }EXPORT_SYMBOL_GPL (nfs_refresh_inode); -static int nfs_post_op_update_inode_locked (struct inode *inode,struct nfs_fattr *fattr) +static int nfs_post_op_update_inode_locked (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *label) {struct nfs_inode *nfsi =NFS_I (inode);
@@ -1241,7 +1242,7 @@ static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr }if ((fattr->valid &NFS_ATTR_FATTR ) ==0 )return 0 ; -return nfs_refresh_inode_locked (inode, fattr); +return nfs_refresh_inode_locked (inode, fattr, label); }/**
@@ -1258,12 +1259,12 @@ static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr* are expected to change one or more attributes, to avoid * unnecessary NFS requests and trips through nfs_update_inode(). */ -int nfs_post_op_update_inode (struct inode *inode,struct nfs_fattr *fattr) +int nfs_post_op_update_inode (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *label) {int status;spin_lock (&inode->i_lock); - status =nfs_post_op_update_inode_locked (inode, fattr); + status =nfs_post_op_update_inode_locked (inode, fattr, label);spin_unlock (&inode->i_lock);return status; }
@@ -1315,7 +1316,7 @@ int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fa fattr->valid |=NFS_ATTR_FATTR_PRESIZE ; } out_noforce: - status =nfs_post_op_update_inode_locked (inode, fattr); + status =nfs_post_op_update_inode_locked (inode, fattr,NULL );spin_unlock (&inode->i_lock);return status; }
@@ -1333,7 +1334,7 @@ EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);* * A very similar scenario holds for the dir cache. */ -static int nfs_update_inode (struct inode *inode,struct nfs_fattr *fattr) +static int nfs_update_inode (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *label) {struct nfs_server *server;struct nfs_inode *nfsi =NFS_I (inode);
fs/nfs/namespace.c +1 -1
@@ -280,7 +280,7 @@ struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry,struct dentry *parent =dget_parent (dentry);/* Look it up again to get its attributes */ - err = server->nfs_client->rpc_ops->lookup (parent->d_inode, &dentry->d_name, fh, fattr); + err = server->nfs_client->rpc_ops->lookup (parent->d_inode, &dentry->d_name, fh, fattr,NULL );dput (parent);if (err !=0 )return ERR_PTR (err);
fs/nfs/nfs3acl.c +2 -2
@@ -240,7 +240,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)switch (status) {case 0 : - status =nfs_refresh_inode (inode, res.fattr); + status =nfs_refresh_inode (inode, res.fattr,NULL );break ;case -EPFNOSUPPORT :case -EPROTONOSUPPORT :
@@ -352,7 +352,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,switch (status) {case 0 : - status =nfs_refresh_inode (inode, fattr); + status =nfs_refresh_inode (inode, fattr,NULL );nfs3_cache_acls (inode, acl, dfacl);break ;case -EPFNOSUPPORT :
fs/nfs/nfs3proc.c +21 -20
138 lines not on this page · raw message
fs/nfs/nfs4_fs.h +1 -1
@@ -229,7 +229,7 @@ extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhextern int nfs4_proc_fs_locations (struct rpc_clnt *,struct inode *,const struct qstr *,struct nfs4_fs_locations *,struct page *);extern struct rpc_clnt *nfs4_proc_lookup_mountpoint (struct inode *,struct qstr *, -struct nfs_fh *,struct nfs_fattr *); +struct nfs_fh *,struct nfs_fattr *,struct nfs4_label *);extern int nfs4_proc_secinfo (struct inode *,const struct qstr *,struct nfs4_secinfo_flavors *);extern int nfs4_release_lockowner (struct nfs4_lock_state *);extern const struct xattr_handler *nfs4_xattr_handlers[];
fs/nfs/nfs4namespace.c +1 -1
@@ -369,7 +369,7 @@ struct vfsmount *nfs4_submount(struct nfs_server *server, struct dentry *dentry,struct vfsmount *mnt;/* Look it up again to get its attributes and sec flavor */ - client =nfs4_proc_lookup_mountpoint (parent->d_inode, &dentry->d_name, fh, fattr); + client =nfs4_proc_lookup_mountpoint (parent->d_inode, &dentry->d_name, fh, fattr,NULL );dput (parent);if (IS_ERR (client))return ERR_CAST (client);
fs/nfs/nfs4proc.c +75 -42
463 lines not on this page · raw message
fs/nfs/proc.c +8 -7
@@ -98,7 +98,7 @@ nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,*/ static int nfs_proc_getattr (struct nfs_server *server,struct nfs_fh *fhandle, -struct nfs_fattr *fattr) +struct nfs_fattr *fattr,struct nfs4_label *label) {struct rpc_message msg = { .rpc_proc = &nfs_procedures[NFSPROC_GETATTR ],
@@ -146,7 +146,8 @@ nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,static int nfs_proc_lookup (struct inode *dir,struct qstr *name, -struct nfs_fh *fhandle,struct nfs_fattr *fattr) +struct nfs_fh *fhandle,struct nfs_fattr *fattr, +struct nfs4_label *label) {struct nfs_diropargs arg = { .fh =NFS_FH (dir),
@@ -243,7 +244,7 @@ nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, status =rpc_call_sync (NFS_CLIENT (dir), &msg,0 );nfs_mark_for_revalidate (dir);if (status ==0 ) - status =nfs_instantiate (dentry, data->res.fh, data->res.fattr); + status =nfs_instantiate (dentry, data->res.fh, data->res.fattr,NULL );nfs_free_createdata (data); out:dprintk ("NFS reply create: %d\n" , status);
@@ -290,7 +291,7 @@ nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, status =rpc_call_sync (NFS_CLIENT (dir), &msg,0 ); }if (status ==0 ) - status =nfs_instantiate (dentry, data->res.fh, data->res.fattr); + status =nfs_instantiate (dentry, data->res.fh, data->res.fattr,NULL );nfs_free_createdata (data); out:dprintk ("NFS reply mknod: %d\n" , status);
@@ -442,7 +443,7 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,* should fill in the data with a LOOKUP call on the wire. */ if (status ==0 ) - status =nfs_instantiate (dentry, fh, fattr); + status =nfs_instantiate (dentry, fh, fattr,NULL ); out_free:nfs_free_fattr (fattr);
@@ -471,7 +472,7 @@ nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) status =rpc_call_sync (NFS_CLIENT (dir), &msg,0 );nfs_mark_for_revalidate (dir);if (status ==0 ) - status =nfs_instantiate (dentry, data->res.fh, data->res.fattr); + status =nfs_instantiate (dentry, data->res.fh, data->res.fattr,NULL );nfs_free_createdata (data); out:dprintk ("NFS reply mkdir: %d\n" , status);
@@ -607,7 +608,7 @@ static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)nfs_invalidate_atime (inode);if (task->tk_status >=0 ) { -nfs_refresh_inode (inode, data->res.fattr); +nfs_refresh_inode (inode, data->res.fattr, data->res.label);/* Emulate the eof flag, which isn't normally needed in NFSv2 * as it is guaranteed to always return the file attributes */
include/linux/nfs_fs.h +5 -4
@@ -328,9 +328,9 @@ extern void nfs_zap_mapping(struct inode *inode, struct address_space *mapping);extern void nfs_zap_caches (struct inode *);extern void nfs_invalidate_atime (struct inode *);extern struct inode *nfs_fhget (struct super_block *,struct nfs_fh *, -struct nfs_fattr *); -extern int nfs_refresh_inode (struct inode *,struct nfs_fattr *); -extern int nfs_post_op_update_inode (struct inode *inode,struct nfs_fattr *fattr); +struct nfs_fattr *,struct nfs4_label *); +extern int nfs_refresh_inode (struct inode *,struct nfs_fattr *,struct nfs4_label *); +extern int nfs_post_op_update_inode (struct inode *inode,struct nfs_fattr *fattr,struct nfs4_label *);extern int nfs_post_op_update_inode_force_wcc (struct inode *inode,struct nfs_fattr *fattr);extern int nfs_getattr (struct vfsmount *,struct dentry *,struct kstat *);extern void nfs_access_add_cache (struct inode *,struct nfs_access_entry *);
@@ -460,7 +460,8 @@ extern const struct file_operations nfs_dir_operations;extern const struct dentry_operations nfs_dentry_operations;extern void nfs_force_lookup_revalidate (struct inode *dir); -extern int nfs_instantiate (struct dentry *dentry,struct nfs_fh *fh,struct nfs_fattr *fattr); +extern int nfs_instantiate (struct dentry *dentry,struct nfs_fh *fh, +struct nfs_fattr *fattr,struct nfs4_label *label);extern int nfs_may_open (struct inode *inode,struct rpc_cred *cred,int openflags);extern void nfs_access_zap_cache (struct inode *inode);
include/linux/nfs_xdr.h +3 -2
@@ -1400,11 +1400,12 @@ struct nfs_rpc_ops {struct dentry *(*try_mount) (int ,const char *,struct nfs_mount_info *,struct nfs_subversion *);int (*getattr) (struct nfs_server *,struct nfs_fh *, -struct nfs_fattr *); +struct nfs_fattr *,struct nfs4_label *);int (*setattr) (struct dentry *,struct nfs_fattr *,struct iattr *);int (*lookup) (struct inode *,struct qstr *, -struct nfs_fh *,struct nfs_fattr *); +struct nfs_fh *,struct nfs_fattr *, +struct nfs4_label *);int (*access) (struct inode *,struct nfs_access_entry *);int (*readlink)(struct inode *,struct page *,unsigned int ,unsigned int );
Signature · 1 line
1.8.1.4
PATCH 9/14 NFS: Add label lifecycle management
In reply to Steve DicksonFrom: Dave Quigley <[email protected]>
Quoted 1 line
From David Quigley <[email protected]>
This patch adds the lifecycle management for the security label structure introduced in an earlier patch. The label is not used yet but allocations and freeing of the structure is handled.
--- fs/nfs/dir.c | 23 ++++++++++++- fs/nfs/inode.c | 15 +++++++-- fs/nfs/nfs4proc.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 126 insertions(+), 10 deletions(-)
fs/nfs/dir.c +22 -1
@@ -585,10 +585,16 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,if (entry.fh ==NULL || entry.fattr ==NULL ) goto out; + entry.label =nfs4_label_alloc (NFS_SERVER (inode),GFP_NOWAIT ); +if (IS_ERR (entry.label)) { + status =PTR_ERR (entry.label); + goto out; + } + array =nfs_readdir_get_array (page);if (IS_ERR (array)) { status =PTR_ERR (array); - goto out; + goto out_label_free; }memset (array,0 ,sizeof (struct nfs_cache_array )); array->eof_index =-1 ;
@@ -614,6 +620,8 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page,nfs_readdir_free_large_page (pages_ptr, pages, array_size); out_release_array:nfs_readdir_release_array (page); +out_label_free: +nfs4_label_free (entry.label); out:nfs_free_fattr (entry.fattr);nfs_free_fhandle (entry.fh);
@@ -1083,6 +1091,10 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)if (fhandle ==NULL || fattr ==NULL ) goto out_error; + label =nfs4_label_alloc (NFS_SERVER (inode),GFP_NOWAIT ); +if (IS_ERR (label)) + goto out_error; + error =NFS_PROTO (dir)->lookup (dir, &dentry->d_name, fhandle, fattr, label);if (error) goto out_bad;
@@ -1093,6 +1105,8 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)nfs_free_fattr (fattr);nfs_free_fhandle (fhandle); +nfs4_label_free (label); + out_set_verifier:nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); out_valid:
@@ -1109,6 +1123,7 @@ out_zap_parent: out_bad:nfs_free_fattr (fattr);nfs_free_fhandle (fhandle); +nfs4_label_free (label);nfs_mark_for_revalidate (dir);if (inode &&S_ISDIR (inode->i_mode)) {/* Purge readdir caches. */
@@ -1129,6 +1144,7 @@ out_zap_parent: out_error:nfs_free_fattr (fattr);nfs_free_fhandle (fhandle); +nfs4_label_free (label);dput (parent); dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) lookup returned error %d\n", __func__, dentry->d_parent->d_name.name,
@@ -1284,6 +1300,10 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned inif (fhandle ==NULL || fattr ==NULL ) goto out; + label =nfs4_label_alloc (NFS_SERVER (dir),GFP_NOWAIT ); +if (IS_ERR (label)) + goto out; + parent = dentry->d_parent;/* Protect against concurrent sillydeletes */ nfs_block_sillyrename (parent);
@@ -1312,6 +1332,7 @@ no_entry:nfs_set_verifier (dentry,nfs_save_change_attribute (dir)); out_unblock_sillyrename:nfs_unblock_sillyrename (parent); +nfs4_label_free (label); out:nfs_free_fattr (fattr);nfs_free_fhandle (fhandle);
fs/nfs/inode.c +12 -3
@@ -830,6 +830,13 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) goto out;nfs_inc_stats (inode,NFSIOS_INODEREVALIDATE ); + + label =nfs4_label_alloc (NFS_SERVER (inode),GFP_KERNEL ); +if (IS_ERR (label)) { + status =PTR_ERR (label); + goto out; + } + status =NFS_PROTO (inode)->getattr (server,NFS_FH (inode), fattr, label);if (status !=0 ) { dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n",
@@ -840,7 +847,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)if (!S_ISDIR (inode->i_mode))set_bit (NFS_INO_STALE , &NFS_I (inode)->flags); } - goto out; + goto err_out; } status =nfs_refresh_inode (inode, fattr, label);
@@ -848,7 +855,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)dfprintk (PAGECACHE ,"nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n" , inode->i_sb->s_id, (long long )NFS_FILEID (inode), status); - goto out; + goto err_out; }if (nfsi->cache_validity &NFS_INO_INVALID_ACL )
@@ -858,7 +865,9 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) inode->i_sb->s_id, (long long)NFS_FILEID(inode)); - out: +err_out: +nfs4_label_free (label); +out:nfs_free_fattr (fattr);return status; }
fs/nfs/nfs4proc.c +92 -6
224 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 10/14 NFS: Client implementation of Labeled-NFS
In reply to Steve DicksonFrom: David Quigley <[email protected]>
This patch implements the client transport and handling support for labeled NFS. The patch adds two functions to encode and decode the security label recommended attribute which makes use of the LSM hooks added earlier. It also adds code to grab the label from the file attribute structures and encode the label to be sent back to the server.
--- fs/nfs/inode.c | 57 ++++++++- fs/nfs/nfs4proc.c | 300 ++++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4xdr.c | 168 ++++++++++++++++++++------ fs/nfs/super.c | 17 ++- include/linux/nfs_fs.h | 3 + include/linux/nfs_fs_sb.h | 7 ++ security/selinux/hooks.c | 4 + 7 files changed, 498 insertions(+), 58 deletions(-)
fs/nfs/inode.c +51 -6
@@ -162,11 +162,19 @@ static void nfs_zap_caches_locked(struct inode *inode)memset (NFS_I (inode)->cookieverf,0 ,sizeof (NFS_I (inode)->cookieverf));if (S_ISREG (mode) ||S_ISDIR (mode) ||S_ISLNK (mode)) { - nfsi->cache_validity |=NFS_INO_INVALID_ATTR |NFS_INO_INVALID_DATA |NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL |NFS_INO_REVAL_PAGECACHE ;nfs_fscache_invalidate (inode); - }else { - nfsi->cache_validity |=NFS_INO_INVALID_ATTR |NFS_INO_INVALID_ACCESS |NFS_INO_INVALID_ACL |NFS_INO_REVAL_PAGECACHE ; - } + nfsi->cache_validity |=NFS_INO_INVALID_ATTR + |NFS_INO_INVALID_LABEL + |NFS_INO_INVALID_DATA + |NFS_INO_INVALID_ACCESS + |NFS_INO_INVALID_ACL + |NFS_INO_REVAL_PAGECACHE ; + }else + nfsi->cache_validity |=NFS_INO_INVALID_ATTR + |NFS_INO_INVALID_LABEL + |NFS_INO_INVALID_ACCESS + |NFS_INO_INVALID_ACL + |NFS_INO_REVAL_PAGECACHE ; }void nfs_zap_caches (struct inode *inode)
@@ -258,6 +266,24 @@ nfs_init_locked(struct inode *inode, void *opaque) }#ifdef CONFIG_NFS_V4_SECURITY_LABEL +void nfs_setsecurity (struct inode *inode,struct nfs_fattr *fattr, +struct nfs4_label *label) +{ +int error; + +if ((fattr->valid &NFS_ATTR_FATTR_V4_SECURITY_LABEL ) && + label && inode->i_security) { + error =security_inode_notifysecctx (inode, label->label, + label->len); +if (error) +printk (KERN_ERR "%s() %s %d " +"security_inode_notifysecctx() %d\n" , + __func__, + (char *)label->label, + label->len, error); + } +} +struct nfs4_label *nfs4_label_alloc (struct nfs_server *server,gfp_t flags) {struct nfs4_label *label =NULL ;
@@ -279,7 +305,13 @@ struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) return label; }EXPORT_SYMBOL_GPL (nfs4_label_alloc); +#else +void inline nfs_setsecurity (struct inode *inode,struct nfs_fattr *fattr, +struct nfs4_label *label) +{ +}#endif +EXPORT_SYMBOL_GPL (nfs_setsecurity);/* * This is our front-end to iget that looks up inodes by file handle
@@ -408,6 +440,9 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st*/ inode->i_blocks =nfs_calc_block_size (fattr->du.nfs3.used); } + +nfs_setsecurity (inode, fattr, label); + nfsi->attrtimeo =NFS_MINATTRTIMEO (inode); nfsi->attrtimeo_timestamp = now; nfsi->access_cache =RB_ROOT ;
@@ -767,6 +802,7 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cspin_unlock (&inode->i_lock);return ctx; } +EXPORT_SYMBOL_GPL (nfs_find_open_context);static void nfs_file_clear_open_context (struct file *filp) {
@@ -895,7 +931,8 @@ static int nfs_attribute_cache_expired(struct inode *inode)*/ int nfs_revalidate_inode (struct nfs_server *server,struct inode *inode) { -if (!(NFS_I (inode)->cache_validity &NFS_INO_INVALID_ATTR ) +if (!(NFS_I (inode)->cache_validity & + (NFS_INO_INVALID_ATTR |NFS_INO_INVALID_LABEL )) && !nfs_attribute_cache_expired (inode))return NFS_STALE (inode) ? -ESTALE :0 ;return __nfs_revalidate_inode (server, inode);
@@ -1236,6 +1273,9 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr, struct nfs4_ status =nfs_refresh_inode_locked (inode, fattr, label);spin_unlock (&inode->i_lock); +if (label && !status) +nfs_setsecurity (inode, fattr, label); +return status; }EXPORT_SYMBOL_GPL (nfs_refresh_inode);
@@ -1275,6 +1315,10 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr, strucspin_lock (&inode->i_lock); status =nfs_post_op_update_inode_locked (inode, fattr, label);spin_unlock (&inode->i_lock); +if (nfs_server_capable (inode,NFS_CAP_SECURITY_LABEL )) { +if (label && !status) +nfs_setsecurity (inode, fattr, label); + }return status; }EXPORT_SYMBOL_GPL (nfs_post_op_update_inode);
@@ -1515,7 +1559,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, struct inode->i_blocks = fattr->du.nfs2.blocks;/* Update attrtimeo value if we're out of the unstable period */ -if (invalid &NFS_INO_INVALID_ATTR ) { +if (invalid & (NFS_INO_INVALID_ATTR |NFS_INO_INVALID_LABEL )) {nfs_inc_stats (inode,NFSIOS_ATTRINVALIDATE ); nfsi->attrtimeo =NFS_MINATTRTIMEO (inode); nfsi->attrtimeo_timestamp = now;
@@ -1528,6 +1572,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, struct } } invalid &= ~NFS_INO_INVALID_ATTR ; + invalid &= ~NFS_INO_INVALID_LABEL ;/* Don't invalidate the data if we were to blame */ if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode)))
fs/nfs/nfs4proc.c +287 -13
476 lines not on this page · raw message
fs/nfs/nfs4xdr.c +131 -37
393 lines not on this page · raw message
fs/nfs/super.c +15 -2
@@ -2374,8 +2374,21 @@ static int nfs_bdi_register(struct nfs_server *server)int nfs_set_sb_security (struct super_block *s,struct dentry *mntroot,struct nfs_mount_info *mount_info) { -return security_sb_set_mnt_opts (s, &mount_info->parsed->lsm_opts, -0 ,NULL ); +int error; +unsigned long kflags =0 , kflags_out =0 ; +if (NFS_SB (s)->caps &NFS_CAP_SECURITY_LABEL ) + kflags |=SECURITY_LSM_NATIVE_LABELS ; + + error =security_sb_set_mnt_opts (s, &mount_info->parsed->lsm_opts, + kflags, &kflags_out); +if (error) + goto err; + +if (NFS_SB (s)->caps &NFS_CAP_SECURITY_LABEL && + !(kflags_out &SECURITY_LSM_NATIVE_LABELS )) +NFS_SB (s)->caps &= ~NFS_CAP_SECURITY_LABEL ; +err: +return error; }EXPORT_SYMBOL_GPL (nfs_set_sb_security);
include/linux/nfs_fs.h +3 -0
@@ -199,6 +199,7 @@ struct nfs_inode {#define NFS_INO_INVALID_ACL 0x0010/* cached acls are invalid */ #define NFS_INO_REVAL_PAGECACHE 0x0020/* must revalidate pagecache */ #define NFS_INO_REVAL_FORCED 0x0040/* force revalidation ignoring a delegation */ +#define NFS_INO_INVALID_LABEL 0x0080/* cached label is invalid */ /* * Bit offsets in flags field
@@ -344,6 +345,8 @@ extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);extern int nfs_revalidate_mapping (struct inode *inode,struct address_space *mapping);extern int nfs_setattr (struct dentry *,struct iattr *);extern void nfs_setattr_update_inode (struct inode *inode,struct iattr *attr); +extern void nfs_setsecurity (struct inode *inode,struct nfs_fattr *fattr, +struct nfs4_label *label);extern struct nfs_open_context *get_nfs_open_context (struct nfs_open_context *ctx);extern void put_nfs_open_context (struct nfs_open_context *ctx);extern struct nfs_open_context *nfs_find_open_context (struct inode *inode,struct rpc_cred *cred,fmode_t mode);
include/linux/nfs_fs_sb.h +7 -0
@@ -145,11 +145,18 @@ struct nfs_server {u32 attr_bitmask[3 ];/* V4 bitmask representing the set of attributes supported on this filesystem */ +u32 attr_bitmask_nl[3 ]; +/* V4 bitmask representing the +set of attributes supported +on this filesystem excluding +the label support bit. */ u32 cache_consistency_bitmask[3 ];/* V4 bitmask representing the subset of change attribute, size, ctime and mtime attributes supported by the server */ +u32 cache_consistency_bitmask_nl[3 ]; +/* As above, excluding label. */ u32 acl_bitmask;/* V4 bitmask representing the ACEs that are supported on this filesystem */
security/selinux/hooks.c +4 -0
@@ -2876,7 +2876,10 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,return ; } + isec->sclass =inode_mode_to_security_class (inode->i_mode); isec->sid = newsid; + isec->initialized =1 ; +return ; }
@@ -2964,6 +2967,7 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,if (rc)return rc; + isec->sclass =inode_mode_to_security_class (inode->i_mode); isec->sid = newsid; isec->initialized =1 ;return 0 ;
Signature · 1 line
1.8.1.4
PATCH 11/14 NFS: Extend NFS xattr handlers to accept the security namespace
In reply to Steve DicksonFrom: David Quigley <[email protected]>
The existing NFSv4 xattr handlers do not accept xattr calls to the security namespace. This patch extends these handlers to accept xattrs from the security namespace in addition to the default NFSv4 ACL namespace.
--- fs/nfs/nfs4proc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ security/security.c | 1 + 2 files changed, 51 insertions(+)
fs/nfs/nfs4proc.c +50 -0
@@ -5505,6 +5505,53 @@ static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,return len; } +#ifdef CONFIG_NFS_V4_SECURITY_LABEL +static inline int nfs4_server_supports_labels (struct nfs_server *server) +{ +return server->caps &NFS_CAP_SECURITY_LABEL ; +} + +static int nfs4_xattr_set_nfs4_label (struct dentry *dentry,const char *key, +const void *buf,size_t buflen, +int flags,int type) +{ +if (security_ismaclabel (key)) +return nfs4_set_security_label (dentry, buf, buflen); + +return -EOPNOTSUPP ; +} + +static int nfs4_xattr_get_nfs4_label (struct dentry *dentry,const char *key, +void *buf,size_t buflen,int type) +{ +if (security_ismaclabel (key)) +return nfs4_get_security_label (dentry->d_inode, buf, buflen); +return -EOPNOTSUPP ; +} + +static size_t nfs4_xattr_list_nfs4_label (struct dentry *dentry,char *list, +size_t list_len,const char *name, +size_t name_len,int type) +{ +size_t len =0 ; + +if (nfs_server_capable (dentry->d_inode,NFS_CAP_SECURITY_LABEL )) { + len =security_inode_listsecurity (dentry->d_inode,NULL ,0 ); +if (list && len <= list_len) +security_inode_listsecurity (dentry->d_inode, list, len); + } +return len; +} + +static const struct xattr_handler nfs4_xattr_nfs4_label_handler = { + .prefix =XATTR_SECURITY_PREFIX , + .list = nfs4_xattr_list_nfs4_label, + .get = nfs4_xattr_get_nfs4_label, + .set = nfs4_xattr_set_nfs4_label, +}; +#endif + +/* * nfs_fhget will use either the mounted_on_fileid or the fileid */
@@ -7242,6 +7289,9 @@ static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {const struct xattr_handler *nfs4_xattr_handlers[] = { &nfs4_xattr_nfs4_acl_handler, +#ifdef CONFIG_NFS_V4_SECURITY_LABEL + &nfs4_xattr_nfs4_label_handler, +#endifNULL };
security/security.c +1 -0
@@ -660,6 +660,7 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t bufferreturn 0 ;return security_ops->inode_listsecurity (inode, buffer, buffer_size); } +EXPORT_SYMBOL (security_inode_listsecurity);void security_inode_getsecid (const struct inode *inode,u32 *secid) {
Signature · 1 line
1.8.1.4
PATCH 12/14 Kconfig: Add Kconfig entry for Labeled NFS V4 client
In reply to Steve DicksonFrom: Steve Dickson <[email protected]>
This patch adds the NFS_V4_SECURITY_LABEL entry which enables security label support for the NFSv4 client
--- fs/nfs/Kconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
fs/nfs/Kconfig +18 -0
@@ -131,6 +131,24 @@ config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN If the NFS client is unchanged from the upstream kernel, this option should be set to the default "kernel.org". +config NFS_V4_SECURITY_LABEL + bool "Provide Security Label support for NFSv4 client" + depends on NFS_V4 && SECURITY + help + + Say Y here if you want enable fine-grained security label attribute + support for NFS version 4. Security labels allow security modules like + SELinux and Smack to label files to facilitate enforcement of their policies. + Without this an NFSv4 mount will have the same label on each file. + + If you do not wish to enable fine-grained security labels SELinux or + Smack policies on NFSv4 files, say N. + + WARNING: there is still a chance of backwards-incompatible protocol changes. + For now we recommend "Y" only for developers and testers." + + If unsure, say N. + config ROOT_NFS bool "Root file system on NFS" depends on NFS_FS=y && IP_PNP
Signature · 1 line
1.8.1.4
PATCH 13/14 NFSD: Server implementation of MAC Labeling
In reply to Steve DicksonFrom: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)
fs/nfsd/nfs4proc.c +41 -0
@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {
@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the
@@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);
@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:
fs/nfsd/nfs4xdr.c +111 -5
176 lines not on this page · raw message
fs/nfsd/nfsd.h +5 -1
@@ -311,7 +311,11 @@ void nfsd_lockd_shutdown(void); | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA \ | FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID) +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#define NFSD4_SUPPORTED_ATTRS_WORD2 FATTR4_WORD2_SECURITY_LABEL +#else #define NFSD4_SUPPORTED_ATTRS_WORD2 0 +#endif #define NFSD4_1_SUPPORTED_ATTRS_WORD0 \ NFSD4_SUPPORTED_ATTRS_WORD0
@@ -350,7 +354,7 @@ static inline u32 nfsd_suppattrs2(u32 minorversion)#define NFSD_WRITEABLE_ATTRS_WORD1 \ (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \ | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) -#define NFSD_WRITEABLE_ATTRS_WORD2 0 +#define NFSD_WRITEABLE_ATTRS_WORD2 FATTR4_WORD2_SECURITY_LABEL#define NFSD_SUPPATTR_EXCLCREAT_WORD0 \ NFSD_WRITEABLE_ATTRS_WORD0
fs/nfsd/vfs.c +29 -0
@@ -28,6 +28,7 @@#include <asm/uaccess.h> #include <linux/exportfs.h> #include <linux/writeback.h> +#include <linux/security.h> #ifdef CONFIG_NFSD_V3 #include "xdr3.h"
@@ -621,6 +622,34 @@ int nfsd4_is_junction(struct dentry *dentry)return 0 ;return 1 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ + error =fh_verify (rqstp, fhp,0 /* S_IFREG */ ,NFSD_MAY_SATTR ); +if (error) +return error; + + dentry = fhp->fh_dentry; + +mutex_lock (&dentry->d_inode->i_mutex); + host_error =security_inode_setsecctx (dentry, label->label, label->len); +mutex_unlock (&dentry->d_inode->i_mutex); +return nfserrno (host_error); +} +#else +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +return -EOPNOTSUPP ; +} +#endif +#endif /* defined(CONFIG_NFSD_V4) */ #ifdef CONFIG_NFSD_V3
fs/nfsd/vfs.h +2 -0
@@ -56,6 +56,8 @@ int nfsd_mountpoint(struct dentry *, struct svc_export *);__be32 nfsd4_set_nfs4_acl (struct svc_rqst *,struct svc_fh *,struct nfs4_acl *);int nfsd4_get_nfs4_acl (struct svc_rqst *,struct dentry *,struct nfs4_acl **); +__be32 nfsd4_set_nfs4_label (struct svc_rqst *,struct svc_fh *, +struct nfs4_label *);#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,
fs/nfsd/xdr4.h +3 -0
@@ -118,6 +118,7 @@ struct nfsd4_create {struct iattr cr_iattr;/* request */ struct nfsd4_change_info cr_cinfo;/* response */ struct nfs4_acl *cr_acl; +struct nfs4_label *cr_label; };#define cr_linklen u.link.namelen#define cr_linkname u.link.name
@@ -246,6 +247,7 @@ struct nfsd4_open {struct nfs4_file *op_file;/* used during processing */ struct nfs4_ol_stateid *op_stp;/* used during processing */ struct nfs4_acl *op_acl; +struct nfs4_label *op_label; };#define op_iattr iattr
@@ -330,6 +332,7 @@ struct nfsd4_setattr {u32 sa_bmval[3 ];/* request */ struct iattr sa_iattr;/* request */ struct nfs4_acl *sa_acl; +struct nfs4_label *sa_label; };struct nfsd4_setclientid {
Signature · 1 line
1.8.1.4
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
fs/nfsd/nfs4proc.c nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 929
Quoted 7 lines · Steve Dickson
fs/nfsd/nfs4proc.c +3
-0@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label);
I'm getting an error from setattr over NFS4.0, even when I don't have nfs4_label support compiled in, I'm not sure why.... Maybe sa_label isn't being initialized to NULL in that case?
(Reproduceable with pynfs 4.0 SATT13.)
...
Quoted 30 lines
index 2b2e239..b2b2e5a 100644
fs/nfsd/vfs.c +16
-0@@ -28,6 +28,7 @@#include <asm/uaccess.h> #include <linux/exportfs.h> #include <linux/writeback.h> +#include <linux/security.h> #ifdef CONFIG_NFSD_V3 #include "xdr3.h" @@ -621,6 +622,34 @@ int nfsd4_is_junction(struct dentry *dentry)return 0 ;return 1 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ + error =fh_verify (rqstp, fhp,0 /* S_IFREG */ ,NFSD_MAY_SATTR ); +if (error) +return error; + + dentry = fhp->fh_dentry; +
fs/nfsd/vfs.c int nfsd4_is_junction(struct dentry *dentry) · line 649
Quoted 10 lines
fs/nfsd/vfs.c +10
-0+mutex_lock (&dentry->d_inode->i_mutex); + host_error =security_inode_setsecctx (dentry, label->label, label->len); +mutex_unlock (&dentry->d_inode->i_mutex); + return nfserrno(host_error); +} +#else +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +return -EOPNOTSUPP ;
That's returning a kernel error number to an nfs client. You want something else, maybe nfserr_attrnotsupp?
But this actually should have been caught earlier by check_attr_support().
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to Steve DicksonQuoted 38 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +11
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,
fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;
Is there any way to avoid this?
How does the vfs open code handle this? It has to be able to set a security contexts atomically on open(O_CREAT), doesn't it?
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 52 lines · J. Bruce Fields
Quoted 38 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +11
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?
I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Quoted 6 lines
--b.
--
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
--
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.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 53 lines · Dave Quigley
Quoted 52 lines · J. Bruce Fields
Quoted 38 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +11
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 8 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by security_inode_init_security(), from the filesystem's create method.
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 70 lines · J. Bruce Fields
Quoted 57 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 19 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 8 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.
Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to nfsd4_security_inode_setsecctx is supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something like security_dentry_init_security which should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
Dave
Casey Schaufler
maintainerRe: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 78 lines · David Quigley
Quoted 70 lines · J. Bruce Fields
Quoted 57 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 19 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 8 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
Quoted 9 lines
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
Quoted 8 lines
Dave
Signature · 4 lines
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
--
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.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 89 lines · Casey Schaufler
Quoted 78 lines · David Quigley
Quoted 70 lines · J. Bruce Fields
Quoted 57 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 19 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 8 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
Quoted 9 lines
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
Quoted 6 lines
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
OK. We need a number. 2k?
--b.
Casey Schaufler
maintainerRe: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 85 lines · J. Bruce Fields
Quoted 84 lines · Casey Schaufler
Quoted 83 lines · David Quigley
Quoted 67 lines · J. Bruce Fields
Quoted 56 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c line 49
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 18 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 7 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
Quoted 7 lines
Quoted 6 lines
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
OK. We need a number. 2k?
Consider some of the kinds of attributes we are likely to see in the not to distant future:
Permitted access times, at around 100 bytes each.
Bell & LaPadula labels at 500 bytes each.
Signatures of various sizes and flavors.
HEPA restrictions
I think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
Quoted 7 lines
--b.
--
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
--
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.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 97 lines · Casey Schaufler
Quoted 85 lines · J. Bruce Fields
Quoted 84 lines · Casey Schaufler
Quoted 83 lines · David Quigley
Quoted 67 lines · J. Bruce Fields
Quoted 56 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c line 49
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 18 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 7 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.Quoted 7 lines
Quoted 6 lines
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
OK. We need a number. 2k?
Consider some of the kinds of attributes we are likely to see in the not to distant future:
Quoted 8 lines
Permitted access times, at around 100 bytes each. Bell & LaPadula labels at 500 bytes each. Signatures of various sizes and flavors.
HEPA restrictionsI think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
2k it is!
steved.
RE: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to Casey SchauflerI think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
What is a good, and working alternative for NFS in term of SE label?
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Casey Schaufler
Sent: Friday, March 29, 2013 3:10 PM
To: J. Bruce Fields
Cc: David Quigley; Steve Dickson; Trond Myklebust; J. Bruce Fields; David P. Quigley; Linux NFS list; Linux Security List; SELinux List; Casey Schaufler
Subject: Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 85 lines · J. Bruce Fields
Quoted 84 lines · Casey Schaufler
Quoted 83 lines · David Quigley
Quoted 67 lines · J. Bruce Fields
Quoted 56 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>---
fs/nfsd/nfs4proc.c| 41 +++++++++++++++++++fs/nfsd/nfs4xdr.c
| 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c index renamed from fs/nfsd/nfs4proc.c +0
-0ae73175..bb17589 100644
fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c line 49
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL #include +<linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 18 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 7 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
Quoted 7 lines
Quoted 6 lines
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
OK. We need a number. 2k?
Consider some of the kinds of attributes we are likely to see in the not to distant future:
Permitted access times, at around 100 bytes each.
Bell & LaPadula labels at 500 bytes each.
Signatures of various sizes and flavors.
HEPA restrictions
I think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
Quoted 8 lines
--b.
--
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
--
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.
--
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.
RE: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 1 line · Joseph
What is a good, and working alternative for NFS in term of SE label?
There isn't any unless you want to start a labeled cifs project. We looked at CIFS and NFSv4 back when I started this project and from what we saw NFS had the more open community. There are other solutions but they are not ideal. I believe someone did SELinux labels on network attached storage by treating the NAS as an iSCSI device. This isn't ideal because it has concurrency issues. Someone proposed xattr for NFSv4/NFSv3 support and that was shot down as well (and for good reason). I don't share Casey's skepticism about the long term importance of NFS. I think with NFSv4 and all the work that has gone into it we'll see NFS being important in Linux and enterprises for a very long time to come.
RE: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Thank you David.
It is good that the community at least support some short term solution. Labeled NFS has been working hard to get the community acceptance.
Thanks.
-----Original Message-----
From: David Quigley [mailto:[email protected]]
Sent: Monday, April 01, 2013 10:55 AM
To: Vu, Joseph
Cc: Casey Schaufler; J. Bruce Fields; Steve Dickson; Trond Myklebust; J. Bruce Fields; David P. Quigley; Linux NFS list; Linux Security List; SELinux List
Subject: RE: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 1 line · Joseph
What is a good, and working alternative for NFS in term of SE label?
There isn't any unless you want to start a labeled cifs project. We looked at CIFS and NFSv4 back when I started this project and from what we saw NFS had the more open community. There are other solutions but they are not ideal. I believe someone did SELinux labels on network attached storage by treating the NAS as an iSCSI device. This isn't ideal because it has concurrency issues. Someone proposed xattr for NFSv4/NFSv3 support and that was shot down as well (and for good reason). I don't share Casey's skepticism about the long term importance of NFS. I think with NFSv4 and all the work that has gone into it we'll see NFS being important in Linux and enterprises for a very long time to come.
--
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.
RE: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 21 lines · Joseph
Thank you David.
It is good that the community at least support some short term solution. Labeled NFS has been working hard to get the community acceptance.
Thanks.
-----Original Message-----
From: David Quigley [mailto:[email protected]]
Sent: Monday, April 01, 2013 10:55 AM
To: Vu, Joseph
Cc: Casey Schaufler; J. Bruce Fields; Steve Dickson; Trond Myklebust; J. Bruce Fields; David P. Quigley; Linux NFS list; Linux Security List; SELinux List
Subject: RE: [PATCH 13/14] NFSD: Server implementation of MAC LabelingQuoted 1 line · Joseph
What is a good, and working alternative for NFS in term of SE label?
Quoted 12 lines
There isn't any unless you want to start a labeled cifs project. We looked at CIFS and NFSv4 back when I started this project and from what we saw NFS had the more open community. There are other solutions but they are not ideal. I believe someone did SELinux labels on network attached storage by treating the NAS as an iSCSI device. This isn't ideal because it has concurrency issues. Someone proposed xattr for
NFSv4/NFSv3 support and that was shot down as well (and for good reason). I don't share Casey's skepticism about the long term importance of NFS. I think with NFSv4 and all the work that has gone into it we'll see NFS being important in Linux and enterprises for a very long time to come.
I don't consider this a short term solution. Labeled NFS is a long term solution with short term milestones that get us something working fairly quickly and I mean fairly quickly in IETF terms (about 5 years). I don't buy Casey's assessment that network file-system protocols are old school and on the way out. A number of storage vendors are doing lots of real work into new versions of NFS and CIFS and they are major technologies in enterprise storage. To be honest I can't even figure out what sort of "long term" solutions Casey is talking about. It looks like he strung together a bunch a buzz words together into some vague ephemeral concept. Typing his idea of future storage into Google doesn't really come up with anything substantive either.
Casey Schaufler
maintainerRe: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to Vu, JosephQuoted 3 lines · Joseph
I think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
What is a good, and working alternative for NFS in term of SE label?
Answering this simple question is complicated. For the short term, I don't think there is one. For the long term I think that there has to be a resource oriented shared storage mechanism that will be very different from anything we have today. We are on the cusp of the transition from the short term to the long term. NFS, CIFS and the like are old school solutions to file sharing, just as mode bits and SELinux are old school security paradigms.
I am on record as not favoring this implementation of security labeling in NFS. I believe that I understand the rationale for the approach, and as I don't have an alternative that hasn't been shot down three ways from Sunday I hope to make the best of it.
Quoted 123 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Casey Schaufler
Sent: Friday, March 29, 2013 3:10 PM
To: J. Bruce Fields
Cc: David Quigley; Steve Dickson; Trond Myklebust; J. Bruce Fields; David P. Quigley; Linux NFS list; Linux Security List; SELinux List; Casey Schaufler
Subject: Re: [PATCH 13/14] NFSD: Server implementation of MAC LabelingQuoted 85 lines · J. Bruce Fields
Quoted 84 lines · Casey Schaufler
Quoted 83 lines · David Quigley
Quoted 67 lines · J. Bruce Fields
Quoted 56 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>---
fs/nfsd/nfs4proc.c| 41 +++++++++++++++++++fs/nfsd/nfs4xdr.c
| 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c index renamed from fs/nfsd/nfs4proc.c +0
-0ae73175..bb17589 100644
fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c line 49
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL #include +<linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 18 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 7 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.Quoted 6 lines
So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going to see a lot of opens that set the label?)
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out. Also where did we come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.Quoted 7 lines
Quoted 6 lines
If anyone cares, Smack labels can (now) be 255 characters. Also, when (if) we get multiple concurrent LSMs the "security context" may include information for more than one LSM. 128 bytes is going to look pretty tiny then.
smack='com.corportation.service'selinux='system_u:object_r:bin_t:s0'
OK. We need a number. 2k?
Consider some of the kinds of attributes we are likely to see in the not to distant future:
Permitted access times, at around 100 bytes each.
Bell & LaPadula labels at 500 bytes each.
Signatures of various sizes and flavors.
HEPA restrictionsI think 2k will do for a while. I think that in the long run it will come up short. I think the real question is whether NFS will remain viable long enough for it to matter.
Quoted 7 lines
--b.
--
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--
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.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to David QuigleyQuoted 77 lines · David Quigley
Quoted 76 lines · J. Bruce Fields
Quoted 57 lines · Dave Quigley
Quoted 4 lines · J. Bruce Fields
Quoted 3 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on
the server for
Quoted 1 line
Quoted 1 line
the purpose of sending them to the client and also to process
label change
Quoted 9 lines
Quoted 9 lines
requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116++++++++++++++++++++++++++++++++++++++++++++++++++---
Quoted 14 lines
Quoted 14 lines
fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" Quoted 5 lines
fs/nfsd/nfs4proc.c
Quoted 5 lines
fs/nfsd/nfs4proc.c +5
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct
nfs4_label*label, u32 *bmval)Quoted 19 lines
Quoted 6 lines
fs/nfsd/nfs4proc.c +6
-0+{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 8 lines
Quoted 3 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?I believe the way this is handled is that the inode is created and labeled and then only after that is it bound to the namespace. Because of that ordering we can fail and release the inode without it ever having a dentry in the namespace.
Grepping around.... Looks like that's done by
security_inode_init_security(), from the filesystem's create method.So we'd need to be able to pass something down to there.
Is the current client actually expected to use this? (So are we going
to see a lot of opens that set the label?)
Quoted 8 lines
Quoted 1 line
--b.
I don't have all the code infront of me but we have a different hook to do that. The call to
nfsd4_security_inode_setsecctxis supposed to be used from the setattr handlers to do the equivalent of a setxattr on the file over NFS. The actual creation gets done with something likesecurity_dentry_init_securitywhich should be in an earlier patch. I'd have to look more clearly at the code to find out.
Anytime an EVM 'protected' xattr is created/modified/deleted, EVM needs to be called to calculate and write the 'security.evm' hmac. It looks like the security_inode_setsecctx() hook is missing the EVM call. Instead of writing the LSM label, immediately followed by the EVM label, security_inode_init_security() creates the list of xattrs to be written. Only then, it calls the fs to write them. I would think that security_inode_setsecctx() would need to do something similar.
thanks,
Mimi
Quoted 4 lines
Also where did we
come up with 128 for label length? The SELinux code assumes a starting point of 255 and goes up from there as needed. The MLS policies will definitely exceed a 128 byte label.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to J. Bruce FieldsQuoted 52 lines · J. Bruce Fields
Quoted 38 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +11
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status = security_inode_setsecctx(resfh->fh_dentry,fs/nfsd/nfs4proc.c line 65
Quoted 10 lines
fs/nfsd/nfs4proc.c +10
-0+ label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;Is there any way to avoid this?
Quoted 2 lines
How does the vfs open code handle this? It has to be able to set a security contexts atomically on
open(O_CREAT), doesn't it?
The security guys are going have to answer this definitely but from greping through the code, it appears the permission checking on the path to the object is done before the object is created.
Stephen, Eric??
steved.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to Steve DicksonQuoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/*
fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );
This is returned as NFS4ERR_NAMETOOLONG.
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +if (bmval[2 ] &FATTR4_WORD2_SECURITY_LABEL ) { +uint32_t pi; +uint32_t lfs; + +READ_BUF (4 ); + len +=4 ; +READ32 (lfs); +READ_BUF (4 ); + len +=4 ;
fs/nfsd/nfs4xdr.c nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, · line 432
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+READ32 (pi); +READ_BUF (4 ); + len +=4 ; +READ32 (dummy32); +READ_BUF (dummy32); + len += (XDR_QUADLEN (dummy32) <<2 ); +READMEM (buf, dummy32); + + *label =nfsd4_label_alloc (dummy32); +if (*label ==NULL ) {
Careful! That should be IS_ERR(*label).
fs/nfsd/nfs4xdr.c nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, · line 433
Quoted 1 line
fs/nfsd/nfs4xdr.c +1
-0+ host_err =PTR_ERR (label);
And that should be *label.
Quoted 19 lines
static
__be32fs/nfsd/nfs4xdr.c +14
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label (struct svc_rqst *rqstp,struct dentry *dentry,__be32 **pp,int *buflen) +{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void )security_inode_getsecctx (dentry->d_inode, &context, &len); +if (len <0 )
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource; + goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */
Could we better a better comment here?
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2072
Quoted 2 lines
fs/nfsd/nfs4xdr.c +2
-0+ +if ((*buflen -=4 ) <0 )
Looks like that should be 8.
Quoted 12 lines
fs/nfsd/nfs4xdr.c +12
-0+return nfserr_resource; + +WRITE32 (lfs); +WRITE32 (pi); + p =xdr_encode_opaque (p, context, len); + *buflen -= (XDR_QUADLEN (len) <<2 ) +4 ; + + *pp = p; +out: +security_release_secctx (context, len); +return err; +}
...
fs/nfsd/nfs4xdr.c
Quoted 9 lines
fs/nfsd/nfs4xdr.c +9
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */
Again: could we get an answer to this question?
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Dave, I think these are both questions for you?
--b.
Quoted 31 lines · bfields
Quoted 18 lines · Steve Dickson
fs/nfsd/nfs4xdr.c +14
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label (struct svc_rqst *rqstp,struct dentry *dentry,__be32 **pp,int *buflen) +{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void )security_inode_getsecctx (dentry->d_inode, &context, &len); +if (len <0 )fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource; + goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */ Could we better a better comment here?
...
Quoted 13 lines
fs/nfsd/vfs.c int nfsd4_is_junction(struct dentry *dentry) · line 633
Quoted 9 lines
fs/nfsd/vfs.c +9
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ Again: could we get an answer to this question?
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 36 lines · J. Bruce Fields
Dave, I think these are both questions for you?
--b.
Quoted 31 lines · bfields
Quoted 18 lines · Steve Dickson
fs/nfsd/nfs4xdr.c +14
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label (struct svc_rqst *rqstp,struct dentry *dentry,__be32 **pp,int *buflen) +{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void )security_inode_getsecctx (dentry->d_inode, &context, &len); +if (len <0 )fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource; + goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */ Could we better a better comment here?
We could remove this comment all together if you want. We're trying to indicate that at some point in the future there will be a label translation facility like idmapd but for labels instead. This is where the call would go if we had it. I had a basic version of the code a long time ago and that is where I had the call but there was way too much work to make it usable for now. Instead I just pass the null translation indicator on the wire and we wave our hands and say don't look at the man behind the curtain.
Quoted 12 lines
...
Quoted 11 lines
fs/nfsd/vfs.c int nfsd4_is_junction(struct dentry *dentry) · line 633
Quoted 9 lines
fs/nfsd/vfs.c +9
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ Again: could we get an answer to this question?
I'm pretty sure we can just remove that comment. It was a question from about 5 years ago now and I never found a compelling reason to say yes to it.
Quoted 7 lines
Quoted 2 lines
--b.
--
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
--
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.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 38 lines · Dave Quigley
Quoted 36 lines · J. Bruce Fields
Dave, I think these are both questions for you?
--b.
Quoted 31 lines · bfields
Quoted 18 lines · Steve Dickson
fs/nfsd/nfs4xdr.c +14
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label (struct svc_rqst *rqstp,struct dentry *dentry,__be32 **pp,int *buflen) +{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void )security_inode_getsecctx (dentry->d_inode, &context, &len); +if (len <0 )fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource; + goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */ Could we better a better comment here?
Quoted 8 lines
We could remove this comment all together if you want. We're trying to indicate that at some point in the future there will be a label translation facility like idmapd but for labels instead. This is where the call would go if we had it. I had a basic version of the code a long time ago and that is where I had the call but there was way too much work to make it usable for now. Instead I just pass the null translation indicator on the wire and we wave our hands and say don't look at the man behind the curtain.
So how about just:
/* * For now we use a 0 here to indicate the null translation; in * the future we may place a call to translation code here. */
Quoted 14 lines
Quoted 13 lines
...
Quoted 11 lines
fs/nfsd/vfs.c int nfsd4_is_junction(struct dentry *dentry) · line 633
Quoted 9 lines
fs/nfsd/vfs.c +9
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ Again: could we get an answer to this question?
Quoted 3 lines
I'm pretty sure we can just remove that comment. It was a question from about 5 years ago now and I never found a compelling reason to say yes to it.
OK, let's remove the comment.
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 51 lines · J. Bruce Fields
Quoted 41 lines · Dave Quigley
Quoted 7 lines · J. Bruce Fields
Dave, I think these are both questions for you?
--b.
Quoted 2 lines · bfields
Review nfsd4_encode_aclname(struct svc_rqst
Quoted 1 line · Steve Dickson
(quoted diff) +0
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst*rqstp, struct
nfs4_ace*ace,Quoted 6 lines
Quoted 6 lines
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
Quoted 6 lines
fs/nfsd/nfs4xdr.c +3
-0FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label(struct svc_rqst *rqstp, structdentry *dentry,
__be32**pp, int *buflen)Quoted 10 lines
Quoted 10 lines
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void)security_inode_getsecctx(dentry->d_inode, &context,&len);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/nfsd/nfs4xdr.c +5
-0+if (len <0 ) +return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource;Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 6 lines
fs/nfsd/nfs4xdr.c +6
-0+ goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */ Could we better a better comment here?
Quoted 8 lines
We could remove this comment all together if you want. We're trying to indicate that at some point in the future there will be a label translation facility like idmapd but for labels instead. This is where the call would go if we had it. I had a basic version of the code a long time ago and that is where I had the call but there was way too much work to make it usable for now. Instead I just pass the null translation indicator on the wire and we wave our hands and say don't look at the man behind the curtain.
Quoted 7 lines
So how about just:
/* * For now we use a 0 here to indicate the null translation; in * the future we may place a call to translation code here. */
Works for me.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
...
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct
svc_fh*fhp,Quoted 9 lines
Quoted 9 lines
fs/nfsd/vfs.c int nfsd4_is_junction(struct dentry *dentry) · line 633
Quoted 7 lines
fs/nfsd/vfs.c +7
-0+ struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ Again: could we get an answer to this question?
Quoted 6 lines
Quoted 3 lines
I'm pretty sure we can just remove that comment. It was a question from about 5 years ago now and I never found a compelling reason to say yes to it.
OK, let's remove the comment.
Agreed
Quoted 1 line
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
In reply to J. Bruce FieldsQuoted 123 lines · J. Bruce Fields
Quoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/* fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );This is returned as
NFS4ERR_NAMETOOLONG.
Quoted 3 lines
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
The 4.2 spec (draft-ietf-nfsv4-minorversion2-19.txt) defines two Labeled NFS errors:NFS4ERR_BADLABEL (Error Code 10093)NFS4ERR_WRONG_LFS (Error Code 10092)
and we currently don't define either one of them... So I guess that will have to change...
So what should NFS4ERR_BADLABEL map to in nfserrno()?
Quoted 24 lines
Quoted 11 lines
fs/nfsd/nfs4xdr.c +10
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +if (bmval[2 ] &FATTR4_WORD2_SECURITY_LABEL ) { +uint32_t pi; +uint32_t lfs; + +READ_BUF (4 ); + len +=4 ; +READ32 (lfs); +READ_BUF (4 ); + len +=4 ;fs/nfsd/nfs4xdr.c nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, · line 432
Quoted 10 lines
fs/nfsd/nfs4xdr.c +10
-0+READ32 (pi); +READ_BUF (4 ); + len +=4 ; +READ32 (dummy32); +READ_BUF (dummy32); + len += (XDR_QUADLEN (dummy32) <<2 ); +READMEM (buf, dummy32); + + *label =nfsd4_label_alloc (dummy32); +if (*label ==NULL ) {Careful! That should be
IS_ERR(*label).
Quoted 3 lines
fs/nfsd/nfs4xdr.c nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, · line 433
Quoted 1 line
fs/nfsd/nfs4xdr.c +1
-0+ host_err =PTR_ERR (label);And that should be *label.
Gotta it...
Quoted 24 lines
Quoted 24 lines
static
__be32fs/nfsd/nfs4xdr.c +18
-0@@ -1988,6 +2044,50 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, FATTR4_WORD0_RDATTR_ERROR)#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static inline __be32 +nfsd4_encode_security_label (struct svc_rqst *rqstp,struct dentry *dentry,__be32 **pp,int *buflen) +{ +void *context; +int err; +int len; +uint32_t pi =0 ; +uint32_t lfs =0 ; +__be32 *p = *pp; + + err =0 ; + (void )security_inode_getsecctx (dentry->d_inode, &context, &len); +if (len <0 ) +return nfserrno (len); + +if (*buflen < ((XDR_QUADLEN (len) <<2 ) +4 +4 +4 )) { + err = nfserr_resource;
Quoted 8 lines
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2070
Quoted 6 lines
fs/nfsd/nfs4xdr.c +6
-0+ goto out; + } + +/* XXX: A call to the translation code should be placed here +* for now send 0 until we have that to indicate the null +* translation */ Could we better a better comment here?
Changed to:
/*
* For now we use a 0 here to indicate the null translation; in
* the future we may place a call to translation code here. */
Quoted 5 lines
fs/nfsd/nfs4xdr.c nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, · line 2072
Quoted 3 lines
fs/nfsd/nfs4xdr.c +2
-0+ +if ((*buflen -=4 ) <0 )Looks like that should be 8.
Right...
Quoted 15 lines
Quoted 13 lines
fs/nfsd/nfs4xdr.c +12
-0+return nfserr_resource; + +WRITE32 (lfs); +WRITE32 (pi); + p =xdr_encode_opaque (p, context, len); + *buflen -= (XDR_QUADLEN (len) <<2 ) +4 ; + + *pp = p; +out: +security_release_secctx (context, len); +return err; +}...
Quoted 11 lines
fs/nfsd/nfs4xdr.c
Quoted 9 lines
fs/nfsd/nfs4xdr.c +9
-0+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +__be32 nfsd4_set_nfs4_label (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct nfs4_label *label) +{ +__be32 error; +int host_error; +struct dentry *dentry; + +/* XXX: should we have a MAY_SSECCTX? */ Again: could we get an answer to this question?
Gone... just a bad dream! ;-)
Thank you the cycles!
steved.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 129 lines · Steve Dickson
Quoted 123 lines · J. Bruce Fields
Quoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/* fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );This is returned as
NFS4ERR_NAMETOOLONG.Quoted 3 lines
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
Quoted 7 lines
The 4.2 spec (draft-ietf-nfsv4-minorversion2-19.txt) defines two Labeled NFS errors:
NFS4ERR_BADLABEL(Error Code 10093)NFS4ERR_WRONG_LFS(Error Code 10092)and we currently don't define either one of them... So I guess that will have to change...
http://tools.ietf.org/html/draft-ietf-nfsv4-minorversion2-19#section-11.1.3.1
just says "The label specified is invalid in some manner" for NFS4ERR_BADLABEL.
Anyway, that sounds like the right one for this case....
Quoted 1 line
So what should
NFS4ERR_BADLABELmap to innfserrno()?
I don't know; I guess I'd check out what errors can be returned from the code that sets a context.
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 142 lines · J. Bruce Fields
Quoted 129 lines · Steve Dickson
Quoted 123 lines · J. Bruce Fields
Quoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/* fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );This is returned as
NFS4ERR_NAMETOOLONG.Quoted 3 lines
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
Quoted 7 lines
The 4.2 spec (draft-ietf-nfsv4-minorversion2-19.txt) defines two Labeled NFS errors:
NFS4ERR_BADLABEL(Error Code 10093)NFS4ERR_WRONG_LFS(Error Code 10092)and we currently don't define either one of them... So I guess that will have to change...
http://tools.ietf.org/html/draft-ietf-nfsv4-minorversion2-19#section-11.1.3.1
just says "The label specified is invalid in some manner" forNFS4ERR_BADLABEL.
Quoted 6 lines
Anyway, that sounds like the right one for this case....
Quoted 1 line
So what should
NFS4ERR_BADLABELmap to innfserrno()?I don't know; I guess I'd check out what errors can be returned from the code that sets a context.
Looking looking at the code under security/selinux, the popular returns seem to be are-EOPNOTSUPP, -EACCES, -EPERM and -EINVAL.
I say we go with -EINVAL....
steved.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 149 lines · Steve Dickson
Quoted 146 lines · J. Bruce Fields
Quoted 129 lines · Steve Dickson
Quoted 123 lines · J. Bruce Fields
Quoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/* fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );This is returned as
NFS4ERR_NAMETOOLONG.Quoted 3 lines
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
Quoted 7 lines
The 4.2 spec (draft-ietf-nfsv4-minorversion2-19.txt) defines two Labeled NFS errors:
NFS4ERR_BADLABEL(Error Code 10093)NFS4ERR_WRONG_LFS(Error Code 10092)and we currently don't define either one of them... So I guess that will have to change...
http://tools.ietf.org/html/draft-ietf-nfsv4-minorversion2-19#section-11.1.3.1
just says "The label specified is invalid in some manner" forNFS4ERR_BADLABEL.Anyway, that sounds like the right one for this case....
Quoted 1 line
So what should
NFS4ERR_BADLABELmap to innfserrno()?
Quoted 7 lines
Quoted 2 lines
I don't know; I guess I'd check out what errors can be returned from the code that sets a context.
Looking looking at the code under
security/selinux, the popular returns seem to be are-EOPNOTSUPP,-EACCES,-EPERMand-EINVAL.I say we go with
-EINVAL....
Note nfserrno() converts from -ERR to nfs4 errors. You may be thinking of the client side nfs4_stat_to_errno().
--b.
Re: [PATCH 13/14] NFSD: Server implementation of MAC Labeling
Quoted 152 lines · J. Bruce Fields
Quoted 151 lines · Steve Dickson
Quoted 148 lines · J. Bruce Fields
Quoted 129 lines · Steve Dickson
Quoted 123 lines · J. Bruce Fields
Quoted 109 lines · Steve Dickson
From: David Quigley <[email protected]>
This patch adds the ability to encode and decode file labels on the server for the purpose of sending them to the client and also to process label change requests from the client.
Signed-off-by Matthew N. Dodd <[email protected]>Signed-off-by Miguel Rodel Felipe <[email protected]>Signed-off-by Phua Eu Gene <[email protected]>Signed-off-by Khin Mi Mi Aung <[email protected]>--- fs/nfsd/nfs4proc.c | 41 +++++++++++++++++++ fs/nfsd/nfs4xdr.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 6 ++- fs/nfsd/vfs.c | 29 ++++++++++++++ fs/nfsd/vfs.h | 2 + fs/nfsd/xdr4.h | 3 ++ 6 files changed, 191 insertions(+), 6 deletions(-)fs/nfsd/nfs4proc.c +41
-0@@ -42,6 +42,36 @@#include "current_stateid.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> + +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ +struct inode *inode = resfh->fh_dentry->d_inode; +int status; + +mutex_lock (&inode->i_mutex); + status =security_inode_setsecctx (resfh->fh_dentry, + label->label, label->len); +mutex_unlock (&inode->i_mutex); + +if (status) +/* +* We should probably fail the whole open at this point, +* but we've already created or opened the file, so it's +* too late; So this seems the least of evils: +*/ + bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; + +return ; +} +#else +static inline void +nfsd4_security_inode_setsecctx (struct svc_fh *resfh,struct nfs4_label *label,u32 *bmval) +{ } +#endif +#define NFSDDBG_FACILITY NFSDDBG_PROCstatic u32 nfsd_attrmask[] = {@@ -230,6 +260,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o (u32 *)open->op_verf.data, &open->op_truncate, &open->op_created); +if (!status && open->op_label !=NULL ) +nfsd4_security_inode_setsecctx (resfh, open->op_label, open->op_bmval); +/* * Following rfc 3530 14.2.16, use the returned bitmask * to indicate which attributes we used to store the @@ -599,6 +632,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; +if (create->cr_label !=NULL ) +nfsd4_security_inode_setsecctx (&resfh, create->cr_label, create->cr_bmval); +if (create->cr_acl !=NULL )do_set_nfs4_acl (rqstp, &resfh, create->cr_acl, create->cr_bmval);@@ -888,6 +924,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, setattr->sa_acl);if (status) goto out; +if (setattr->sa_label !=NULL ) + status =nfsd4_set_nfs4_label (rqstp, &cstate->current_fh, + setattr->sa_label); +if (status) + goto out; status =nfsd_setattr (rqstp, &cstate->current_fh, &setattr->sa_iattr,0 , (time_t )0 ); out:fs/nfsd/nfs4xdr.c +5
-0@@ -55,6 +55,11 @@#include "cache.h" #include "netns.h" +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +#include <linux/security.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_XDR/* fs/nfsd/nfs4xdr.c check_filename(char *str, int len) · line 93
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -79,6 +84,24 @@ check_filename(char *str, int len)return nfserr_badname;return 0 ; } +#ifdef CONFIG_NFSD_V4_SECURITY_LABEL +static struct nfs4_label *nfsd4_label_alloc (u32 len) +{ +struct nfs4_label *label =NULL ; + +if (len >NFS4_MAXLABELLEN ) +return ERR_PTR (-ENAMETOOLONG );This is returned as
NFS4ERR_NAMETOOLONG.Quoted 3 lines
The 4.2 spec should note this case, if it's the right error. rfc 5661 says that error's only for filenames, and doesn't allow it for setattr (which doesn't take a filename).
Quoted 7 lines
The 4.2 spec (draft-ietf-nfsv4-minorversion2-19.txt) defines two Labeled NFS errors:
NFS4ERR_BADLABEL(Error Code 10093)NFS4ERR_WRONG_LFS(Error Code 10092)and we currently don't define either one of them... So I guess that will have to change...
http://tools.ietf.org/html/draft-ietf-nfsv4-minorversion2-19#section-11.1.3.1
just says "The label specified is invalid in some manner" forNFS4ERR_BADLABEL.Anyway, that sounds like the right one for this case....
Quoted 1 line
So what should
NFS4ERR_BADLABELmap to innfserrno()?I don't know; I guess I'd check out what errors can be returned from the code that sets a context.
Quoted 8 lines
Quoted 5 lines
Looking looking at the code under
security/selinux, the popular returns seem to be are-EOPNOTSUPP,-EACCES,-EPERMand-EINVAL.I say we go with
-EINVAL....Note
nfserrno()converts from-ERRto nfs4 errors. You may be thinking of the client sidenfs4_stat_to_errno().
I was looking at nfsd4_decode_fattr()... If nfsd4_label_alloc() does fail, host_err is set and we jump to out_nfserr:. Then status is then set by the return value of nfserrno(host_err); I'm thinking that status should be set to -EINVAL
steved.
PATCH 14/14 Kconfig: Add Kconfig entry for Labeled NFS V4 server
In reply to Steve DicksonFrom: Steve Dickson <[email protected]>
This patch adds the NFSd_V4_SECURITY_LABEL entry which enables security label support for the NFSv4 server
--- fs/nfsd/Kconfig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/nfsd/Kconfig +16 -0
@@ -81,6 +81,22 @@ config NFSD_V4 If unsure, say N. +config NFSD_V4_SECURITY_LABEL + bool "Provide Security Label support for NFSv4 server" + depends on NFSD_V4 && SECURITY + help + + Say Y here if you want enable fine-grained security label attribute + support for NFS version 4. Security labels allow security modules like + SELinux and Smack to label files to facilitate enforcement of their policies. + Without this an NFSv4 mount will have the same label on each file. + + If you do not wish to enable fine-grained security labels SELinux or + Smack policies on NFSv4 files, say N. + + WARNING: there is still a chance of backwards-incompatible protocol changes. + For now we recommend "Y" only for developers and testers." + config NFSD_FAULT_INJECTION bool "NFS server manual fault injection" depends on NFSD_V4 && DEBUG_KERNEL
Signature · 1 line
1.8.1.4