Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp280009ybi; Wed, 29 May 2019 21:16:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxj65ENjsLz9Ylv8pMHqRD/QxNsQysr1TWdUaItF0Gs4u+6Y0/EUR746XGy4Bv9+B1XSyGp X-Received: by 2002:a63:b706:: with SMTP id t6mr1900614pgf.305.1559189803320; Wed, 29 May 2019 21:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189803; cv=none; d=google.com; s=arc-20160816; b=TvPhMv1Z4h+90/iClgjauZegNaNjeDMi8OnkWMeStVTwhMvweSjchARSt7vk/KrsQc Osp/oI/N7yif5rD5448On6Gd4CKrrmjDDVbxZ0exABRdN56kG3QanBeXJ33wvC9t5LDT P3tUsMc8HyhoHpGh5fyOkVDkny7bli+xyipsfNhlO9E4yeRW3i5gQUCh7JdAqOHvlHuR fEpyYBUHxLKpXlFmJwF4fMcXrQxEiI6Rn514fOJQKBZb0QFg8g1zA5YdzxsudNhvqptl 9Xg33g21b+El3AExfHz1xgpabRKuLKBPQP1BLSpO5JqRlCC63KHvLXZ1ADS31p6AdnOG GhGg== 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=IrJWS9DyQ3XyTF/PJ/IYuqpUs8KDzmPMFLAWTFdTO24=; b=wbVDZD9Ye86tIAru80YKqeOi/tf4in0Poa6MtVticm8C9QMiROxkCYt/ciOCpDF4O2 gfLpkiutTOW+l1QoyD+zVq45XA+s44ez6gkPSY63sSU9ziwFMUUHVRUmY+5s9PuyjbcR 15i1LmVWxe5kfNAhf8b6AJpTUneUiFu7iSQ0eFBeoliDKA92tNlB5tmp0SppOXKBf+dY jBWNH/NrPmaB1F/YVnGWT9udfzMYhEc06O74yIuswP8Aa4T/LKio/I3CpoLXatYB8OTC eWe7RcDGTz1hCBuQjrH4tBjURcDF1zchED5VB2EecUr8+Ec2yW7Utze2GdDRRuqSNIc8 M7Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZXlM3soM; 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 o128si2027421pgo.51.2019.05.29.21.16.27; Wed, 29 May 2019 21:16:43 -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=ZXlM3soM; 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 S1730921AbfE3EOZ (ORCPT + 99 others); Thu, 30 May 2019 00:14:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:41614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730618AbfE3DQM (ORCPT ); Wed, 29 May 2019 23:16:12 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 0B056245D8; Thu, 30 May 2019 03:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186172; bh=uP0wVDJZ21vTACQut16rItjPR0xwaJ5+3qdiC+JLdQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZXlM3soM0MbzOvRcEbxIk8S/vcLPunTliJHaAdPv1BPLwxCg7Plyc0hAukmaErOX3 ICvk7/sV9ZmHKZ/u6vjCabNzIbGKood7zx2HLhG2JOt4em/EjybSas7bO37Voui3/R tKOPUTQl0UbN+F9j9UIabevmHuPBBNK5zf7UUaPg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ira Weiny , Jan Kara , Theodore Tso Subject: [PATCH 4.19 003/276] ext4: wait for outstanding dio during truncate in nojournal mode Date: Wed, 29 May 2019 20:02:41 -0700 Message-Id: <20190530030523.634560870@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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: Jan Kara commit 82a25b027ca48d7ef197295846b352345853dfa8 upstream. 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") Reviewed-by: Ira Weiny Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5601,20 +5601,17 @@ int ext4_setattr(struct dentry *dentry, 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);