Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1105405pxa; Thu, 20 Aug 2020 02:37:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzkeELjUW/pPK3BqG8EDacq6+Ib1eJl6jIPb6YecbClSD6C4QadzDml1h/SL0SMfrhm+pQ X-Received: by 2002:a17:907:385:: with SMTP id ss5mr2293883ejb.496.1597916222132; Thu, 20 Aug 2020 02:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916222; cv=none; d=google.com; s=arc-20160816; b=M4xLLD1jlcnq9awxU3V6Jy6ZgfxjBU4ZCSI4OKtL9SLKQCv02Psa8jLJrlRiOJhETI 2Q1MJaGYGqcb0JM8e11mOrUCFGSmJH9WUExX/ZzzARBESzBeJ0oEekqLelD2B0BrPmni b5WRfrwzOluUDiIuWM3rfSiGjlftOpbmDYc/2AaVcPEXiO6kUv6cZ7+urkK4xRDyvyNS ETSnmPMPAanqCUIhcAP6P5eqdmaSG4KAH8i+Ewp2YXKr6y6CXdUj57Jvso54yZ6+h+rM RCAwGRFEpYVYPEA5j/XPq1CYP6Pt/XsD4JbBeyxv+WTRi2HdqjIpDlHGSEQQJFM3+Fel Ot1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R8tnXY14NS7esqSJgw2Wc6mrY336OnAsV6xFifHPApI=; b=jnYm/BqoIi3HAdVpeA1AaYe1FXckwwWxTecbLcy4ICmNtUUv7cF9R96BaoKl4WBFSN kvBa52B5sNo2iJYDD01QZhXllfX/C29q+hJ2ScqgYvf8OhiQCd3/lUzZxY6i8f1Et2SY mSv7v4LIfFHJGQYEwfm7SBJ4W+A11uOY9jN5df3iVXzEA/IH57lkxOSAoDttNA7jAEnG sEZDpcDX2Qd7kTTOgelTZZBeHQk9h0zGhUCqg26DviwsHCAXfI1yB6J+VS2e9FhB906D 4sLXsoEjk22MVT05TIC7ST325/8VnBKphL9U9cihdRXnmEUikblilXFV1h0B4pDmXbVr hSUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uwhvQ5DW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si872227ejx.477.2020.08.20.02.36.37; Thu, 20 Aug 2020 02:37:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uwhvQ5DW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgHTJeF (ORCPT + 99 others); Thu, 20 Aug 2020 05:34:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728252AbgHTJbr (ORCPT ); Thu, 20 Aug 2020 05:31:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 79DA220724; Thu, 20 Aug 2020 09:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915907; bh=GLXQfcRWfRzS75qj46k4hC5dnG429jw21sLIeHx3YyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwhvQ5DWzRbqvZg3IX5nIYScR3sb5JA+NnAt6gMzS23CNFEQy/nkgA7GsRwfKpHaE fDbh1uTo2i9XDuLLImjHVzGjPtJEli54xIEaYgq2XABrWWs1kTz+pF55LTrcuadF5l LaE1blJCrYUZ+wXkmAO9gI4xvZQdqXuYqzBaDthI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger , Sasha Levin Subject: [PATCH 5.8 176/232] ubifs: Fix wrong orphan node deletion in ubifs_jnl_update|rename Date: Thu, 20 Aug 2020 11:20:27 +0200 Message-Id: <20200820091621.342215904@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng [ Upstream commit 094b6d1295474f338201b846a1f15e72eb0b12cf ] There a wrong orphan node deleting in error handling path in ubifs_jnl_update() and ubifs_jnl_rename(), which may cause following error msg: UBIFS error (ubi0:0 pid 1522): ubifs_delete_orphan [ubifs]: missing orphan ino 65 Fix this by checking whether the node has been operated for adding to orphan list before being deleted, Signed-off-by: Zhihao Cheng Fixes: 823838a486888cf484e ("ubifs: Add hashes to the tree node cache") Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- fs/ubifs/journal.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index e5ec1afe1c668..2cf05f87565c2 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, const struct fscrypt_name *nm, const struct inode *inode, int deletion, int xent) { - int err, dlen, ilen, len, lnum, ino_offs, dent_offs; + int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0; int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir); int last_reference = !!(deletion && inode->i_nlink == 0); struct ubifs_inode *ui = ubifs_inode(inode); @@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, goto out_finish; } ui->del_cmtno = c->cmt_no; + orphan_added = 1; } err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync); @@ -702,7 +703,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, kfree(dent); out_ro: ubifs_ro_mode(c, err); - if (last_reference) + if (orphan_added) ubifs_delete_orphan(c, inode->i_ino); finish_reservation(c); return err; @@ -1218,7 +1219,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, void *p; union ubifs_key key; struct ubifs_dent_node *dent, *dent2; - int err, dlen1, dlen2, ilen, lnum, offs, len; + int err, dlen1, dlen2, ilen, lnum, offs, len, orphan_added = 0; int aligned_dlen1, aligned_dlen2, plen = UBIFS_INO_NODE_SZ; int last_reference = !!(new_inode && new_inode->i_nlink == 0); int move = (old_dir != new_dir); @@ -1334,6 +1335,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, goto out_finish; } new_ui->del_cmtno = c->cmt_no; + orphan_added = 1; } err = write_head(c, BASEHD, dent, len, &lnum, &offs, sync); @@ -1415,7 +1417,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, release_head(c, BASEHD); out_ro: ubifs_ro_mode(c, err); - if (last_reference) + if (orphan_added) ubifs_delete_orphan(c, new_inode->i_ino); out_finish: finish_reservation(c); -- 2.25.1