From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60918C28CC4 for ; Wed, 3 Mar 2021 00:47:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2176264FB5 for ; Wed, 3 Mar 2021 00:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239908AbhCCA3j (ORCPT ); Tue, 2 Mar 2021 19:29:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:52496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1447101AbhCBMmZ (ORCPT ); Tue, 2 Mar 2021 07:42:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7DB9C64F81; Tue, 2 Mar 2021 11:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614686275; bh=W37Gyp3g8smGOxEQWlmsBfoNwDFpQ2O/lIDtM+zaLTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bv4C7ykcglRqF/bFqOrdPCljm5kah8xETP5pTbbT+IlKKgr7LLEBq2DEgEvpj2KWb lCayofVVZXlrT4T7I/FiuV2HR6hWs5uhVaxCydWt5Qc9t/G/Dh+xSTUsoZkh9HzZE0 0UKRFngjTRSnkulXOXfaLMcnyegwxSY5m0r86YIkN9pq4RQbp8JG+snewXxbXyxBeD /59rmXXtwCGp9FLFOL452fa8dgw56GKmeF0+wf/hXts3swRH8ofVI73NGcurUhd51x mIU1ghUBn+FB5//NeVBkw1y1XqdyU4mKUwCSkyhI/Z//2XleFqRc+5xPZBGxHNdczy wCD3cait60QpQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Steven J. Magnani" , Jan Kara , Sasha Levin Subject: [PATCH AUTOSEL 5.4 03/33] udf: fix silent AED tagLocation corruption Date: Tue, 2 Mar 2021 06:57:19 -0500 Message-Id: <20210302115749.62653-3-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210302115749.62653-1-sashal@kernel.org> References: <20210302115749.62653-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Steven J. Magnani" [ Upstream commit 63c9e47a1642fc817654a1bc18a6ec4bbcc0f056 ] When extending a file, udf_do_extend_file() may enter following empty indirect extent. At the end of udf_do_extend_file() we revert prev_epos to point to the last written extent. However if we end up not adding any further extent in udf_do_extend_file(), the reverting points prev_epos into the header area of the AED and following updates of the extents (in udf_update_extents()) will corrupt the header. Make sure that we do not follow indirect extent if we are not going to add any more extents so that returning back to the last written extent works correctly. Link: https://lore.kernel.org/r/20210107234116.6190-2-magnani@ieee.org Signed-off-by: Steven J. Magnani Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/udf/inode.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 97a192eb9949..507f8f910327 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -547,11 +547,14 @@ static int udf_do_extend_file(struct inode *inode, udf_write_aext(inode, last_pos, &last_ext->extLocation, last_ext->extLength, 1); + /* - * We've rewritten the last extent but there may be empty - * indirect extent after it - enter it. + * We've rewritten the last extent. If we are going to add + * more extents, we may need to enter possible following + * empty indirect extent. */ - udf_next_aext(inode, last_pos, &tmploc, &tmplen, 0); + if (new_block_bytes || prealloc_len) + udf_next_aext(inode, last_pos, &tmploc, &tmplen, 0); } /* Managed to do everything necessary? */ -- 2.30.1