Commit 7cb35119 authored by Miklos Szeredi's avatar Miklos Szeredi

ovl: listxattr: use strnlen()

Be defensive about what underlying fs provides us in the returned xattr
list buffer.  If it's not properly null terminated, bail out with a warning
insead of BUG.
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Cc: <stable@vger.kernel.org>
parent 0eb45fc3
...@@ -255,7 +255,8 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size) ...@@ -255,7 +255,8 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
{ {
struct dentry *realdentry = ovl_dentry_real(dentry); struct dentry *realdentry = ovl_dentry_real(dentry);
ssize_t res; ssize_t res;
int off; size_t len;
char *s;
const struct cred *old_cred; const struct cred *old_cred;
old_cred = ovl_override_creds(dentry->d_sb); old_cred = ovl_override_creds(dentry->d_sb);
...@@ -265,17 +266,19 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size) ...@@ -265,17 +266,19 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
return res; return res;
/* filter out private xattrs */ /* filter out private xattrs */
for (off = 0; off < res;) { for (s = list, len = res; len;) {
char *s = list + off; size_t slen = strnlen(s, len) + 1;
size_t slen = strlen(s) + 1;
BUG_ON(off + slen > res); /* underlying fs providing us with an broken xattr list? */
if (WARN_ON(slen > len))
return -EIO;
len -= slen;
if (ovl_is_private_xattr(s)) { if (ovl_is_private_xattr(s)) {
res -= slen; res -= slen;
memmove(s, s + slen, res - off); memmove(s, s + slen, len);
} else { } else {
off += slen; s += slen;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment