[PATCH] Backport of security_inode_post_setxattr hook

From: James Carter (jwcart2@private)
Date: Fri Sep 26 2003 - 08:18:29 PDT

  • Next message: James Carter: "[PATCH] Backport of security_d_instantiate hook move"

    This patch against lsm-2.4 is a backport of the changes accepted into
    the 2.5/6 kernel to add the security_inode_post_setxattr hook.  It adds
    a security_inode_post_setxattr hook so that security modules can update
    the inode security structure after a successful setxattr.
    
    The new 2.4-based SELinux (a backport of the 2.6-based SELinux) depends
    on these, so we'd like to get them into the lsm-2.4 tree so that we can
    also merge the new 2.4-based SELinux into it.
    
    For reference see Steve's LSM email of 28 Apr 2003.
    http://mail.wirex.com/pipermail/linux-security-module/2003-April/4330.html
    
    If there are no objections, I will ask Steve to merge it.
    
    
     fs/xattr.c               |    9 +++++----
     include/linux/security.h |   15 +++++++++++++++
     security/dummy.c         |    6 ++++++
     3 files changed, 26 insertions(+), 4 deletions(-)
    
    diff -Nru a/fs/xattr.c b/fs/xattr.c
    --- a/fs/xattr.c	Thu Sep 25 15:18:05 2003
    +++ b/fs/xattr.c	Thu Sep 25 15:18:05 2003
    @@ -85,17 +85,18 @@
     
     	error = -EOPNOTSUPP;
     	if (d->d_inode->i_op && d->d_inode->i_op->setxattr) {
    +		down(&d->d_inode->i_sem);
    +		lock_kernel();
     		error = security_inode_setxattr(d, kname, kvalue, size, flags);
     		if (error)
     			goto out;
    -		down(&d->d_inode->i_sem);
    -		lock_kernel();
     		error = d->d_inode->i_op->setxattr(d, kname, kvalue, size, flags);
    +		if (!error)
    +			security_inode_post_setxattr(d, kname, kvalue, size, flags);
    +out:
     		unlock_kernel();
     		up(&d->d_inode->i_sem);
     	}
    -
    -out:
     	xattr_free(kvalue, size);
     	return error;
     }
    diff -Nru a/include/linux/security.h b/include/linux/security.h
    --- a/include/linux/security.h	Thu Sep 25 15:18:05 2003
    +++ b/include/linux/security.h	Thu Sep 25 15:18:05 2003
    @@ -360,6 +360,9 @@
      * 	Check permission before setting the extended attributes
      * 	@value identified by @name for @dentry.
      * 	Return 0 if permission is granted.
    + * @inode_post_setxattr:
    + * 	Update inode security field after successful setxattr operation.
    + * 	@value identified by @name for @dentry.
      * @inode_getxattr:
      * 	Check permission before obtaining the extended attributes
      * 	identified by @name for @dentry.
    @@ -1306,6 +1309,8 @@
     	int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
     	int (*inode_permission) (struct inode *inode, int mask);
             int (*inode_revalidate) (struct dentry *dentry);
    +	void (*inode_post_setxattr) (struct dentry *dentry, char *name, void *value,
    +				     size_t size, int flags);
     	int (*inode_setattr)	(struct dentry *dentry, struct iattr *attr);
             int (*inode_stat) (struct inode *inode);
             void (*inode_delete) (struct inode *inode);
    @@ -1864,6 +1869,12 @@
     	return security_ops->inode_setxattr (dentry, name, value, size, flags);
     }
     
    +static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
    +						void *value, size_t size, int flags)
    +{
    +	security_ops->inode_post_setxattr (dentry, name, value, size, flags);
    +}
    +
     static inline int security_inode_getxattr (struct dentry *dentry, char *name)
     {
     	return security_ops->inode_getxattr (dentry, name);
    @@ -2557,6 +2568,10 @@
     {
     	return 0;
     }
    +
    +static inline void security_inode_post_setxattr (struct dentry *dentry, char *name,
    +						 void *value, size_t size, int flags)
    +{ }
     
     static inline int security_inode_getxattr (struct dentry *dentry, char *name)
     {
    diff -Nru a/security/dummy.c b/security/dummy.c
    --- a/security/dummy.c	Thu Sep 25 15:18:05 2003
    +++ b/security/dummy.c	Thu Sep 25 15:18:05 2003
    @@ -432,6 +432,11 @@
     	return 0;
     }
     
    +static void dummy_inode_post_setxattr (struct dentry *dentry, char *name, void *value,
    +				       size_t size, int flags)
    +{
    +}
    +
     static int dummy_inode_getxattr (struct dentry *dentry, char *name)
     {
     	return 0;
    @@ -1014,6 +1019,7 @@
     	set_to_dummy_if_null(ops, inode_stat);
     	set_to_dummy_if_null(ops, inode_delete);
     	set_to_dummy_if_null(ops, inode_setxattr);
    +	set_to_dummy_if_null(ops, inode_post_setxattr);
     	set_to_dummy_if_null(ops, inode_getxattr);
     	set_to_dummy_if_null(ops, inode_listxattr);
     	set_to_dummy_if_null(ops, inode_removexattr);
    
     
    -- 
    James Carter <jwcart2@private>
    National Security Agency
    



    This archive was generated by hypermail 2b30 : Fri Sep 26 2003 - 08:18:55 PDT