diff options
Diffstat (limited to 'fs/jfs/xattr.c')
-rw-r--r-- | fs/jfs/xattr.c | 67 |
1 files changed, 10 insertions, 57 deletions
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c index 23aa5066b5a4..f23048f9471f 100644 --- a/fs/jfs/xattr.c +++ b/fs/jfs/xattr.c | |||
@@ -17,6 +17,7 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/capability.h> | ||
20 | #include <linux/fs.h> | 21 | #include <linux/fs.h> |
21 | #include <linux/xattr.h> | 22 | #include <linux/xattr.h> |
22 | #include <linux/posix_acl_xattr.h> | 23 | #include <linux/posix_acl_xattr.h> |
@@ -83,21 +84,6 @@ struct ea_buffer { | |||
83 | #define EA_NEW 0x0004 | 84 | #define EA_NEW 0x0004 |
84 | #define EA_MALLOC 0x0008 | 85 | #define EA_MALLOC 0x0008 |
85 | 86 | ||
86 | /* Namespaces */ | ||
87 | #define XATTR_SYSTEM_PREFIX "system." | ||
88 | #define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1) | ||
89 | |||
90 | #define XATTR_USER_PREFIX "user." | ||
91 | #define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1) | ||
92 | |||
93 | #define XATTR_OS2_PREFIX "os2." | ||
94 | #define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1) | ||
95 | |||
96 | /* XATTR_SECURITY_PREFIX is defined in include/linux/xattr.h */ | ||
97 | #define XATTR_SECURITY_PREFIX_LEN (sizeof (XATTR_SECURITY_PREFIX) - 1) | ||
98 | |||
99 | #define XATTR_TRUSTED_PREFIX "trusted." | ||
100 | #define XATTR_TRUSTED_PREFIX_LEN (sizeof (XATTR_TRUSTED_PREFIX) - 1) | ||
101 | 87 | ||
102 | /* | 88 | /* |
103 | * These three routines are used to recognize on-disk extended attributes | 89 | * These three routines are used to recognize on-disk extended attributes |
@@ -773,36 +759,23 @@ static int can_set_system_xattr(struct inode *inode, const char *name, | |||
773 | static int can_set_xattr(struct inode *inode, const char *name, | 759 | static int can_set_xattr(struct inode *inode, const char *name, |
774 | const void *value, size_t value_len) | 760 | const void *value, size_t value_len) |
775 | { | 761 | { |
776 | if (IS_RDONLY(inode)) | 762 | if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) |
777 | return -EROFS; | ||
778 | |||
779 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) | ||
780 | return -EPERM; | ||
781 | |||
782 | if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0) | ||
783 | /* | ||
784 | * "system.*" | ||
785 | */ | ||
786 | return can_set_system_xattr(inode, name, value, value_len); | 763 | return can_set_system_xattr(inode, name, value, value_len); |
787 | 764 | ||
788 | if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) | 765 | /* |
789 | return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM); | 766 | * Don't allow setting an attribute in an unknown namespace. |
790 | 767 | */ | |
791 | #ifdef CONFIG_JFS_SECURITY | 768 | if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) && |
792 | if (strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) | 769 | strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) && |
793 | == 0) | 770 | strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && |
794 | return 0; /* Leave it to the security module */ | 771 | strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) |
795 | #endif | ||
796 | |||
797 | if((strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) != 0) && | ||
798 | (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) != 0)) | ||
799 | return -EOPNOTSUPP; | 772 | return -EOPNOTSUPP; |
800 | 773 | ||
801 | if (!S_ISREG(inode->i_mode) && | 774 | if (!S_ISREG(inode->i_mode) && |
802 | (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX)) | 775 | (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX)) |
803 | return -EPERM; | 776 | return -EPERM; |
804 | 777 | ||
805 | return permission(inode, MAY_WRITE, NULL); | 778 | return 0; |
806 | } | 779 | } |
807 | 780 | ||
808 | int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, | 781 | int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, |
@@ -972,22 +945,6 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value, | |||
972 | return rc; | 945 | return rc; |
973 | } | 946 | } |
974 | 947 | ||
975 | static int can_get_xattr(struct inode *inode, const char *name) | ||
976 | { | ||
977 | #ifdef CONFIG_JFS_SECURITY | ||
978 | if(strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) | ||
979 | return 0; | ||
980 | #endif | ||
981 | |||
982 | if(strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) | ||
983 | return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM); | ||
984 | |||
985 | if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0) | ||
986 | return 0; | ||
987 | |||
988 | return permission(inode, MAY_READ, NULL); | ||
989 | } | ||
990 | |||
991 | ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, | 948 | ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, |
992 | size_t buf_size) | 949 | size_t buf_size) |
993 | { | 950 | { |
@@ -998,12 +955,8 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, | |||
998 | ssize_t size; | 955 | ssize_t size; |
999 | int namelen = strlen(name); | 956 | int namelen = strlen(name); |
1000 | char *os2name = NULL; | 957 | char *os2name = NULL; |
1001 | int rc; | ||
1002 | char *value; | 958 | char *value; |
1003 | 959 | ||
1004 | if ((rc = can_get_xattr(inode, name))) | ||
1005 | return rc; | ||
1006 | |||
1007 | if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { | 960 | if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { |
1008 | os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1, | 961 | os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1, |
1009 | GFP_KERNEL); | 962 | GFP_KERNEL); |