Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp297085yba; Mon, 20 May 2019 08:54:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMtpZcpvnG33qe3kF7EmjWblbbj1Lj7rQgUHId1T97DARcHaFAeudE1FXz/KOkguXWkRNN X-Received: by 2002:a63:1d02:: with SMTP id d2mr76534018pgd.26.1558367642181; Mon, 20 May 2019 08:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558367642; cv=none; d=google.com; s=arc-20160816; b=Br5RiF5cGFaevmf2xryPn6YKGo/RTb/SgJ8a8sgulqKr1OxP8BGKF1/KQzE+wgg9qz ahOeFw/twxucu+2R+faoLVuAqBgYMNfsHYt2F41OnnZZuXC08+ErDcWbrHb+46CvEDyR Vweuo/sAn3vcmfo1D+SjrU7UmBJhe3DE1McYZaj7SixPy/s53CKI+6fqP5gPFSJvoU8h lrzTetJ8ofOwE6atfBs3cnLEfg8wYnl6WRiC2TNOqnYxgdEGaxzyjJsRgqRNg5ZqVYLV NkTE9punRIUh8WtcYkQyPDHlC3yDPgMNcH1rFGZzT9QoonQx6ojJBs5HLfXWLYg6qbDU LCoQ== 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=yUg6xwsC4xjYzkFghkKBERp8fpsWPi3yYU1B8GsNp/E=; b=LQ7j0MVJ1iv07fuXaDLPoc6xIG73R7lmH8VrVjLgiJP3FTZdKcke9VVCACu1Ew04Oh mces7syLU9Z2vi2yjaEUhefPz7IQx5bRcPXuWfbYftQKDINq5p8G1Xes0G1SE71w4kfv A6D7id7aR1QRNBdvTqQeijf/Dh9pvJo70eHrz23QGE2fo2K4jROxPuxxJ2krTi/HiUsP nyWi7NhQwxYgEHwQp3kyfj746Z5Qax6/qYApq1GsOKvvo8+DDsjOzhkyuNZMn0kGvjFg 3UkjycuNlX6ogSApoNwJfqfvyk939xGtXsn5R441FSx5LBbyG1FfXYEYLEK8CTZMymN9 XhUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ojQ8q48S; 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 d2si18415806pln.43.2019.05.20.08.53.47; Mon, 20 May 2019 08:54:02 -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=ojQ8q48S; 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 S2388888AbfETMYj (ORCPT + 99 others); Mon, 20 May 2019 08:24:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:39496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388878AbfETMYh (ORCPT ); Mon, 20 May 2019 08:24:37 -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 1FBBF20645; Mon, 20 May 2019 12:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355076; bh=Y8pn0klUBCj5HAGh+Ju8aJxxSJY616eLJ6p9gRpf8b4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ojQ8q48SYqyDsOKPWeRbq2ROy3fh8Stf/0Pwc83Al2ZOjQsmjn0BO0s7ctXA8PIFc eFJi3SDGgQbsEjg6+lD1sPi/5uRqKXKNusUlwow2AHyCA8um1WQUlymQ9L+uxmh4Ym oQ3XlVEhvD712vzZXqpQ1wz4o+ZPuQhc6bCtsvNI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Czerner , Theodore Tso , stable@kernel.org Subject: [PATCH 4.19 086/105] ext4: fix data corruption caused by overlapping unaligned and aligned IO Date: Mon, 20 May 2019 14:14:32 +0200 Message-Id: <20190520115253.212480888@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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: Lukas Czerner commit 57a0da28ced8707cb9f79f071a016b9d005caf5a upstream. Unaligned AIO must be serialized because the zeroing of partial blocks of unaligned AIO can result in data corruption in case it's overlapping another in flight IO. Currently we wait for all unwritten extents before we submit unaligned AIO which protects data in case of unaligned AIO is following overlapping IO. However if a unaligned AIO is followed by overlapping aligned AIO we can still end up corrupting data. To fix this, we must make sure that the unaligned AIO is the only IO in flight by waiting for unwritten extents conversion not just before the IO submission, but right after it as well. This problem can be reproduced by xfstest generic/538 Signed-off-by: Lukas Czerner Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/file.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -264,6 +264,13 @@ ext4_file_write_iter(struct kiocb *iocb, } ret = __generic_file_write_iter(iocb, from); + /* + * Unaligned direct AIO must be the only IO in flight. Otherwise + * overlapping aligned IO after unaligned might result in data + * corruption. + */ + if (ret == -EIOCBQUEUED && unaligned_aio) + ext4_unwritten_wait(inode); inode_unlock(inode); if (ret > 0)