From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADB93277026; Sat, 17 Oct 2026 16:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792255894; cv=none; b=cjQCocgc5UFCgEpbboIaRVUUmGB+0u8f/6g6SF437i2bYXDifYU3OXz0NFH2VJJmfLPNy6EAUJ4CuQXKdKj7iPnmxUc/C/+HaOvrCMqdWKr9jUQQRp8mb7sD3GwmJSGdhWfGX2UowgYQzS6vXG5PWXV//hKIilzOs7tzUC1yZoY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792255894; c=relaxed/simple; bh=XZ/l2cOhApuMlN3hFYTBbY9hNGo/rreVBrGBSsuf0Bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r6mWK5wu6Hu9vnEu7Z/TZilIVGVcaGeJYS3whmc0YwapG5/q3ybXd+Ru3SHbw+sqDGIwH9FSSdDT/ykmuYR/RFHyg8uBbJjNxKduFvTVeNbA2HvqssFs7ypwZo8H3On3AdxqWvdhvKShn/dhyLoPylQpgLQXpW+pD3wxFjBzWA4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=n5jXx0gK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n5jXx0gK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 089F01F000C4; Sat, 17 Oct 2026 16:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792255893; bh=bfBjtO+LHJen3HtDEUHWkmik/jhwHEJRuq6bhoa7O94=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n5jXx0gK5xk6CVBgGUjnnDOTcTIWl6SVmutnDJIcvXpsiJcVfc2zES8+KVaHLDBP6 XMmrboOuF0UaXosml0wRj370hp2n83VrkxPJjBseZdsZMwP0yniao41ulAeeu5wjTx 9M3xTP2ViD61AxioVrjm7H5XKbzpC/c+R1DjSclI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Longlong Xia , Sergey Senozhatsky , Jens Axboe , Minchan Kim , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 0055/1674] zram: fix out-of-bounds access in read_block_state() Date: Sat, 17 Oct 2026 17:38:47 +0200 Message-ID: <20261017160432.550778497@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Longlong Xia [ Upstream commit 391f057f44a51cc9418da5cba78b014324174264 ] read_block_state() calculates nr_pages before taking dev_lock. If the device is reset and reinitialized with a smaller disksize before lock acquisition, nr_pages still describes the old table. The subsequent loop can then call slot_lock() past the end of the newly allocated table. Read disksize after acquiring dev_lock and checking that the device is initialized. The read lock then keeps the table and its bound stable for the duration of the scan. Link: https://lore.kernel.org/20260804065919.3970386-3-xialonglong2025@163.com Fixes: c0265342bff4 ("zram: introduce zram memory tracking") Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Longlong Xia Reviewed-by: Sergey Senozhatsky Cc: Jens Axboe Cc: Minchan Kim Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- drivers/block/zram/zram_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 91a1cec8a6e3f..c83ef64521ee5 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -878,7 +878,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf, char *kbuf; ssize_t index, written = 0; struct zram *zram = file->private_data; - unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; + unsigned long nr_pages; kbuf = kvmalloc(count, GFP_KERNEL); if (!kbuf) @@ -891,6 +891,8 @@ static ssize_t read_block_state(struct file *file, char __user *buf, return -EINVAL; } + nr_pages = zram->disksize >> PAGE_SHIFT; + for (index = *ppos; index < nr_pages; index++) { int copied; struct timespec64 ts; -- 2.53.0