linux-stable/block
Li Nan 9e8bf9f95f blk-iocost: fix divide by 0 error in calc_lcoefs()
[ Upstream commit 984af1e66b ]

echo max of u64 to cost.model can cause divide by 0 error.

  # echo 8:0 rbps=18446744073709551615 > /sys/fs/cgroup/io.cost.model

  divide error: 0000 [#1] PREEMPT SMP
  RIP: 0010:calc_lcoefs+0x4c/0xc0
  Call Trace:
   <TASK>
   ioc_refresh_params+0x2b3/0x4f0
   ioc_cost_model_write+0x3cb/0x4c0
   ? _copy_from_iter+0x6d/0x6c0
   ? kernfs_fop_write_iter+0xfc/0x270
   cgroup_file_write+0xa0/0x200
   kernfs_fop_write_iter+0x17d/0x270
   vfs_write+0x414/0x620
   ksys_write+0x73/0x160
   __x64_sys_write+0x1e/0x30
   do_syscall_64+0x35/0x80
   entry_SYSCALL_64_after_hwframe+0x63/0xcd

calc_lcoefs() uses the input value of cost.model in DIV_ROUND_UP_ULL,
overflow would happen if bps plus IOC_PAGE_SIZE is greater than
ULLONG_MAX, it can cause divide by 0 error.

Fix the problem by setting basecost

Signed-off-by: Li Nan <linan122@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20230117070806.3857142-5-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-11 16:43:54 +01:00
..
partitions docs: admin-guide: add a series of orphaned documents 2019-07-15 11:03:02 -03:00
Kconfig blkcg: implement blk-iocost 2019-08-28 21:17:12 -06:00
Kconfig.iosched docs: block: convert to ReST 2019-07-15 09:20:27 -03:00
Makefile blkcg: implement blk-iocost 2019-08-28 21:17:12 -06:00
badblocks.c block: switch all files cleared marked as GPLv2 to SPDX tags 2019-04-30 16:11:57 -06:00
bfq-cgroup.c block, bfq: fix null pointer dereference in bfq_bio_bfqg() 2022-12-08 11:22:57 +01:00
bfq-iosched.c block, bfq: protect 'bfqd->queued' by 'bfqd->lock' 2022-11-10 17:57:54 +01:00
bfq-iosched.h bfq: Get rid of __bio_blkcg() usage 2022-06-14 18:11:50 +02:00
bfq-wf2q.c bfq: fix blkio cgroup leakage v4 2020-09-03 11:26:54 +02:00
bio-integrity.c block: bio-integrity: Copy flags when bio_integrity_payload is cloned 2023-03-11 16:43:35 +01:00
bio.c block: fix bio_clone_blkg_association() to associate with proper blkcg_gq 2022-06-14 18:11:50 +02:00
blk-cgroup.c blk-cgroup: fix missing pd_online_fn() while activating policy 2023-02-06 07:52:48 +01:00
blk-core.c block: fix and cleanup bio_check_ro 2023-02-06 07:52:47 +01:00
blk-exec.c block: add SPDX tags to block layer files missing licensing information 2019-04-30 16:12:03 -06:00
blk-flush.c block: Fix fsync always failed if once failed 2022-03-08 19:07:47 +01:00
blk-integrity.c block: centralize PI remapping logic to the block layer 2019-09-17 20:03:49 -06:00
blk-ioc.c block: Fix use-after-free issue accessing struct io_cq 2020-04-17 10:50:04 +02:00
blk-iocost.c blk-iocost: fix divide by 0 error in calc_lcoefs() 2023-03-11 16:43:54 +01:00
blk-iolatency.c blk-iolatency: Fix inflight count imbalances and IO hangs on offline 2022-06-14 18:11:49 +02:00
blk-lib.c block: fix 32 bit overflow in __blkdev_issue_discard() 2018-11-14 08:17:18 -07:00
blk-map.c block: fix memleak when __blk_rq_map_user_iov() is failed 2020-01-12 12:21:43 +01:00
blk-merge.c block: return ELEVATOR_DISCARD_MERGE if possible 2022-05-25 09:14:38 +02:00
blk-mq-cpumap.c blk-mq: balance mapping between present CPUs and queues 2019-08-04 21:43:12 -06:00
blk-mq-debugfs-zoned.c block: Cleanup license notice 2019-01-17 21:21:40 -07:00
blk-mq-debugfs.c blk-mq: don't create hctx debugfs dir until q->debugfs_dir is created 2022-08-25 11:17:36 +02:00
blk-mq-debugfs.h blk-mq: no need to check return value of debugfs_create functions 2019-06-13 03:00:30 -06:00
blk-mq-pci.c block: Fix blk_mq_*_map_queues() kernel-doc headers 2019-05-31 15:12:34 -06:00
blk-mq-rdma.c block: Fix blk_mq_*_map_queues() kernel-doc headers 2019-05-31 15:12:34 -06:00
blk-mq-sched.c blk-mq: correct stale comment of .get_budget 2023-03-11 16:43:34 +01:00
blk-mq-sched.h block: only call sched requeue_request() for scheduled requests 2020-09-23 12:40:37 +02:00
blk-mq-sysfs.c blk-mq: fix possible memleak when register 'hctx' failed 2023-01-18 11:41:38 +01:00
blk-mq-tag.c blk-mq: introduce blk_mq_tagset_wait_completed_request() 2019-08-04 21:41:29 -06:00
blk-mq-tag.h
blk-mq-virtio.c block: Fix blk_mq_*_map_queues() kernel-doc headers 2019-05-31 15:12:34 -06:00
blk-mq.c blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait 2023-03-11 16:43:34 +01:00
blk-mq.h blk-mq: insert passthrough request into hctx->dispatch directly 2020-03-21 08:11:52 +01:00
blk-pm.c scsi: block: Fix a race in the runtime power management code 2021-01-06 14:48:37 +01:00
blk-pm.h block: remove the queue_lock indirection 2018-11-15 12:17:28 -07:00
blk-rq-qos.c rq-qos: fix missed wake-ups in rq_qos_throttle try two 2021-07-19 08:53:16 +02:00
blk-rq-qos.h block: fix race between adding/removing rq qos and normal IO 2021-07-14 16:53:18 +02:00
blk-settings.c blk-settings: align max_sectors on "logical_block_size" boundary 2021-03-04 10:26:40 +01:00
blk-softirq.c block: remove a few unused exports 2018-11-15 12:13:25 -07:00
blk-stat.c block: add SPDX tags to block layer files missing licensing information 2019-04-30 16:12:03 -06:00
blk-stat.h block: deactivate blk_stat timer in wbt_disable_default() 2018-12-12 06:47:51 -07:00
blk-sysfs.c block: don't delete queue kobject before its children 2022-04-15 14:18:05 +02:00
blk-throttle.c blk-throttle: fix UAF by deleteing timer in blk_throtl_exit() 2021-09-26 14:07:13 +02:00
blk-timeout.c block: add SPDX tags to block layer files missing licensing information 2019-04-30 16:12:03 -06:00
blk-wbt.c blk-wbt: make sure throttle is enabled properly 2021-07-14 16:53:25 +02:00
blk-wbt.h blk-wbt: introduce a new disable state to prevent false positive by rwb_enabled() 2021-07-14 16:53:25 +02:00
blk-zoned.c blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN 2021-09-22 12:26:19 +02:00
blk.h block: fix memleak of bio integrity data 2020-01-26 10:01:09 +01:00
bounce.c block: remove the i argument to bio_for_each_segment_all 2019-04-30 09:26:13 -06:00
bsg-lib.c block: Fix the type of 'sts' in bsg_queue_rq() 2020-01-23 08:22:44 +01:00
bsg.c scsi: bsg: Remove support for SCSI_IOCTL_SEND_COMMAND 2021-09-22 12:26:23 +02:00
cmdline-parser.c
compat_ioctl.c block/compat_ioctl: fix range check in BLKGETSIZE 2022-04-27 13:50:50 +02:00
elevator.c block: return ELEVATOR_DISCARD_MERGE if possible 2022-05-25 09:14:38 +02:00
genhd.c block: Suppress uevent for hidden device when removed 2021-03-30 14:35:23 +02:00
ioctl.c block: add SPDX tags to block layer files missing licensing information 2019-04-30 16:12:03 -06:00
ioprio.c block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2) 2021-12-14 14:49:02 +01:00
kyber-iosched.c kyber: fix out of bounds access when preempted 2021-05-19 10:08:30 +02:00
mq-deadline.c block: return ELEVATOR_DISCARD_MERGE if possible 2022-05-25 09:14:38 +02:00
opal_proto.h block: sed-opal: Removed duplicate OPAL_METHOD_LENGTH definition 2019-08-20 09:34:49 -06:00
partition-generic.c block: unhash blkdev part inode when the part is deleted 2022-12-19 12:24:16 +01:00
scsi_ioctl.c block: switch all files cleared marked as GPLv2 to SPDX tags 2019-04-30 16:11:57 -06:00
sed-opal.c block: sed-opal: kmalloc the cmd/resp buffers 2022-11-25 17:42:14 +01:00
t10-pi.c block: t10-pi: fix -Wswitch warning 2019-09-23 08:05:19 -06:00