First, algorithm_params_store(), like any sysfs handler, should grab device init lock. Second, like any write() sysfs handler, it should grab device init lock in exclusive mode. Third, it should not permit change of algos' parameters after device init, as this doesn't make sense - we cannot compress with one C/D dict and then just change C/D dict to a different one, for example. Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute") Cc: gao xu Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index c41e1257243f..7551c5e664a9 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1769,6 +1769,10 @@ static ssize_t algorithm_params_store(struct device *dev, if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS) return -EINVAL; + guard(rwsem_write)(&zram->dev_lock); + if (init_done(zram)) + return -EBUSY; + ret = comp_params_store(zram, prio, level, dict_path, &deflate_params); return ret ? ret : len; } -- 2.53.0.473.g4a7958ca14-goog