All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/1] xfs: tighten GETBMAP input validation
@ 2022-01-26  2:18 Darrick J. Wong
  2022-01-26  2:18 ` [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2022-01-26  2:18 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

Hi all,

syzbot complained that the input validation for XFS_IOC_GETBMAP isn't as
strict as the one in the kvmalloc calls that it uses to stage the bmap
reporting.  This is an annoying use of maintainer time, but fix it anyway.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=getbmap-validation-5.17
---
 fs/xfs/xfs_ioctl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


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

* [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP*
  2022-01-26  2:18 [PATCHSET 0/1] xfs: tighten GETBMAP input validation Darrick J. Wong
@ 2022-01-26  2:18 ` Darrick J. Wong
  2022-01-31 22:04   ` Alli
  2022-02-01 21:58   ` Catherine Hoang
  0 siblings, 2 replies; 4+ messages in thread
From: Darrick J. Wong @ 2022-01-26  2:18 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

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>
---
 fs/xfs/xfs_ioctl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 03a6198c97f6..2515fe8299e1 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1464,7 +1464,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 = kvcalloc(bmx.bmv_count, sizeof(*buf), GFP_KERNEL);


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

* Re: [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP*
  2022-01-26  2:18 ` [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Darrick J. Wong
@ 2022-01-31 22:04   ` Alli
  2022-02-01 21:58   ` Catherine Hoang
  1 sibling, 0 replies; 4+ messages in thread
From: Alli @ 2022-01-31 22:04 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, 2022-01-25 at 18:18 -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> 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>
This fix looks fine to me.  Lets get it through.  Thanks!
Reviewed-By: Allison Henderson <allison.henderson@oracle.com>
> ---
>  fs/xfs/xfs_ioctl.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 03a6198c97f6..2515fe8299e1 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1464,7 +1464,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 = kvcalloc(bmx.bmv_count, sizeof(*buf), GFP_KERNEL);
> 


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

* Re: [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP*
  2022-01-26  2:18 ` [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Darrick J. Wong
  2022-01-31 22:04   ` Alli
@ 2022-02-01 21:58   ` Catherine Hoang
  1 sibling, 0 replies; 4+ messages in thread
From: Catherine Hoang @ 2022-02-01 21:58 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

> On Jan 25, 2022, at 6:18 PM, Darrick J. Wong <djwong@kernel.org> wrote:
> 
> From: Darrick J. Wong <djwong@kernel.org>
> 
> 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>
> ---
> fs/xfs/xfs_ioctl.c |    2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 

Looks good,
Reviewed-by: Catherine Hoang <catherine.hoang@oracle.com>
> 
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 03a6198c97f6..2515fe8299e1 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1464,7 +1464,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 = kvcalloc(bmx.bmv_count, sizeof(*buf), GFP_KERNEL);
> 


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

end of thread, other threads:[~2022-02-01 21:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26  2:18 [PATCHSET 0/1] xfs: tighten GETBMAP input validation Darrick J. Wong
2022-01-26  2:18 ` [PATCH 1/1] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Darrick J. Wong
2022-01-31 22:04   ` Alli
2022-02-01 21:58   ` Catherine Hoang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.