9pfs: use g_malloc0 to allocate space for xattr
PATCH 1/1 9pfs: use g_malloc0 to allocate space for xattr
From: Prasad J Pandit <[email protected]>
9p back-end first queries the size of an extended attribute, allocates space for it via g_malloc() and then retrieves its value into allocated buffer. Race between querying attribute size and retrieving its could lead to memory bytes disclosure. Use g_malloc0() to avoid it.
Reported-by Tuomas Tynkkynen <[email protected]>
Signed-off-by Prasad J Pandit <[email protected]>
--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p.c +2 -2
@@ -3234,7 +3234,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type =P9_FID_XATTR ; xattr_fidp->fs.xattr.xattrwalk_fid = true;if (size) { - xattr_fidp->fs.xattr.value =g_malloc (size); + xattr_fidp->fs.xattr.value =g_malloc0 (size); err =v9fs_co_llistxattr (pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len);
@@ -3267,7 +3267,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type =P9_FID_XATTR ; xattr_fidp->fs.xattr.xattrwalk_fid = true;if (size) { - xattr_fidp->fs.xattr.value =g_malloc (size); + xattr_fidp->fs.xattr.value =g_malloc0 (size); err =v9fs_co_lgetxattr (pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len);
Signature · 1 line
2.13.6
Greg Kurz
AppliedQuoted 8 lines · On Wed, 4 Oct 2017 17:06:52 +0530 P J P <[email protected]> wrote:
From: Prasad J Pandit <[email protected]>
9p back-end first queries the size of an extended attribute, allocates space for it via
g_malloc()and then retrieves its value into allocated buffer. Race between querying attribute size and retrieving its could lead to memory bytes disclosure. Useg_malloc0()to avoid it.
Applied to 9p-next.
Thanks.
Quoted 28 lines
Reported-by Tuomas Tynkkynen <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/9pfs/9p.c +2
-2@@ -3234,7 +3234,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type =P9_FID_XATTR ; xattr_fidp->fs.xattr.xattrwalk_fid = true;if (size) { - xattr_fidp->fs.xattr.value =g_malloc (size); + xattr_fidp->fs.xattr.value =g_malloc0 (size); err =v9fs_co_llistxattr (pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len);@@ -3267,7 +3267,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fid_type =P9_FID_XATTR ; xattr_fidp->fs.xattr.xattrwalk_fid = true;if (size) { - xattr_fidp->fs.xattr.value =g_malloc (size); + xattr_fidp->fs.xattr.value =g_malloc0 (size); err =v9fs_co_lgetxattr (pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len);