From: Rohinthan <rokinthanp03@gmail.com>
To: Minchan Kim <minchan@kernel.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Rohinthan <rokinthanp03@gmail.com>,
syzbot+fb23651a7efbea8868ed@syzkaller.appspotmail.com
Subject: [PATCH] zram: reject zero or overflowed disksize in disksize_store
Date: Tue, 22 Sep 2026 17:47:20 +0530 [thread overview]
Message-ID: <20260922121720.11241-1-rokinthanp03@gmail.com> (raw)
When userspace writes a value close to U64_MAX (such as (u64)-1) to the
sysfs attribute /sys/block/zram<id>/disksize, disksize_store() parses it
with memparse() and then calls:
disksize = PAGE_ALIGN(disksize);
Because adding PAGE_SIZE - 1 to values in the range
[U64_MAX - PAGE_SIZE + 2, U64_MAX] causes an integer overflow wrapping
to 0, disksize becomes 0. disksize_store() then passes 0 to
zram_meta_alloc(), which computes num_pages = 0 and calls vzalloc(0).
In mm/vmalloc.c, __vmalloc_node_range_noprof() checks
`if (WARN_ON_ONCE(!size))` and triggers a kernel warning:
WARNING: mm/vmalloc.c:4038 at __vmalloc_node_range_noprof
Call trace:
__vmalloc_node_range_noprof
vzalloc_noprof
disksize_store
dev_attr_store
sysfs_kf_write
Fix this by checking if disksize wrapped to 0 after PAGE_ALIGN(disksize)
and returning -EINVAL. Also add a defensive check in zram_meta_alloc()
to return false if disksize is 0, avoiding vzalloc(0) under any
circumstance.
Fixes: cd67e10ac699 ("zram: promote zram from staging")
Reported-by: syzbot+fb23651a7efbea8868ed@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fb23651a7efbea8868ed
Signed-off-by: Rohinthan <rokinthanp03@gmail.com>
---
drivers/block/zram/zram_drv.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 6cb44e2..fdd13df 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1989,6 +1989,9 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
{
size_t num_pages;
+ if (!disksize)
+ return false;
+
num_pages = disksize >> PAGE_SHIFT;
zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
if (!zram->table)
@@ -2878,6 +2881,9 @@ static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
}
disksize = PAGE_ALIGN(disksize);
+ if (!disksize)
+ return -EINVAL;
+
if (!zram_meta_alloc(zram, disksize))
return -ENOMEM;
--
2.53.0
next reply other threads:[~2026-09-22 12:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 12:17 Rohinthan [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-09-22 12:10 Rokinthan p
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260922121720.11241-1-rokinthanp03@gmail.com \
--to=rokinthanp03@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=syzbot+fb23651a7efbea8868ed@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®