linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] overlayfs: initialize error in ovl_copy_xattr
@ 2020-05-27  3:08 Yuxuan Shui
  2020-06-04  8:55 ` Miklos Szeredi
  0 siblings, 1 reply; 2+ messages in thread
From: Yuxuan Shui @ 2020-05-27  3:08 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-unionfs, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]


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.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
---
 fs/overlayfs/copy_up.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 9709cf22cab3..07e0d1961e96 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -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) ||
-- 
2.26.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] overlayfs: initialize error in ovl_copy_xattr
  2020-05-27  3:08 [PATCH] overlayfs: initialize error in ovl_copy_xattr Yuxuan Shui
@ 2020-06-04  8:55 ` Miklos Szeredi
  0 siblings, 0 replies; 2+ messages in thread
From: Miklos Szeredi @ 2020-06-04  8:55 UTC (permalink / raw)
  To: Yuxuan Shui; +Cc: overlayfs, linux-kernel

On Wed, May 27, 2020 at 5:20 AM Yuxuan Shui <yshuiv7@gmail.com> wrote:
>
>
> 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.
>
> Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>

Thanks, applied.

Miklos

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-04  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27  3:08 [PATCH] overlayfs: initialize error in ovl_copy_xattr Yuxuan Shui
2020-06-04  8:55 ` Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).