Whamcloud - gitweb
LU-1838 llite: trusted. xattr is invisible to non-root
authorFan Yong <yong.fan@whamcloud.com>
Thu, 6 Sep 2012 16:18:05 +0000 (00:18 +0800)
committerJohann Lombardi <johann@whamcloud.com>
Thu, 13 Sep 2012 08:32:58 +0000 (04:32 -0400)
Filter out all invalid xattrs in listxattr.
This includes trusted. xattrs that can cause
unnecessary "EPERM" in subsequent getxattr operations.

Signed-off-by: Fan Yong <yong.fan@whamcloud.com>
Signed-off-by: Bob Glossman <bogl@whamcloud.com>
Change-Id: I9613444adcdb14067a775f68f951af7a9b941e9a
Reviewed-on: http://review.whamcloud.com/3892
Tested-by: Hudson
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/llite/xattr.c
lustre/tests/sanity.sh

index c2e1c5f..8ff6b61 100644 (file)
@@ -413,6 +413,30 @@ ssize_t ll_listxattr(struct dentry *dentry, char *buffer, size_t size)
         if (rc < 0)
                 GOTO(out, rc);
 
+       if (buffer != NULL) {
+               struct ll_sb_info *sbi = ll_i2sbi(inode);
+               char *xattr_name = buffer;
+               int xlen, rem = rc;
+
+               while (rem > 0) {
+                       xlen = strnlen(xattr_name, rem - 1) + 1;
+                       rem -= xlen;
+                       if (xattr_type_filter(sbi,
+                                       get_xattr_type(xattr_name)) == 0) {
+                               /* skip OK xattr type
+                                * leave it in buffer
+                                */
+                               xattr_name += xlen;
+                               continue;
+                       }
+                       /* move up remaining xattrs in buffer
+                        * removing the xattr that is not OK
+                        */
+                       memmove(xattr_name, xattr_name + xlen, rem);
+                       rc -= xlen;
+               }
+       }
+
         if (S_ISREG(inode->i_mode)) {
                 struct ll_inode_info *lli = ll_i2info(inode);
                 struct lov_stripe_md *lsm = NULL;
index 3260794..3229b22 100644 (file)
@@ -4558,6 +4558,22 @@ test_102k() {
 }
 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
 
+test_102l() {
+       # LU-1838 trusted. xattr is invisible to non-root
+       local testfile=$DIR/$tfile
+
+       touch $testfile
+
+       echo "listxattr as user..."
+       chown $RUNAS_ID $testfile
+       $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
+           grep -q "trusted" &&
+               error "$testfile trusted xattrs are user visible"
+
+       return 0;
+}
+run_test 102l "listxattr filter test =================================="
+
 cleanup_test102
 
 run_acl_subtest()