Re: [PATCH 1/1] zram: reject disksizes that exceed slot index range

From: Sergey Senozhatsky

Date: Tue Aug 04 2026 - 21:28:37 EST


On (26/08/04 22:38), Longlong Xia wrote:
> 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.
>
> Fixes: 33863c21e69e ("Staging: zram: Replace ioctls with sysfs interface")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Assisted-by: Codex:gpt-5.6-sol
> Signed-off-by: Longlong Xia <xialonglong@xxxxxxxxxx>

Reviewed-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>