summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2016-09-16 14:12:11 +0200
committerMiklos Szeredi <mszeredi@redhat.com>2016-09-16 14:12:11 +0200
commit8b326c61de08f5ca4bc454a168f19e7e43c4cc2a (patch)
treeeb3d11705f81fa3627796dca0fdee18296790704 /fs/overlayfs
parent9395452b4aab7bc2475ef8935b4a4fb99d778d70 (diff)
downloadlinux-8b326c61de08f5ca4bc454a168f19e7e43c4cc2a.tar.gz
linux-8b326c61de08f5ca4bc454a168f19e7e43c4cc2a.tar.bz2
linux-8b326c61de08f5ca4bc454a168f19e7e43c4cc2a.zip
ovl: copy_up_xattr(): use strnlen
Be defensive about what underlying fs provides us in the returned xattr list buffer. strlen() may overrun the buffer, so use strnlen() and WARN if the contents are not properly null terminated. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Cc: <stable@vger.kernel.org>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r--fs/overlayfs/copy_up.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 43fdc2765aea..abadbc30e013 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -57,6 +57,7 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new)
ssize_t list_size, size, value_size = 0;
char *buf, *name, *value = NULL;
int uninitialized_var(error);
+ size_t slen;
if (!old->d_inode->i_op->getxattr ||
!new->d_inode->i_op->getxattr)
@@ -79,7 +80,16 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new)
goto out;
}
- for (name = buf; name < (buf + list_size); name += strlen(name) + 1) {
+ for (name = buf; list_size; name += slen) {
+ slen = strnlen(name, list_size) + 1;
+
+ /* underlying fs providing us with an broken xattr list? */
+ if (WARN_ON(slen > list_size)) {
+ error = -EIO;
+ break;
+ }
+ list_size -= slen;
+
if (ovl_is_private_xattr(name))
continue;
retry: