• Coly Li's avatar
    bcache: fix potential div-zero error of writeback_rate_p_term_inverse · 38d2286e
    Coly Li authored
    [ Upstream commit 5b5fd3c9 ]
    
    Current code already uses d_strtoul_nonzero() to convert input string
    to an unsigned integer, to make sure writeback_rate_p_term_inverse
    won't be zero value. But overflow may happen when converting input
    string to an unsigned integer value by d_strtoul_nonzero(), then
    dc->writeback_rate_p_term_inverse can still be set to 0 even if the
    sysfs file input value is not zero, e.g. 4294967296 (a.k.a UINT_MAX+1).
    
    If dc->writeback_rate_p_term_inverse is set to 0, it might cause a
    dev-zero error in following code from __update_writeback_rate(),
    	int64_t proportional_scaled =
    		div_s64(error, dc->writeback_rate_p_term_inverse);
    
    This patch replaces d_strtoul_nonzero() by sysfs_strtoul_clamp() and
    limit the value range in [1, UINT_MAX]. Then the unsigned integer
    overflow and dev-zero error can be avoided.
    Signed-off-by: 's avatarColy Li <colyli@suse.de>
    Signed-off-by: 's avatarJens Axboe <axboe@kernel.dk>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    38d2286e
Name
Last commit
Last update
Documentation Loading commit data...
LICENSES Loading commit data...
arch Loading commit data...
block Loading commit data...
certs Loading commit data...
crypto Loading commit data...
drivers Loading commit data...
firmware Loading commit data...
fs Loading commit data...
include Loading commit data...
init Loading commit data...
ipc Loading commit data...
kernel Loading commit data...
lib Loading commit data...
mm Loading commit data...
net Loading commit data...
samples Loading commit data...
scripts Loading commit data...
security Loading commit data...
sound Loading commit data...
tools Loading commit data...
usr Loading commit data...
virt Loading commit data...
.clang-format Loading commit data...
.cocciconfig Loading commit data...
.get_maintainer.ignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
Kbuild Loading commit data...
Kconfig Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README Loading commit data...