overlayfs: initialize error in ovl_copy_xattr
PATCH 1/1 overlayfs: initialize error in ovl_copy_xattr
In ovl_copy_xattr, if all the xattrs to be copied are overlayfs private xattrs, the copy loop will terminate without assigning anything to the error variable, thus returning an uninitialized value.
If ovl_copy_xattr is called from ovl_clear_empty, this uninitialized error value is put into a pointer by ERR_PTR(), causing potential invalid memory accesses down the line.
This commit initialize error with 0. This is the correct value because when there's no xattr to copy, because all xattrs are private, ovl_copy_xattr should succeed.
This bug is discovered with the help of INIT_STACK_ALL and clang.
--- fs/overlayfs/copy_up.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/copy_up.c +1 -1
@@ -47,7 +47,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 ); +int error =0 ;size_t slen; if (!(old->d_inode->i_opflags & IOP_XATTR) ||
Signature · 1 line
2.26.2
Quoted 10 lines · Yuxuan Shui
In
ovl_copy_xattr, if all the xattrs to be copied are overlayfs private xattrs, the copy loop will terminate without assigning anything to the error variable, thus returning an uninitialized value.If
ovl_copy_xattris called fromovl_clear_empty, this uninitialized error value is put into a pointer byERR_PTR(), causing potential invalid memory accesses down the line.
Quoted 7 lines
This commit initialize error with 0. This is the correct value because when there's no xattr to copy, because all xattrs are private,
ovl_copy_xattrshould succeed.This bug is discovered with the help of
INIT_STACK_ALLand clang.Signed-off-by Yuxuan Shui <[email protected]>
Thanks, applied.
Miklos