The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Longlong Xia <xialonglong2025@163.com>
Cc: minchan@kernel.org, senozhatsky@chromium.org, axboe@kernel.dk,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Longlong Xia <xialonglong@kylinos.cn>
Subject: Re: [PATCH 1/1] zram: reject disksizes that exceed slot index range
Date: Wed, 5 Aug 2026 11:54:24 -0700	[thread overview]
Message-ID: <20260805115424.a0c8abdb9bbd2f7caa6fb66a@linux-foundation.org> (raw)
In-Reply-To: <20260804143832.146129-1-xialonglong2025@163.com>

On Tue,  4 Aug 2026 22:38:32 +0800 Longlong Xia <xialonglong2025@163.com> wrote:

> From: Longlong Xia <xialonglong@kylinos.cn>
> 
> zram uses u32 slot indexes, while disksize_store() accepts a u64
> size. On 32-bit systems, a disksize larger than U32_MAX pages is
> truncated when zram_meta_alloc() assigns the page count to size_t.
> array_size() then sees only the truncated count, so a small table can
> be allocated while the original capacity is published. Valid I/O
> within that capacity can subsequently access beyond zram->table.
> 
> The same oversized capacity also lets full-device scanners compare a
> u32 index with an upper bound larger than U32_MAX, so the index can
> wrap instead of terminating.
> 
> Reject disksizes larger than U32_MAX pages before aligning and
> allocating the table. This keeps the table size, published capacity and
> slot index range consistent.

Oh.  Rejecting large devices sounds severe.  Can't we just fix the
32-bit trucation issues?

> --- 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)U32_MAX << PAGE_SHIFT)
> +		return -EINVAL;
> +

It would be helpful to have a comment explaining why we're doing this.


AI review appears to have found a similar issue in mark_idle(),
although it could be that your patch accidentally prevents it from
occurring:

	https://sashiko.dev/#/patchset/20260804143832.146129-1-xialonglong2025@163.com

  parent reply	other threads:[~2026-08-05 18:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 14:38 [PATCH 1/1] zram: reject disksizes that exceed slot index range Longlong Xia
2026-08-05  1:28 ` Sergey Senozhatsky
2026-08-05 18:54 ` Andrew Morton [this message]
2026-08-06  2:41   ` Sergey Senozhatsky

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=20260805115424.a0c8abdb9bbd2f7caa6fb66a@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --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=stable@vger.kernel.org \
    --cc=xialonglong2025@163.com \
    --cc=xialonglong@kylinos.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox