* [PATCH] zram: reject disksize values that overflow PAGE_ALIGN
@ 2026-08-20 3:13 Jiacheng Xu
2026-08-20 4:07 ` Sergey Senozhatsky
0 siblings, 1 reply; 3+ messages in thread
From: Jiacheng Xu @ 2026-08-20 3:13 UTC (permalink / raw)
To: Minchan Kim; +Cc: Sergey Senozhatsky, Jens Axboe, linux-kernel
disksize_store() parses the value written to the disksize sysfs
attribute with memparse() and then aligns it with PAGE_ALIGN().
For values in the last PAGE_SIZE - 1 bytes of the u64 range, the
addition performed by PAGE_ALIGN() wraps around. For example,
U64_MAX - 3 is aligned to zero. zram_meta_alloc() then calls
vzalloc(0), which triggers a warning in __vmalloc_node_range().
With panic_on_warn enabled, this can also result in a kernel panic.
Reject values that cannot be safely page-aligned before calling
PAGE_ALIGN().
Fixes: cd67e10ac699 ("zram: promote zram from staging")
Signed-off-by: Jiacheng Xu <stitch@zju.edu.cn>
---
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 ace65c586072..2696bd3b29f6 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2876,6 +2876,9 @@ static ssize_t disksize_store(struct device *dev, struct
device_attribute *attr,
return -EBUSY;
}
+ if (disksize > U64_MAX - (PAGE_SIZE - 1))
+ return -EINVAL;
+
disksize = PAGE_ALIGN(disksize);
if (!zram_meta_alloc(zram, disksize))
return -ENOMEM;
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] zram: reject disksize values that overflow PAGE_ALIGN
2026-08-20 3:13 [PATCH] zram: reject disksize values that overflow PAGE_ALIGN Jiacheng Xu
@ 2026-08-20 4:07 ` Sergey Senozhatsky
2026-08-20 9:05 ` Jiacheng Xu
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Senozhatsky @ 2026-08-20 4:07 UTC (permalink / raw)
To: Jiacheng Xu; +Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, linux-kernel
On (26/08/20 11:13), Jiacheng Xu wrote:
> disksize_store() parses the value written to the disksize sysfs
> attribute with memparse() and then aligns it with PAGE_ALIGN().
>
> For values in the last PAGE_SIZE - 1 bytes of the u64 range, the
> addition performed by PAGE_ALIGN() wraps around. For example,
> U64_MAX - 3 is aligned to zero. zram_meta_alloc() then calls
> vzalloc(0), which triggers a warning in __vmalloc_node_range().
>
> With panic_on_warn enabled, this can also result in a kernel panic.
>
> Reject values that cannot be safely page-aligned before calling
> PAGE_ALIGN().
>
> Fixes: cd67e10ac699 ("zram: promote zram from staging")
> Signed-off-by: Jiacheng Xu <stitch@zju.edu.cn>
> ---
> 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 ace65c586072..2696bd3b29f6 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -2876,6 +2876,9 @@ static ssize_t disksize_store(struct device *dev, struct
> device_attribute *attr,
> return -EBUSY;
> }
>
> + if (disksize > U64_MAX - (PAGE_SIZE - 1))
> + return -EINVAL;
> +
> disksize = PAGE_ALIGN(disksize);
> if (!zram_meta_alloc(zram, disksize))
> return -ENOMEM;
I think we already check disksize boundaries (you probably want to check
out linux-next):
if (!num_pages || ((u64)num_pages << PAGE_SHIFT) != disksize)
return -EINVAL;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Re: [PATCH] zram: reject disksize values that overflow PAGE_ALIGN
2026-08-20 4:07 ` Sergey Senozhatsky
@ 2026-08-20 9:05 ` Jiacheng Xu
0 siblings, 0 replies; 3+ messages in thread
From: Jiacheng Xu @ 2026-08-20 9:05 UTC (permalink / raw)
To: Sergey Senozhatsky; +Cc: Minchan Kim, Jens Axboe, linux-kernel
Thanks for pointing this out. I checked the latest linux-next code and
confirmed that the new page-count validation rejects the reproducer
before zram_meta_alloc() calls vzalloc(0).
Best regards,
Jiacheng
> -----原始邮件-----
> 发件人: "Sergey Senozhatsky" <senozhatsky@chromium.org>
> 发送时间:2026-08-20 12:07:38 (星期四)
> 收件人: "Jiacheng Xu" <stitch@zju.edu.cn>
> 抄送: "Minchan Kim" <minchan@kernel.org>, "Sergey Senozhatsky" <senozhatsky@chromium.org>, "Jens Axboe" <axboe@kernel.dk>, linux-kernel@vger.kernel.org
> 主题: Re: [PATCH] zram: reject disksize values that overflow PAGE_ALIGN
>
> On (26/08/20 11:13), Jiacheng Xu wrote:
> > disksize_store() parses the value written to the disksize sysfs
> > attribute with memparse() and then aligns it with PAGE_ALIGN().
> >
> > For values in the last PAGE_SIZE - 1 bytes of the u64 range, the
> > addition performed by PAGE_ALIGN() wraps around. For example,
> > U64_MAX - 3 is aligned to zero. zram_meta_alloc() then calls
> > vzalloc(0), which triggers a warning in __vmalloc_node_range().
> >
> > With panic_on_warn enabled, this can also result in a kernel panic.
> >
> > Reject values that cannot be safely page-aligned before calling
> > PAGE_ALIGN().
> >
> > Fixes: cd67e10ac699 ("zram: promote zram from staging")
> > Signed-off-by: Jiacheng Xu <stitch@zju.edu.cn>
> > ---
> > 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 ace65c586072..2696bd3b29f6 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -2876,6 +2876,9 @@ static ssize_t disksize_store(struct device *dev, struct
> > device_attribute *attr,
> > return -EBUSY;
> > }
> >
> > + if (disksize > U64_MAX - (PAGE_SIZE - 1))
> > + return -EINVAL;
> > +
> > disksize = PAGE_ALIGN(disksize);
> > if (!zram_meta_alloc(zram, disksize))
> > return -ENOMEM;
>
> I think we already check disksize boundaries (you probably want to check
> out linux-next):
>
> if (!num_pages || ((u64)num_pages << PAGE_SHIFT) != disksize)
> return -EINVAL;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-20 9:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 3:13 [PATCH] zram: reject disksize values that overflow PAGE_ALIGN Jiacheng Xu
2026-08-20 4:07 ` Sergey Senozhatsky
2026-08-20 9:05 ` Jiacheng Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox