Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1003416yba; Thu, 4 Apr 2019 02:11:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzK3WlWpouMxlF8GQnoyR+K8VkchmKPRy4DuwzxRQYdjxG9kkYJGKk7VAR+Krv8G/dzXMeb X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr5201644plb.131.1554369069635; Thu, 04 Apr 2019 02:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369069; cv=none; d=google.com; s=arc-20160816; b=0LiHCPNJAEkBdHhCK5jgsP85+xEpK44mhipH0dxOe7snDBZlbFek9JOevt42ipCHpz MrTspucW5KSKnVGoFgtSB1VNY4SnbtfMrsagEzYKGOnKxmVzClRRbLL5yfGE9K4tMxFr 75xIvmBVZvvqBKr0QLXgHMCd21jj+7YKnsnWFLbR+cL1P7H8Fp0967U63WtYz7EH8JMu JXFn5EPGA16GxwmiDR0niO6OD5ipt1J5L77orspCD3QDj0TzGdVOVMpSJIEyUvIC/JzQ 4AiXRaheKBSrfi5ZoO7LfEsecxm104hwaxFR3jI9jLRpJNdqLU9nYggViOMADOhYeX7F cFPQ== 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=fAZ2U2IrxX1qsu4+cIuSn7EX9vziPvl7TzU7xCwM0Yc=; b=DjUUatToa0Yoxc2TIvHJ5P05OJz8PSznHy3NYDpilzMDxtz6a53arS/J0sCS6R1T+z bpfcDnx7VukUyfaPDDEc3YSDWv51p/2Qs0RpR/0/YTbE5AlAAnb99sAIos5qxFHvxhAj j6jSt/cHfU6clZHbYv1G7iQHwhCLJJqnIqVldv2hvdAqQ/05QV5LBAjtYeQHlpEfkCEk jTnL/1ERkMZLFOguekwwiqkNeBrflnbaxIgxO9J5yT2WxFH9GnJ1hxbFivfJ5z8vHiyB n+18Wrgxrd6Bt7tMDz/7QBKwnJyRiz94iUVpFpPzLV7IXzr79Xv5aLhtrfhE8egBU7/8 rIIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=faAs1l2Y; 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 h185si15504062pfc.241.2019.04.04.02.10.54; Thu, 04 Apr 2019 02:11:09 -0700 (PDT) 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=faAs1l2Y; 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 S1732770AbfDDJJG (ORCPT + 99 others); Thu, 4 Apr 2019 05:09:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:48172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728723AbfDDJJC (ORCPT ); Thu, 4 Apr 2019 05:09:02 -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 B74A52054F; Thu, 4 Apr 2019 09:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368941; bh=Hulf+svYeBluasqDKCLFFqURh4CMdy9JBglNQBJlCHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=faAs1l2Yyae8RTmpE28XjHCbeFyo0Lm5c8AomcYH/CRUAi8JPX3NeEH4gs/nIGBx6 qpaYQ69n39DTing6lu2HToWKdnTlEroXcoktKfQHN+dQnyKo6y6s2Qy6TDZvVUtjvX J+nfcaKZ5Msco3/XjOAUp2YbSAdHa97wzLbHBDRs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Zheng Liang , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.0 038/246] f2fs: fix to data block override node segment by mistake Date: Thu, 4 Apr 2019 10:45:38 +0200 Message-Id: <20190404084620.381027246@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit a0770e13c8da83bdb64738c0209ab02dd3cfff8b ] v4: Rearrange the previous three versions. The following scenario could lead to data block override by mistake. TASK A | TASK kworker | TASK B | TASK C | | | open | | | write | | | close | | | | f2fs_write_data_pages | | | f2fs_write_cache_pages | | | f2fs_outplace_write_data | | | f2fs_allocate_data_block (get block in seg S, | | | S is full, and only | | | have this valid data | | | block) | | | allocate_segment | | | locate_dirty_segment (mark S as PRE) | | | f2fs_submit_page_write (submit but is not | | | written on dev) | | unlink | | | iput_final | | | f2fs_drop_inode | | | f2fs_truncate | | | (not evict) | | | | | write_checkpoint | | | flush merged bio but not wait file data writeback | | | set_prefree_as_free (mark S as FREE) | | | | update NODE/DATA | | | allocate_segment (select S) | writeback done | | So we need to guarantee io complete before truncate inode in f2fs_drop_inode. Reviewed-by: Chao Yu Signed-off-by: Zheng Liang Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c46a1d4318d4..93d7427d8883 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -915,6 +915,10 @@ static int f2fs_drop_inode(struct inode *inode) sb_start_intwrite(inode->i_sb); f2fs_i_size_write(inode, 0); + f2fs_submit_merged_write_cond(F2FS_I_SB(inode), + inode, NULL, 0, DATA); + truncate_inode_pages_final(inode->i_mapping); + if (F2FS_HAS_BLOCKS(inode)) f2fs_truncate(inode); -- 2.19.1