xfs: Fix integer overflow in fs/xfs/linux-2.6/xfs_ioctl*.c
authorZhitong Wang <zhitong.wangzt@alibaba-inc.com>
Mon, 22 Mar 2010 22:51:22 +0000 (09:51 +1100)
committerAlex Elder <aelder@sgi.com>
Wed, 19 May 2010 14:58:07 +0000 (09:58 -0500)
The am_hreq.opcount field in the xfs_attrmulti_by_handle() interface
is not bounded correctly. The opcount is used to determine the size
of the buffer required. The size is bounded, but can overflow and so
the size checks may not be sufficient to catch invalid opcounts.
Fix it by catching opcount values that would cause overflows before
calculating the size.

Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>
Reviewed-by: Dave Chinner <david@fromorbit.com>
fs/xfs/linux-2.6/xfs_ioctl.c
fs/xfs/linux-2.6/xfs_ioctl32.c

index 7b26cc2fd2844bf1d768e65be90ceeca9eb85e72..699b60cbab9c0da98deb5ca1f1b5839ee726d4b2 100644 (file)
@@ -527,6 +527,10 @@ xfs_attrmulti_by_handle(
        if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
+       /* overflow check */
+       if (am_hreq.opcount >= INT_MAX / sizeof(xfs_attr_multiop_t))
+               return -E2BIG;
+
        dentry = xfs_handlereq_to_dentry(parfilp, &am_hreq.hreq);
        if (IS_ERR(dentry))
                return PTR_ERR(dentry);
index 593c05b4df8dea614b13c0ee0f13613a9dcbc1e1..9287135e9bfcedf7ab0f563d5c14bfe9d309e8e5 100644 (file)
@@ -420,6 +420,10 @@ xfs_compat_attrmulti_by_handle(
                           sizeof(compat_xfs_fsop_attrmulti_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
+       /* overflow check */
+       if (am_hreq.opcount >= INT_MAX / sizeof(compat_xfs_attr_multiop_t))
+               return -E2BIG;
+
        dentry = xfs_compat_handlereq_to_dentry(parfilp, &am_hreq.hreq);
        if (IS_ERR(dentry))
                return PTR_ERR(dentry);