Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1619373ybv; Fri, 21 Feb 2020 00:24:47 -0800 (PST) X-Google-Smtp-Source: APXvYqz9uEfP4w34ZeqGGm1yqNCktiMa0gGABlouQbYCX9nCDpsL26OcE88MZY7Jlxs4FCYqjnYh X-Received: by 2002:aca:ea43:: with SMTP id i64mr1066240oih.30.1582273486998; Fri, 21 Feb 2020 00:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273486; cv=none; d=google.com; s=arc-20160816; b=XRPKBX0Ro33Jb5tU/nfK5oNB6mU4WhiM9mvurdTZiQNzGDNM1ImCDtay9wL4Eb0Fz5 A19UycyYOkl/CSzlU/lCVv2qfKH+P+TThGf6qBIYC22HyCs7EbG89ct7hlmdQ1W/DkZP iR7cNwdPuKQVwWEA8vl/EKg/KzSCI8cjbN/CEHHa2hLCqu9kfw41yTELhnd5342BLwbJ DBEnyab5e1g5sz3TD4ct/usymAhOZ1e85O4Jz1CN+hFIhhNE+gwBSu9pzVjEZ4IKAmQl ZExGAqrlxpJhifUcOXyGRhlRx7WhXbiXAFRLumFVtjKnTSnXrzle2QA4UfbtUMgmxKjR AuLg== 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=nXj4iMaoFizHHzoqygi2pQn2DXg1306JXdgd5xtrxk4=; b=DYQugqg0c2afUIg+7PQpRmDSteEyS0TAXTI31OSvp5bMil6WajUmtCBBj0ATwk9nLu lZTqaCxBfWkBYNvThX8u0Ediau2PNFbUmXeMkO+PZQEaJUPvzAWhVG6mU3tMcUBXrfpU MrXpFSy4zg9JESj1uAocp5mEWr0r4wify0mn1yTLTyDC2NzdrigdS3xAxziF8TUFIQg3 2QmYv+SqNmD2ux5yxGZ0tU1WEqvs+MuKUHpd60r7yV+9oU+vf0VgjaW0mmhg4AInJYCL ROVaeobmJGgBTuGedNr1TDF4bEV4tigr6zCMOOKihJIYa+1Y4sc5uzui9jN7QQemjz6s 75KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1ZFNmSY7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si1116057otq.31.2020.02.21.00.24.34; Fri, 21 Feb 2020 00:24:46 -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=1ZFNmSY7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388233AbgBUIXv (ORCPT + 99 others); Fri, 21 Feb 2020 03:23:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:36034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388553AbgBUIXt (ORCPT ); Fri, 21 Feb 2020 03:23:49 -0500 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 2B69A206ED; Fri, 21 Feb 2020 08:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273428; bh=Hr2VUpDssZs1HdNn8uSIML9LTdcNc7YznffUA7zUajE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ZFNmSY7Z8Dnc9FFxKHrKZrNsEQW2j4H3gvH66kzAadtGpVo/lmHfXrGNKCLBu5A2 +URXPGktW7SAkfExsh14ZIEpxz5Dj1EaaAkQkscOn1VmRaG0WtzDdUtoxQ6psuKsiO UvNizGQnFAdAE79Cd7KIMHsypY4CopGpwxR7KJCA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.19 131/191] f2fs: set I_LINKABLE early to avoid wrong access by vfs Date: Fri, 21 Feb 2020 08:41:44 +0100 Message-Id: <20200221072306.555851761@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@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: Jaegeuk Kim [ Upstream commit 5b1dbb082f196278f82b6a15a13848efacb9ff11 ] 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 Signed-off-by: Sasha Levin --- 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 0ace2c2e3de93..4f0cc0c79d1ee 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -769,6 +769,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); @@ -835,6 +836,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; @@ -865,17 +872,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, @@ -883,7 +884,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); @@ -915,7 +916,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) @@ -939,7 +940,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; } } } @@ -958,7 +959,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) @@ -992,15 +992,14 @@ put_out_dir: 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.20.1