Skip to content

Commit 9355aed

Browse files
rhvgoyalJens Axboe
authored andcommitted
blkio-throttle: limit max iops value to UINT_MAX
- Limit max iops value to UINT_MAX and return error to user if value is more than that instead of accepting bigger values and truncating implicitly. Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 5e901a2 commit 9355aed

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,10 @@ static int blkio_policy_parse_and_set(char *buf,
656656
{
657657
char *s[4], *p, *major_s = NULL, *minor_s = NULL;
658658
int ret;
659-
unsigned long major, minor, temp, iops;
659+
unsigned long major, minor, temp;
660660
int i = 0;
661661
dev_t dev;
662-
u64 bps;
662+
u64 bps, iops;
663663

664664
memset(s, 0, sizeof(s));
665665

@@ -731,13 +731,16 @@ static int blkio_policy_parse_and_set(char *buf,
731731
break;
732732
case BLKIO_THROTL_read_iops_device:
733733
case BLKIO_THROTL_write_iops_device:
734-
ret = strict_strtoul(s[1], 10, &iops);
734+
ret = strict_strtoull(s[1], 10, &iops);
735735
if (ret)
736736
return -EINVAL;
737737

738+
if (iops > THROTL_IOPS_MAX)
739+
return -EINVAL;
740+
738741
newpn->plid = plid;
739742
newpn->fileid = fileid;
740-
newpn->val.iops = iops;
743+
newpn->val.iops = (unsigned int)iops;
741744
break;
742745
}
743746
break;

‎block/blk-cgroup.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ enum blkio_policy_id {
2020
BLKIO_POLICY_THROTL, /* Throttling */
2121
};
2222

23+
/* Max limits for throttle policy */
24+
#define THROTL_IOPS_MAX UINT_MAX
25+
2326
#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
2427

2528
#ifndef CONFIG_BLK_CGROUP

0 commit comments

Comments
 (0)