From patchwork Thu Mar 30 08:56:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 745148 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vtz5p1szxz9s2Q for ; Thu, 30 Mar 2017 19:57:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ARHORF0m"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=1HFTWegjJIGUHtw3n9Eczgm9GqNPBRjD/N14z5JTUpE=; b=ARH ORF0mpMNIKLg6SCVivv6zfIk3RC2WDJ38PB77LfplPv2DTVkPJ8XzFxP+uMCTy+K8M+YVBcYnOsro etFgPFkI5BGkCWrg7VMt83aIYOTmWDLYXljJ7IcA6JcwVSz+n1ZZnlbgkclUR9ngJDjEVgYvf3I9f GRlkg5SV5rTzWVMHcdy9U0R6nzIQp5gjeS2VKyGOj2MRCiW5rc/qtseJh/SzRZWZuERIZ2ASrA/ir ykr7lWP4aSbJQsNZesApukRAS8sOwVfqQwI0dmsdUa4FpR83NloN3vV+NRL4CINuEXLjHKU1h6Sqn OxGckg2cWmCI5asEu/dMoeT9+mQhGWQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctVt1-0001f5-8E; Thu, 30 Mar 2017 08:56:55 +0000 Received: from mail.sigma-star.at ([95.130.255.111]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctVsw-0001bU-1F for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 08:56:53 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id 02F2224E0002; Thu, 30 Mar 2017 10:56:27 +0200 (CEST) Received: from linux.site (richard.vpn.sigmapriv.at [10.3.0.5]) by mail.sigma-star.at (Postfix) with ESMTPSA id 104EF24E0001; Thu, 30 Mar 2017 10:56:26 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH] ubifs: Fix O_TMPFILE corner case in ubifs_link() Date: Thu, 30 Mar 2017 10:56:21 +0200 Message-Id: <1490864181-2192-1-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_015650_322541_60C24462 X-CRM114-Status: GOOD ( 10.73 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dedekind1@gmail.com, richard@nod.at, Amir Goldstein , linux-kernel@vger.kernel.org, stable@vger.kernel.org, adrian.hunter@intel.com, Ralph Sennhauser MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org It is perfectly fine to link a tmpfile back using linkat(). Since tmpfiles are created with a link count of 0 they appear on the orphan list, upon re-linking the inode has to be removed from the orphan list again. Cc: Cc: Ralph Sennhauser Cc: Amir Goldstein Tested-by: Ralph Sennhauser Reported-by: Amir Goldstein --- fs/ubifs/dir.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 0858213a4e63..0139155045fe 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -748,6 +748,11 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir, goto out_fname; lock_2_inodes(dir, inode); + + /* Handle O_TMPFILE corner case, it is allowed to link a O_TMPFILE. */ + if (inode->i_nlink == 0) + ubifs_delete_orphan(c, inode->i_ino); + inc_nlink(inode); ihold(inode); inode->i_ctime = ubifs_current_time(inode);