Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp11208ybm; Mon, 20 May 2019 10:58:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4ETR8BXteKzw3ODCAVnoZXXxfJPQrY8ulnPJqzft3uQS9ajIHF3xXmLXhpMBJl7QMqG43 X-Received: by 2002:a65:5347:: with SMTP id w7mr20784431pgr.375.1558375131110; Mon, 20 May 2019 10:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558375131; cv=none; d=google.com; s=arc-20160816; b=LQDm3eCvNsXFfLis5I2qSsCnMsqRh/mTjPC3YUB/zx4fcbN7hiOysxk4JDG3s6tZa3 X4cDQym2ezRQLmoVQGOsl83NgOtazWUVoMDHg5g/AEzWtYXPdxMNnZgyj6qmxjVtGR2O U57Wc7Wqo2Mwmzi4RTNIzjPIv673pjmiscbDCpVUXJEHTHRqT0LBaJay4mCHECYHiLe5 JKsEGv4KCfQsOgGk4kus2lSGoEXdxbkHz6O10ryPKyanesPH5kq9IhBj1Wyy0GCDXyas 97XN9GFALjeflKNImQCz2coiCwzvoyEZqM8CqRFXO6xuL2qQc0a04WaxAsqUTparWkeZ gkuA== 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=VaCmbpIBTItq9/fk4euq755oE/u9TuNCYSmcJNaTaRo=; b=jep4CzXiHxLPjgXvrrjOSoZqhSCgC7f3GEl3CD/rk2ac2gDqIUO4JbvruD6reXJCsm tAN5VshCRGn+gkbFKqiyk5Kj/9D0iDjhI9jfU5zwVIMZ0V1vY2aypcN2BRLLEtd76GXh G1WJmY5Op8LJpX75e3UbEpQSEUIFFjVbATsempxETQCulVbSssE8TJjglpwfTIOegp+E pkBKgGrzGzjgAiK6fLfYLIiOeki7p5cUOPfjuZ109UT0Qi82DICOia3eb1WIgAI2bCaq HqknDwUz0vVmHWrZBvhf08EhRxkBQSZ3hUSI1L2v+43E4TGQPeva+je7p80wz/xI8zmH xuuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uF8kx5Bd; 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 h4si13238388plr.24.2019.05.20.10.58.36; Mon, 20 May 2019 10:58:51 -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=uF8kx5Bd; 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 S2391468AbfETMuc (ORCPT + 99 others); Mon, 20 May 2019 08:50:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:34262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732569AbfETMUr (ORCPT ); Mon, 20 May 2019 08:20:47 -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 A2AE2214AE; Mon, 20 May 2019 12:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354847; bh=QOAseeH2yv1IQXokjrSetFhF2bK4kHRU9OJPRZHBuFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uF8kx5BdhNRLEy8v8Qo5bdy9B3td8z1MIlytRqz9buS2f0hGeQskf4Fr4fraH/Q0o aH3WvwFpn3sfsgEmMyGa5K33KT4eEDL44AZsIGfIck0P/p1rE7ALKNI+3a9ZxuKSfh 1iZS9t0q7HOVle1Uni0g0ZeFMH/zo5ehscCPbikg= 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.14 58/63] ext4: fix data corruption caused by overlapping unaligned and aligned IO Date: Mon, 20 May 2019 14:14:37 +0200 Message-Id: <20190520115237.335124529@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115231.137981521@linuxfoundation.org> References: <20190520115231.137981521@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 @@ -262,6 +262,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)