]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
zram: reject unrecognized type= values in recompress_store()
authorAndrew Stellman <astellman@stellman-greene.com>
Tue, 7 Apr 2026 15:30:27 +0000 (11:30 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 18 Apr 2026 07:10:55 +0000 (00:10 -0700)
recompress_store() parses the type= parameter with three if statements
checking for "idle", "huge", and "huge_idle".  An unrecognized value
silently falls through with mode left at 0, causing the recompression pass
to run with no slot filter — processing all slots instead of the
intended subset.

Add a !mode check after the type parsing block to return -EINVAL for
unrecognized values, consistent with the function's other parameter
validation.

Link: https://lore.kernel.org/20260407153027.42425-1-astellman@stellman-greene.com
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/zram/zram_drv.c

index 43b68fdd95d6df79f39fd95646119b22e52869ba..aebc710f0d6ae08adb0ab9b70146313800263ff2 100644 (file)
@@ -2546,6 +2546,8 @@ static ssize_t recompress_store(struct device *dev,
                                mode = RECOMPRESS_HUGE;
                        if (!strcmp(val, "huge_idle"))
                                mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE;
+                       if (!mode)
+                               return -EINVAL;
                        continue;
                }