From 215e3df27dbcb56ee014aba9c4f53b539fee4ba0 Mon Sep 17 00:00:00 2001 From: Fan Yong Date: Fri, 7 Sep 2012 00:18:05 +0800 Subject: [PATCH] LU-1838 llite: trusted. xattr is invisible to non-root 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 Signed-off-by: Bob Glossman Change-Id: I9613444adcdb14067a775f68f951af7a9b941e9a Reviewed-on: http://review.whamcloud.com/3892 Tested-by: Hudson Reviewed-by: Bob Glossman Reviewed-by: Andreas Dilger Tested-by: Maloo --- lustre/llite/xattr.c | 24 ++++++++++++++++++++++++ lustre/tests/sanity.sh | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index c2e1c5f..8ff6b61 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -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; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 3260794..3229b22 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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() -- 1.8.3.1