drivers/block/zram/zram_drv.c | 3 +++ 1 file changed, 3 insertions(+)
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.
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Changes in v2:
- Use !mode check after the strcmp chain instead of restructuring
into if/else if/else, as suggested by Sergey Senozhatsky.
drivers/block/zram/zram_drv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8ea2a12..67dea80 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2552,6 +2552,9 @@ static ssize_t recompress_store(struct device *dev,
if (!strcmp(val, "huge_idle"))
mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE;
+ if (!mode)
+ return -EINVAL;
+
continue;
}
--
2.34.1
Adding Andrew on this: Message-ID: <20260407153027.42425-1-astellman@stellman-greene.com> On (26/04/07 11:30), Andrew Stellman wrote: [..] > 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. > > Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org> > Signed-off-by: Andrew Stellman <astellman@stellman-greene.com> > --- Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> Thank you.
© 2016 - 2026 Red Hat, Inc.