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 AE7A13CDBD3; Thu, 17 Sep 2026 19:01:13 +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=1789671682; cv=none; b=dFGMVazXb6++kb6Rd1U8O8ky1vY8HjBlaVE7xF6D9TWBqMgKI49Et3tgWcYQo9kf1x2Em4Ozbyu6wAco4J4jy6I664gahOv6RojaWU+3UU3jeOGyOrpM8JPQO1FTZkJgBFlfNskxOHXI0Xk3aY6orKSM/7LJp4OLe9II0E3OHfg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789671682; c=relaxed/simple; bh=4NAXNc6+dqez8XTmt89vHm22ExuyqYT6SryLKOVZmH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ruhkimNIFaQAXHcB0H7yWBvgVc2EIwd3aWgmrPDyFhDFZBP6VviKfkUC9le53Bs2e1varOCWQy0P9jT0hvRI8tcNskh6TGSHNPMAemEM37HJUvwfZG5GIZ9Kzu4d0HBxceTzFaX3HV+E2796+pb1Nl1rz68OSapPwdYn6odLk9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PAlZjMsd; 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="PAlZjMsd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 275E81F008A0; Thu, 17 Sep 2026 19:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789671663; bh=5JFCXPmpXnjmWqaiP1TcEIl+K3WWXSJ5bEFvwcyYyTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PAlZjMsdu6h4Qm0BFb0xnA+xI6IZmFgtItMWtKAbKtr5vXsDoR6ZoWNKpEd7KBXtz mMbW9dGKQ5SePWTCwm4nL/g/k+amf0ZYnsKzp878zxqHOwLqwFAgSL79Np6bAtxNl6 gop6cjzBmFLNF4WroG0OpxCwTfmcROVWGLGD1zns= 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.12 1012/1102] zram: fix out-of-bounds access in read_block_state() Date: Thu, 17 Sep 2026 16:15:55 +0100 Message-ID: <20260917151606.154273914@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151539.408551884@linuxfoundation.org> References: <20260917151539.408551884@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.12-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 Signed-off-by: Greg Kroah-Hartman --- drivers/block/zram/zram_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -868,7 +868,7 @@ static ssize_t read_block_state(struct f 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) @@ -881,6 +881,8 @@ static ssize_t read_block_state(struct f return -EINVAL; } + nr_pages = zram->disksize >> PAGE_SHIFT; + for (index = *ppos; index < nr_pages; index++) { int copied; struct timespec64 ts;