ceph: avoid divide by zero in __validate_layout()
authorSage Weil <sage@inktank.com>
Tue, 21 Aug 2012 19:11:51 +0000 (12:11 -0700)
committerSage Weil <sage@inktank.com>
Tue, 21 Aug 2012 22:55:28 +0000 (15:55 -0700)
If "l->stripe_unit" is zero the the mod on the next line will cause a
divide by zero bug.  This comes from the copy_from_user() in
ceph_ioctl_set_layout_policy().  Passing 0 is valid, though (it means
"do not change") so avoid the % check in that case.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Alex Elder <elder@inktank.com>
fs/ceph/ioctl.c

index 8e3fb69fbe62e60cd3698c07d9fa8e53d6d2b184..1396ceb46797400c124ac80880f31a90583d0e4b 100644 (file)
@@ -42,7 +42,8 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
        /* validate striping parameters */
        if ((l->object_size & ~PAGE_MASK) ||
            (l->stripe_unit & ~PAGE_MASK) ||
-           ((unsigned)l->object_size % (unsigned)l->stripe_unit))
+           (l->stripe_unit != 0 &&
+            ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
                return -EINVAL;
 
        /* make sure it's a valid data pool */