Re: [PATCH] blk-throttle: verify format of bandwidth limit and detect overflows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05.03.2019 18:56, Tejun Heo wrote:
Hello, Konstantin.

On Wed, Feb 27, 2019 at 11:05:44AM +0300, Konstantin Khlebnikov wrote:
Unlike to memory cgroup blkio throttler does not support value suffixes.

It silently ignores everything after last digit. For example this command
will set rate limit 1 byte per second rather than 1 megabyte per second:

# echo "7:0 1M" > blkio.throttle.read_bps_device
# cat blkio.throttle.read_bps_device
7:0 1

Cgroup2 interface has the same flaw:

# echo "7:0 rbps=1M" > io.max
# cat io.max
7:0 rbps=1 wbps=max riops=max wiops=max

Also sscanf does not care much about overflows.

This patch uses modern function kstrtou64 for parsing.
It rejects trailing garbage and detects integer overflows.

Also this patch handles iops limit overflows for cgroup-v1 in the same as
cgroup-v2: limits >= UINT_MAX becomes unlimited.

Fixes: 2ee867dcfa2e ("blkcg: implement interface for the unified hierarchy")
Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>

So, I'd much rather keep the parsing implementations simple.  Unless
there's a correctness problem (you mentioned overflowing, how would
that happen?), the simpler the better.  I don't think the kernel needs
to be in the business of strict input verification here.

This is inconsistency between controllers. IO controller should either
accept size suffixes or reject them. Ignoring garbage is not an option.
To be honest, I've successfully shot in the foot by bps limit "1M".

Integer overflows are happens when userspace software uses floats for data
representation and calculations. This way values bigger than 2^32-1 or
2^64-1 could appear easily in text representation.

Almost all integer knobs in sysctl and sysfs use modern kstrtoXX functions
with strict validation of format and overflows.


Thanks.




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux