From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385176; b=1medUvrshQ2r5DqKQ9C5OHp0YFhl+wpOyVidXtM4YOCv6r1coC9fXUfvZaElcKF281fV msBd+mVKSDOkEcADjht0w+Ae/wxMfQhSvs+rpYNWoFdcL6i9zG5sU0WbvkBAa2YyORVBt tR7GmudgO8Jk5Re/mJ4WANOOQ/CaA6LIqXE6dYtTARFQS8lWyR+7n/shGycfWbz8seiYh /+HWZNc6yzv0eTRXLaAHqm35hYKeOwLak6jy0DDGWXfl4YmCuhqFXfs6P0leOPbhmZwcw NdYRIC+GLneO3D0xU87yYVsS+JNZX08e7Ci7uDSwObM0w/sMxXYrrffzZzJJtjJn9mg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385176; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=G42405Uc45fJcb5r5TH3kRsCMNs4vTvVw/D0g6mpMOg=; b=3ZVpheLKe6x5tzR0PqP+HcwFslr3wt0Xk7+TV/jIaq52UVNWWb/fTrWNA03x7/lElqb6 OHKlXh2Cn7qv3nraj4bsZxavbkIZr5Dl0yIvzEX0SDq1rVpW4PNi1pev6pKu58bz60B7P 3EooGSiNl5OKFV8zQKG6wBJPuWKT2UYh46R87SHftK0DXJ1C5XaR4zX1ZZu0wJ6THKyLl y+PN+LoS8LMJc4s25zTHIzT63Xst/0QRKNh53tMS5z9G/7hEt7Tk5gh5VJraSAGpNtGIN xj2LJvln2JjTMwingBz9ZUwfF5pPnqs2oL1wYDsxtNiiJrhSenqgV+ra1o3lLYtEQnA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gfeFegjX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FC18606A322; Fri, 4 Dec 2026 11:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gfeFegjX Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB39E1F000C2; Fri, 4 Dec 2026 11:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385176; bh=G42405Uc45fJcb5r5TH3kRsCMNs4vTvVw/D0g6mpMOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gfeFegjXyp3GV+OJlS8JHAvMbP89JsHxQIh2M8tiEnKl1DuveQateono8v0eZOXuJ GCDl5CtvBZUEynl1H4WytxQ3q4RzaSPIAczVRI5gG/OMz6EMws4qgNN8W9jdAieo8O zsd2bR128sRLBa5111Uzg380iFKpgGS+4LiGwsxc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chi Zhiling , Namjae Jeon , Sasha Levin Subject: [PATCH 6.6 0449/1167] exfat: fix used_clusters accounting during cluster allocation Date: Fri, 4 Dec 2026 18:57:56 +0900 Message-ID: <20261204100713.709528886@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chi Zhiling [ Upstream commit cb9dbf8a4e34b4fdf311598835ab4d76ed7e07c1 ] In the current exfat_alloc_cluster(), p_chain->size is incremented as each cluster is allocated so that the partially allocated chain can be freed by __exfat_free_cluster() on the error path. However, sbi->used_clusters is still updated only after all clusters have been allocated, while __exfat_free_cluster() unconditionally subtracts the number of freed clusters from sbi->used_clusters. Therefore, when allocation fails partway through, the partially allocated clusters are subtracted from sbi->used_clusters even though they were never added to it. This corrupts the free-space accounting and can cause sbi->used_clusters to underflow. Increment sbi->used_clusters together with p_chain->size as each cluster is allocated. This keeps the accounting consistent with __exfat_free_cluster() on both the success and error paths. This issue is caught by generic/476 with 256k cluster size: Ran: generic/476 Failures: generic/476 Failed 1 of 1 tests *** fsck.exfat output *** ERROR: : more clusters are allocated. truncate to N bytes ... /dev/vdc: corrupted. directories 331, files 526 /dev/vdc: files corrupted 9, files fixed 0 *** end fsck.exfat output *** Fixes: d5c514b6a0c0 ("exfat: fix the newly allocated clusters are not freed in error handling") Signed-off-by: Chi Zhiling Signed-off-by: Namjae Jeon [ sashal: Dropped the local sbi->used_clusters += num_alloc; line and its trailing blank line instead of upstream's p_chain->size form, since this tree has no done: label. ] Signed-off-by: Sasha Levin --- fs/exfat/fatent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index e5f4ce8c38e1a..c25613fe4d948 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -402,13 +402,12 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, } } p_chain->size++; + sbi->used_clusters++; last_clu = new_clu; if (p_chain->size == num_alloc) { sbi->clu_srch_ptr = hint_clu; - sbi->used_clusters += num_alloc; - mutex_unlock(&sbi->bitmap_lock); return 0; } -- 2.53.0