Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp645264ybm; Tue, 21 May 2019 00:44:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEbO96kdtk/qnmmRuVa7FmngF7KERIg9Z81+ryUZCMVPIvuki2E9AcxFCWkuEm+Jtf1ndH X-Received: by 2002:a62:570a:: with SMTP id l10mr85635176pfb.151.1558424678238; Tue, 21 May 2019 00:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558424678; cv=none; d=google.com; s=arc-20160816; b=mr21dt6wh0fPNU/jqv6B7m0/p0o7BM6NKShCexJ5vk5oRP8sWG2aNgUU3vXXyOrdm1 ZG1zdw9852ZhGbmrrdyJkLo0ikBUKNGAiZbAwmVwJa+g9dkXOLtg4j9qa03RVjr2QRMW 2uyKzR+f8NgYP5X+9qYjMEvB28hNdF6Omuj1Yo+AkNn+P/+DDOr2IIW1hTAuiNkAjlI1 Fw28f9Prt+AHIahGKs43I+kSSzBDCbmLrBcpeco/e1GWlt8CbRmAMw06Jm66irXsElSk Al/lj2Jbt9AafUcJ25ShmB9BFLwQ415gH67sk2gAZi/6dDU0n5ckVDkb8D8JzijH4TfP Sppw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=z7BDRH2gLtr8hygUJGsVilQ/Uo10eAeAiVn2+/RDRCw=; b=b+e8sm4bUcszqK1HRPHgrvJ/QTtm+7k0j1cqzJEcGruSoJdia6e5VdQ9zoiSFouLfO iD2LiGeo0UxgSYMclyyOqn1+L/kQR2di0S4wARNVbJk8JchZHBe314k5Jky8HTYxeudH AjC3LLvMGoFSm5QJpLhNCRnWRXSm4zOLYbNYmUy0jvQw9c3iDJYmCzhebjo1BpEwBShm xZ5SPwNj6MJ0TmdyNW7iwrWCVKdvMDjy0FKkzLYgo1XkyfA0m0jXiamq/PpycWZSzvI/ XJtoT/z64WQB3XKRv3Qqp/BCDiI4Aos8dD12GOOGGBCogZ1uf85jQ0OwSuxiRrS0LQHF H7Ig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 d16si20662161pfr.229.2019.05.21.00.44.24; Tue, 21 May 2019 00:44:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726028AbfEUHoH (ORCPT + 99 others); Tue, 21 May 2019 03:44:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:37332 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726316AbfEUHoH (ORCPT ); Tue, 21 May 2019 03:44:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DAB55AD12; Tue, 21 May 2019 07:44:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id D0BED1E3C81; Tue, 21 May 2019 09:44:04 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , "Weiny, Ira" , Jan Kara , stable@vger.kernel.org Subject: [PATCH 1/3] ext4: Wait for outstanding dio during truncate in nojournal mode Date: Tue, 21 May 2019 09:43:56 +0200 Message-Id: <20190521074358.17186-2-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190521074358.17186-1-jack@suse.cz> References: <20190521074358.17186-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org We didn't wait for outstanding direct IO during truncate in nojournal mode (as we skip orphan handling in that case). This can lead to fs corruption or stale data exposure if truncate ends up freeing blocks and these get reallocated before direct IO finishes. Fix the condition determining whether the wait is necessary. CC: stable@vger.kernel.org Fixes: 1c9114f9c0f1 ("ext4: serialize unlocked dio reads with truncate") Signed-off-by: Jan Kara --- fs/ext4/inode.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 82298c63ea6d..9bcb7f2b86dd 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5630,20 +5630,17 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) goto err_out; } } - if (!shrink) + if (!shrink) { pagecache_isize_extended(inode, oldsize, inode->i_size); - - /* - * Blocks are going to be removed from the inode. Wait - * for dio in flight. Temporarily disable - * dioread_nolock to prevent livelock. - */ - if (orphan) { - if (!ext4_should_journal_data(inode)) { - inode_dio_wait(inode); - } else - ext4_wait_for_tail_page_commit(inode); + } else { + /* + * Blocks are going to be removed from the inode. Wait + * for dio in flight. + */ + inode_dio_wait(inode); } + if (orphan && ext4_should_journal_data(inode)) + ext4_wait_for_tail_page_commit(inode); down_write(&EXT4_I(inode)->i_mmap_sem); rc = ext4_break_layouts(inode); -- 2.16.4