Skip to content

Commit

Permalink
xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP*
Browse files Browse the repository at this point in the history
[ Upstream commit 29d650f ]

Syzbot tripped over the following complaint from the kernel:

WARNING: CPU: 2 PID: 15402 at mm/util.c:597 kvmalloc_node+0x11e/0x125 mm/util.c:597

While trying to run XFS_IOC_GETBMAP against the following structure:

struct getbmap fubar = {
	.bmv_count	= 0x22dae649,
};

Obviously, this is a crazy huge value since the next thing that the
ioctl would do is allocate 37GB of memory.  This is enough to make
kvmalloc mad, but isn't large enough to trip the validation functions.
In other words, I'm fussing with checks that were **already sufficient**
because that's easier than dealing with 644 internal bug reports.  Yes,
that's right, six hundred and forty-four.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Catherine Hoang <catherine.hoang@oracle.com>
Signed-off-by: Leah Rumancik <leah.rumancik@gmail.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Darrick J. Wong authored and Greg Kroah-Hartman committed Aug 25, 2022
1 parent 1350a4c commit b92be74
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/xfs/xfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ xfs_ioc_getbmap(

if (bmx.bmv_count < 2)
return -EINVAL;
if (bmx.bmv_count > ULONG_MAX / recsize)
if (bmx.bmv_count >= INT_MAX / recsize)
return -ENOMEM;

buf = kvzalloc(bmx.bmv_count * sizeof(*buf), GFP_KERNEL);
Expand Down

0 comments on commit b92be74

Please sign in to comment.