ceph: fix xattr search while getxattr
PATCH 1/1 ceph: fix xattr search while getxattr
Reproducible: always
How to reproduce:
$ touch file $ setfattr -n user.bare -v bare file $ setfattr -n user.bar -v bar $ getfattr -d file
user.bar="bar"
user.bare="bar"
This is because one xattr name is a sub-string of another, so search picks up first matching name -- a shorter one. Patch fixes search routine to do full-length string comparison.
Signed-off-by Sergiy Kibrik <[email protected]>
--- fs/ceph/xattr.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
fs/ceph/xattr.c +4 -2
@@ -219,13 +219,15 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,struct rb_node **p;struct rb_node *parent =NULL ;struct ceph_inode_xattr *xattr =NULL ; -int c; +int c, name_len =strlen (name); p = &ci->i_xattrs.index.rb_node;while (*p) { parent = *p; xattr = rb_entry(parent, struct ceph_inode_xattr, node); - c =strncmp (name, xattr->name, xattr->name_len); + c = name_len - xattr->name_len; +if (!c) + c =strncmp (name, xattr->name, xattr->name_len);if (c <0 ) p = &(*p)->rb_left;else if (c >0 )
Signature · 1 line
1.7.1
Hey,
Thanks for the bug report! I applied a slightly different fix (need to keep the sort lexicographic). Pushed to master branch of ceph-client.git.
sage
fs/ceph/xattr.c +3 -0
@@ -219,6 +219,7 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,struct rb_node **p;struct rb_node *parent =NULL ;struct ceph_inode_xattr *xattr =NULL ; +int name_len =strlen (name);int c; p = &ci->i_xattrs.index.rb_node;
@@ -226,6 +227,8 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci, parent = *p; xattr = rb_entry(parent, struct ceph_inode_xattr, node); c =strncmp (name, xattr->name, xattr->name_len); +if (c ==0 && name_len > xattr->name_len) + c =1 ;if (c <0 ) p = &(*p)->rb_left;else if (c >0 )
Quoted 50 lines · Sergiy Kibrik
Reproducible: always
How to reproduce:$ touch file $ setfattr -n user.bare -v bare file $ setfattr -n user.bar -v bar $ getfattr -d fileuser.bar="bar"
user.bare="bar"This is because one xattr name is a sub-string of another, so search picks up first matching name -- a shorter one. Patch fixes search routine to do full-length string comparison.
Signed-off-by Sergiy Kibrik <[email protected]>--- fs/ceph/xattr.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)fs/ceph/xattr.c +4
-2@@ -219,13 +219,15 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,struct rb_node **p;struct rb_node *parent =NULL ;struct ceph_inode_xattr *xattr =NULL ; -int c; +int c, name_len =strlen (name); p = &ci->i_xattrs.index.rb_node;while (*p) { parent = *p; xattr = rb_entry(parent, struct ceph_inode_xattr, node); - c =strncmp (name, xattr->name, xattr->name_len); + c = name_len - xattr->name_len; +if (!c) + c =strncmp (name, xattr->name, xattr->name_len);if (c <0 ) p = &(*p)->rb_left;else if (c >0 )Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html