xfs: fix memory exposure problems
PATCH 1/1 xfs: fix memory exposure problems
Fix a couple of memory exposure problems in the getbmap implementation where we copy too much header data from userspace, and a second problem in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents into userspace.
--- fs/xfs/xfs_ioctl.c | 4 ++-- fs/xfs/xfs_itable.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_ioctl.c +2 -2
@@ -1547,10 +1547,10 @@ xfs_ioc_getbmap(unsigned int cmd, void __user *arg) { - struct getbmapx bmx; + struct getbmapx bmx = {0};int error; -if (copy_from_user (&bmx, arg,sizeof (struct getbmapx ))) +if (copy_from_user (&bmx, arg,sizeof (struct getbmap )))return -EFAULT ;if (bmx.bmv_count <2 )
fs/xfs/xfs_itable.c +1 -1
@@ -584,7 +584,7 @@ xfs_inumbers(return error; bcount =MIN (left, (int )(PAGE_SIZE /sizeof (*buffer))); - buffer =kmem_alloc (bcount *sizeof (*buffer),KM_SLEEP ); + buffer =kmem_zalloc (bcount *sizeof (*buffer),KM_SLEEP ); do { struct xfs_inobt_rec_incore r; int stat;
Quoted 5 lines · Darrick J. Wong
Fix a couple of memory exposure problems in the getbmap implementation where we copy too much header data from userspace, and a second problem in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents into userspace.
This should be two different patches.
fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1550
Quoted 8 lines
fs/xfs/xfs_ioctl.c +1
-1@@ -1547,10 +1547,10 @@ xfs_ioc_getbmap(unsigned int cmd, void __user *arg) { - struct getbmapx bmx; + struct getbmapx bmx = {0};
missing spaces around the zero.
fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1554
Quoted 5 lines
fs/xfs/xfs_ioctl.c +1
-1int error; -if (copy_from_user (&bmx, arg,sizeof (struct getbmapx ))) +if (copy_from_user (&bmx, arg,sizeof (struct getbmap )))return -EFAULT ;
This really needs a comment on how struct getbmap is a strict subset of struct getbmapx. Or even better don't use getbmap at all and use offsetoff on struct getbmapx.
fs/xfs/xfs_itable.c xfs_inumbers( · line 587
Quoted 10 lines
fs/xfs/xfs_itable.c +1
-1@@ -584,7 +584,7 @@ xfs_inumbers(return error; bcount =MIN (left, (int )(PAGE_SIZE /sizeof (*buffer))); - buffer =kmem_alloc (bcount *sizeof (*buffer),KM_SLEEP ); + buffer =kmem_zalloc (bcount *sizeof (*buffer),KM_SLEEP );
This looks fine:
Quoted 22 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong
Fix a couple of memory exposure problems in the getbmap implementation where we copy too much header data from userspace, and a second problem in inumbers where we allocate an array of structures with holes, fail to zero the holes, then blindly copy the kernel memory contents into userspace.
This should be two different patches.
fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1550
Quoted 8 lines
fs/xfs/xfs_ioctl.c +1
-1@@ -1547,10 +1547,10 @@ xfs_ioc_getbmap(unsigned int cmd, void __user *arg) { - struct getbmapx bmx; + struct getbmapx bmx = {0};missing spaces around the zero.
Quoted 2 lines
fs/xfs/xfs_ioctl.c +0
-0int error;
Quoted 7 lines
fs/xfs/xfs_ioctl.c xfs_ioc_getbmap( · line 1554
Quoted 3 lines
fs/xfs/xfs_ioctl.c +1
-1-if (copy_from_user (&bmx, arg,sizeof (struct getbmapx ))) +if (copy_from_user (&bmx, arg,sizeof (struct getbmap )))return -EFAULT ;This really needs a comment on how struct getbmap is a strict subset of struct getbmapx. Or even better don't use getbmap at all and use offsetoff on struct getbmapx.
Agreed, was going to make the same observation.
-Eric
Quoted 19 lines
fs/xfs/xfs_itable.c xfs_inumbers( · line 587
Quoted 10 lines
fs/xfs/xfs_itable.c +1
-1@@ -584,7 +584,7 @@ xfs_inumbers(return error; bcount =MIN (left, (int )(PAGE_SIZE /sizeof (*buffer))); - buffer =kmem_alloc (bcount *sizeof (*buffer),KM_SLEEP ); + buffer =kmem_zalloc (bcount *sizeof (*buffer),KM_SLEEP );This looks fine:
Reviewed-by Christoph Hellwig <[email protected]>--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html