Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4639354ybl; Mon, 9 Dec 2019 14:24:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyGPwO46/EVM0EKXbo7YXxJKg6uHjPqRL3MaG/tWunSBwjFM/f9Qyc2OGP27buyGhmnCxt6 X-Received: by 2002:aca:ab95:: with SMTP id u143mr1344423oie.128.1575930281022; Mon, 09 Dec 2019 14:24:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575930281; cv=none; d=google.com; s=arc-20160816; b=tL2a/g81HsFLliXnGm5Y8Tuxe8G3G1oZ5Aa4FUpDe4zUkeBnUAd24WzctH27e9EeX8 5JrYBuu28T54XuYT6oby0PaxDuTe7d9YSoR5q1aE9UHueyogsnp2DbzD/mAIbxGoCA+2 rLjWUs0NrjJXvMoqv1zkgfyeNUCdAti8/jj59lUD7ngqosOpGNgjTw2JjKNLQHXqY6j2 2tEdrUFXO/Cq8Oc6Y9faC46Nb9C3exgDcCGJm4xnVgNtZXcDKtgcdE06R71Aver4QeYN zKsS0bZWRZWgMOus69Ywd++Nb1GuBQJfOYcoEph7Gv8SGAc2EtiWLVxOPTaYD684cpL5 3VzQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=z/oiHcjiw+o6GyDLOumaRxV2O2cWj7nYtfBCzlLAzwQ=; b=fjFXFmV6XaASeJxgHoUtGWeVQSSnQ3HXr6KN2AdV3r2VUBXqLbkmNGlAFEDyiYv51j RCTW/o9U2MWLgZOPrUj3QbJHANqzFci6Dwkqh/Yg3BiAo74q/3XYxNnM6wxpAEeEOGyU q4uy2OclZj2b+1hf3h/BGMSr//B7Fb1NVeJSkIROUSXPOORfd11x5bTxMmqCyV4dAUYb gH/w45HO9M75VPZQpUIW+cVjNsSw8A2XBvxP0UzGSXRinluv4PDUhdpUbIKuXaWsYzMS 5jYe6gQsNrCiLraAsA3KC+5EI1OtQtaVbPfMISFnXUxqO/vxhLYeo28CeynBngXNRi6m CtVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XR0W5USg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j26si649118otk.291.2019.12.09.14.24.28; Mon, 09 Dec 2019 14:24:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XR0W5USg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbfLIWXw (ORCPT + 99 others); Mon, 9 Dec 2019 17:23:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:40608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbfLIWXv (ORCPT ); Mon, 9 Dec 2019 17:23:51 -0500 Received: from localhost (unknown [104.132.0.81]) (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 092792077B; Mon, 9 Dec 2019 22:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575930230; bh=GVlYvsMRRyavxn/zXjrz3uDCgvOaDXX411kOrF5IbxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XR0W5USgZHzG07sOfWJ+ubFjq+I6N+kRIQeyWBCCKrSrgXbDpt26yGGazqqXogFEz N7kvMXysmOh/pKZitWqMXVRyJT5yxR+dlnRvwDknxMoO+9WPrmW0ZNNI5BvsY4Si79 ZKLgZgR82aj2yi3QmEm75W32A43j1VBFC5LQizAg= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 6/6] f2fs: set I_LINKABLE early to avoid wrong access by vfs Date: Mon, 9 Dec 2019 14:23:45 -0800 Message-Id: <20191209222345.1078-6-jaegeuk@kernel.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20191209222345.1078-1-jaegeuk@kernel.org> References: <20191209222345.1078-1-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch moves setting I_LINKABLE early in rename2(whiteout) to avoid the below warning. [ 3189.163385] WARNING: CPU: 3 PID: 59523 at fs/inode.c:358 inc_nlink+0x32/0x40 [ 3189.246979] Call Trace: [ 3189.248707] f2fs_init_inode_metadata+0x2d6/0x440 [f2fs] [ 3189.251399] f2fs_add_inline_entry+0x162/0x8c0 [f2fs] [ 3189.254010] f2fs_add_dentry+0x69/0xe0 [f2fs] [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] [ 3189.261079] vfs_rename+0x3f8/0xaa0 [ 3189.263056] ? tomoyo_path_rename+0x44/0x60 [ 3189.265283] ? do_renameat2+0x49b/0x550 [ 3189.267324] do_renameat2+0x49b/0x550 [ 3189.269316] __x64_sys_renameat2+0x20/0x30 [ 3189.271441] do_syscall_64+0x5a/0x230 [ 3189.273410] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 3189.275848] RIP: 0033:0x7f270b4d9a49 Signed-off-by: Jaegeuk Kim --- fs/f2fs/namei.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index a1c507b0b4ac..5d9584281935 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -797,6 +797,7 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, if (whiteout) { f2fs_i_links_write(inode, false); + inode->i_state |= I_LINKABLE; *whiteout = inode; } else { d_tmpfile(dentry, inode); @@ -867,6 +868,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, F2FS_I(old_dentry->d_inode)->i_projid))) return -EXDEV; + if (flags & RENAME_WHITEOUT) { + err = f2fs_create_whiteout(old_dir, &whiteout); + if (err) + return err; + } + err = dquot_initialize(old_dir); if (err) goto out; @@ -898,17 +905,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, } } - if (flags & RENAME_WHITEOUT) { - err = f2fs_create_whiteout(old_dir, &whiteout); - if (err) - goto out_dir; - } - if (new_inode) { err = -ENOTEMPTY; if (old_dir_entry && !f2fs_empty_dir(new_inode)) - goto out_whiteout; + goto out_dir; err = -ENOENT; new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, @@ -916,7 +917,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, if (!new_entry) { if (IS_ERR(new_page)) err = PTR_ERR(new_page); - goto out_whiteout; + goto out_dir; } f2fs_balance_fs(sbi, true); @@ -948,7 +949,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, err = f2fs_add_link(new_dentry, old_inode); if (err) { f2fs_unlock_op(sbi); - goto out_whiteout; + goto out_dir; } if (old_dir_entry) @@ -972,7 +973,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, if (IS_ERR(old_page)) err = PTR_ERR(old_page); f2fs_unlock_op(sbi); - goto out_whiteout; + goto out_dir; } } } @@ -991,7 +992,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, f2fs_delete_entry(old_entry, old_page, old_dir, NULL); if (whiteout) { - whiteout->i_state |= I_LINKABLE; set_inode_flag(whiteout, FI_INC_LINK); err = f2fs_add_link(old_dentry, whiteout); if (err) @@ -1027,15 +1027,14 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, f2fs_unlock_op(sbi); if (new_page) f2fs_put_page(new_page, 0); -out_whiteout: - if (whiteout) - iput(whiteout); out_dir: if (old_dir_entry) f2fs_put_page(old_dir_page, 0); out_old: f2fs_put_page(old_page, 0); out: + if (whiteout) + iput(whiteout); return err; } -- 2.19.0.605.g01d371f741-goog