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 356664E5348; Tue, 13 Oct 2026 12:21:26 +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=1791894087; cv=none; b=j1mmFHX0sndtt4C1nqvSr/WPh6kyNSCvIyDol+y0VhJO/oJ/IZCvzmgNnFP6WWtwYcQ3GvSjm0ccRJo6QLqV1Op/oU3+sh4LcUkfKNFawbrCGra7s3JLaqdhkHqL+nDFjZWOcjYXKDwjljw5D2nypOccK9Teviwhl+XHtdKh+jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791894087; c=relaxed/simple; bh=wyylPMrarpOrGmubz25vlfmRjmDDw2qhVbRaEMe1xWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nm+jG5zCXf8jajY4firF2o3r3kgNMaFY/iKIhhrSt3T/mvNd6tgjTCFc06UJGHdzE7AsMEKeqHnVu66tjDiC50hG9mopnnPggnLb9u5FsTHya0SkT3gF8uhiagnhmc2uke1Zn/ikfx90XV5xuxZG7RvYLqvOrOvY97lIT1j+N50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZXegXm8N; 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="ZXegXm8N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 877311F000FF; Tue, 13 Oct 2026 12:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791894086; bh=FRYnCvjR/CJy/++0oImirfHKPWwiRL/QkdUS5yXqJIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZXegXm8N4/jDYKGuTbfsXaYprkO3Hb+3/BeQ1wO9HFRx2n0S3KmADMfzofU6KmcXc NYShLw21NlbnmuVqgvECOkcVE5iKhcx29IVc3pygpTrS86Ajy2w5kIGGH/Vq1NU44J EKQGaWlNTS0VUUS471/8JWZ1qiXD6U4JhzVOtebE= 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 388/621] zram: fix out-of-bounds access in writeback_store() Date: Tue, 13 Oct 2026 13:36:23 +0200 Message-ID: <20261013112930.051754174@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261013112920.855194808@linuxfoundation.org> References: <20261013112920.855194808@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 894913e2d35c46ff19a77530907771ae57862b96 ] Patch series "zram: fix stale scan bounds after reinitialization". Both writeback_store() and read_block_state() derive their table scan bounds from zram->disksize before acquiring dev_lock. If the device is reset and reinitialized with a smaller disksize between that read and lock acquisition, the bound can describe the old table while the scan operates on the new one. This can lead to out-of-bounds slot accesses. Move both bound calculations under dev_lock so each bound remains consistent with the table throughout its scan. Keep the fixes separate because the affected interfaces originate from different commits and can be backported independently. This patch (of 2): writeback_store() calculates the table scan bounds before taking dev_lock. A reset followed by reconfiguration with a smaller disksize can therefore replace zram->table while writeback_store() is waiting for the lock. Once it acquires the lock, it sees an initialized device but scans the new table using the old upper bound, resulting in an out-of-bounds access. Calculate the number of pages while holding dev_lock so the scan bound matches the table protected by the lock. Link: https://lore.kernel.org/20260804065919.3970386-1-xialonglong2025@163.com Link: https://lore.kernel.org/20260804065919.3970386-2-xialonglong2025@163.com Fixes: a939888ec38b ("zram: support idle/huge page writeback") 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5a08e8bebd6df..ea5a9b81a310e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -948,8 +948,8 @@ static ssize_t writeback_store(struct device *dev, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); - u64 nr_pages = zram->disksize >> PAGE_SHIFT; - unsigned long lo = 0, hi = nr_pages; + u64 nr_pages; + unsigned long lo = 0, hi; struct zram_pp_ctl *ctl = NULL; char *args, *param, *val; ssize_t ret = len; @@ -972,6 +972,9 @@ static ssize_t writeback_store(struct device *dev, goto release_init_lock; } + nr_pages = zram->disksize >> PAGE_SHIFT; + hi = nr_pages; + ctl = init_pp_ctl(); if (!ctl) { ret = -ENOMEM; -- 2.53.0