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 552792D23A6; Sat, 12 Sep 2026 13:34:34 +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=1789220076; cv=none; b=P/XPKEmczWhniGoBL3AfCRh58GbWxX0FKOZNcEe6pp62PQjm9MNF6AVf+GmhbgV7dXbDzZE9KU7PsRuk7w1XoZV99MLx9Bxlhn+/Mn7J0cyBBUifr9PTrw1kG/KnNUdlYZdpmxrsxx7dFZHeTjiY7fVEcjHRbek/yNKVbPkowGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789220076; c=relaxed/simple; bh=AOaZ6N+xh+har/zk2zx6JsKcic9n/P+qoS+uUvu9cPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Znt9pjFfCVcUZ+lY6Srf1vcdPPp/WoF7SrI0P/bOCjw7uIR6zQXYFvt9bXybSPmlXUu5K+HTeMbtU/oofFob7wYF6V+B/N9CULbI9RuoIY9u5xk5KzFn8n9zYSsflRkJVIWULDSuKCJDgK+OsiRrSoTsm0IqEsxtrtz/9F9vIbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zja51b1D; 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="zja51b1D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A2F41F00893; Sat, 12 Sep 2026 13:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789220074; bh=mbzS4/iTahjTSW0Ft/tA7/47XbGr9b5hzskfOBAVoys=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zja51b1DvlakCZb1+3Rl3GcQkkaBKtI/mYGS1HhulDNtOdAf/dYl+wmo1+fUnTIKX 2JTpzpBRIYiSOIYMahA+EFw/C8WXkjH31OGsc3sKWpLwBGavLtaVOS7Ck4EwiOKlqM 50AhJJPZcMD94sl9ooWybxR9ymMw4c/2C1SVKvyQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yemu Lu , Ren Wei , Yuan Tan , Yifan Wu , Juefei Pu , Xin Liu , OGAWA Hirofumi , Christian Brauner , Andrew Morton Subject: [PATCH 6.6 0102/1424] fat: restore original value when fat_ent_write failed Date: Sat, 12 Sep 2026 08:42:14 +0200 Message-ID: <20260912065609.590627405@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@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: Yemu Lu commit 64d9183203eebe33de6188b70a8c1e91f52885db upstream. fat_ent_write() may have committed the new link to the primary FAT but then failed on the mirror copy, leaving the chain pointing to new_dclus even though the caller will free it. Restore the original value to keep the chain consistent. Link: https://lore.kernel.org/20260525085649.781643-1-n05ec@lzu.edu.cn Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Yemu Lu Signed-off-by: Ren Wei Reported-by: Yuan Tan Reported-by: Yifan Wu Reported-by: Juefei Pu Reported-by: Xin Liu Acked-by: OGAWA Hirofumi Cc: Christian Brauner Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/fat/misc.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/fat/misc.c +++ b/fs/fat/misc.c @@ -133,7 +133,11 @@ int fat_chain_add(struct inode *inode, i ret = fat_ent_read(inode, &fatent, last); if (ret >= 0) { int wait = inode_needs_sync(inode); + int old = ret; + ret = fat_ent_write(inode, &fatent, new_dclus, wait); + if (ret < 0) + fat_ent_write(inode, &fatent, old, wait); fatent_brelse(&fatent); } if (ret < 0)