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 2C8BC595748; Wed, 9 Sep 2026 14:40:24 +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=1788964825; cv=none; b=guIGj8K0TWi12X8T3qF+SNECj+rb8COceiJe7USjuv5fkfIemOq9MAnG84Gk1trXaJ8vZPuHVi/rxk70JEDGuGfZaptB5Ka4MXVA190eevkS/T447VZXcw3pEvRbjiNLy8O6K7iJZlEmrYU3oqpLcEaRYN70s5rpEawtxYj/97k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964825; c=relaxed/simple; bh=A4bjCSG9IBQrEVm6vadH84nw87TCfcA/6Q/nGIiIkf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mBvhH1p+Qva/CkNPLtLVmTzhwwKQxttgwr/bbHsf8NQKF7BSf9WjyYdNG3aTtzxoi7nK4fI+nGP9PjG8pF73Xd5M4wA7a/oTRjebf3lRnaaY0Kj9lUGQV41mi3PGsChdIcWEnIR6PnlMrcdgz2+4/05qwQxnt+NjFZbF7Q6ilpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cTWoUqPU; 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="cTWoUqPU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 901D11F00A3A; Wed, 9 Sep 2026 14:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788964824; bh=/Tr4rlHrG5nhS6eB4Ngqpjubw2mQApb6p02AR8wqdRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cTWoUqPUYkqBJ4ZbCVDIivqb9Wy43i3eur7CDW+ee6xEzZg3QWtiL0sRjGKs4afVE xd84Pjs3OCqCsssjYMgVHCI3h5lzPb1H3dpwRxQSsCM93VEbHEg5VfgfciVb5ZL/VH PuIg9kQr5TFGJc6cF7MXuS+xeyPM4AAXR1env/jA= 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.18 554/583] zram: fix out-of-bounds access in read_block_state() Date: Wed, 9 Sep 2026 15:43:59 +0200 Message-ID: <20260909134256.898453605@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@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.18-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 @@ -1135,7 +1135,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) @@ -1148,6 +1148,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;