All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Jiacheng Xu <stitch@zju.edu.cn>
Cc: Minchan Kim <minchan@kernel.org>,
	 Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] zram: reject disksize values that overflow PAGE_ALIGN
Date: Thu, 20 Aug 2026 13:07:38 +0900	[thread overview]
Message-ID: <aoZ9LkrqVbH9pLi_@google.com> (raw)
In-Reply-To: <1760e5f1.15b52.1a01d28f800.Coremail.stitch@zju.edu.cn>

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;

  reply	other threads:[~2026-08-20  4:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20  3:13 [PATCH] zram: reject disksize values that overflow PAGE_ALIGN Jiacheng Xu
2026-08-20  4:07 ` Sergey Senozhatsky [this message]
2026-08-20  9:05   ` Jiacheng Xu

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=aoZ9LkrqVbH9pLi_@google.com \
    --to=senozhatsky@chromium.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=stitch@zju.edu.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.