mvadkert / rpms / qemu

Forked from rpms/qemu 6 years ago
Clone
59eb7ad
From: Prasad J Pandit <pjp@fedoraproject.org>
59eb7ad
Date: Mon, 16 Oct 2017 14:21:59 +0200
59eb7ad
Subject: [PATCH] 9pfs: use g_malloc0 to allocate space for xattr
59eb7ad
59eb7ad
9p back-end first queries the size of an extended attribute,
59eb7ad
allocates space for it via g_malloc() and then retrieves its
59eb7ad
value into allocated buffer. Race between querying attribute
59eb7ad
size and retrieving its could lead to memory bytes disclosure.
59eb7ad
Use g_malloc0() to avoid it.
59eb7ad
59eb7ad
Reported-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
59eb7ad
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
59eb7ad
Signed-off-by: Greg Kurz <groug@kaod.org>
59eb7ad
(cherry picked from commit 7bd92756303f2158a68d5166264dc30139b813b6)
59eb7ad
---
59eb7ad
 hw/9pfs/9p.c | 4 ++--
59eb7ad
 1 file changed, 2 insertions(+), 2 deletions(-)
59eb7ad
59eb7ad
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
59eb7ad
index 8e9490c5f5..c41c0eb106 100644
59eb7ad
--- a/hw/9pfs/9p.c
59eb7ad
+++ b/hw/9pfs/9p.c
59eb7ad
@@ -3236,7 +3236,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
59eb7ad
         xattr_fidp->fid_type = P9_FID_XATTR;
59eb7ad
         xattr_fidp->fs.xattr.xattrwalk_fid = true;
59eb7ad
         if (size) {
59eb7ad
-            xattr_fidp->fs.xattr.value = g_malloc(size);
59eb7ad
+            xattr_fidp->fs.xattr.value = g_malloc0(size);
59eb7ad
             err = v9fs_co_llistxattr(pdu, &xattr_fidp->path,
59eb7ad
                                      xattr_fidp->fs.xattr.value,
59eb7ad
                                      xattr_fidp->fs.xattr.len);
59eb7ad
@@ -3269,7 +3269,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
59eb7ad
         xattr_fidp->fid_type = P9_FID_XATTR;
59eb7ad
         xattr_fidp->fs.xattr.xattrwalk_fid = true;
59eb7ad
         if (size) {
59eb7ad
-            xattr_fidp->fs.xattr.value = g_malloc(size);
59eb7ad
+            xattr_fidp->fs.xattr.value = g_malloc0(size);
59eb7ad
             err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path,
59eb7ad
                                     &name, xattr_fidp->fs.xattr.value,
59eb7ad
                                     xattr_fidp->fs.xattr.len);