Received: by 10.192.165.148 with SMTP id m20csp2445512imm; Sun, 22 Apr 2018 07:13:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+h8xs5JiYRCPqidqVIBxp5cYtqoRY9icQUvjdb2FVPy3Fed+tOpd0BRMB/P79wX39RUt8Y X-Received: by 10.98.213.8 with SMTP id d8mr11943158pfg.234.1524406429457; Sun, 22 Apr 2018 07:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406429; cv=none; d=google.com; s=arc-20160816; b=FNb6lFUtnTVL1TQJDl4P7AXnIvB+RUi+WwRWs4nHfCI2U+7BIdW/WxHpNDGtNqs/yB iJvaiWCLGty/MEdwmg7xlp6NQneXpxJumfoGgwjdQ89/LOCtcKfaiu3zu2vfOoYqZYFG 5ULikkv5ycQM2vtlpj0sC3CDYvKlq3Tu8chXsg5vHVdCwsEccw5lsHHdlnVgF6avznSJ mPUpfRrf9liFeYm76oYXoP5p/lH0Td1fE92xY2TC7UcbD+dFVxsO9dpCmPGAvIb5OtoR ISUKM2Rp6kRZRvON7t1VtVjbEs6392HCC/OamkLtNW7qm5dUzQ0oOA3Z2zY/kPbnn7QF nHXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GVYRq4++jxyZ6OJmAv4CQvgZ+w4lPS4hk7lgBZ3DBu8=; b=N2bY1d1p9RLHUGWxTjYIuXlF4UNo1/ij8TAIRFaPQdpX1xr6M4OHGXasxUKD+ISIKR Lt8gh66ONrb9KNCSTTqWntVark9IDHKK4lbWMwuJJ+fQZjBZ3pLKkvJ4BQKPOlCqoijQ LSHoV4pdHC7PZzMnimy67A1+In2RubIkOOEv91VDoBGuVo1da+rhfRCRxhuqDbPFD0LO ZXuBh/ANfst+PKac4zL7TDDAp9uL4lUvR6E+DRvqu1s07UVxjkNrt8G8MCigDVgn3MGD XPvKht6zz7Hr9H64/4N2mrnKxcg0Vyjatm9hX0JnpGAHLk99pxfdTU8rcNgyqyoIbsbM wRMg== ARC-Authentication-Results: i=1; mx.google.com; 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 u9si9550917pfa.293.2018.04.22.07.13.35; Sun, 22 Apr 2018 07:13:49 -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; 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 S1756700AbeDVOMd (ORCPT + 99 others); Sun, 22 Apr 2018 10:12:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54990 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756624AbeDVOMU (ORCPT ); Sun, 22 Apr 2018 10:12:20 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3BB1FC27; Sun, 22 Apr 2018 14:12:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Eryu Guan , Theodore Tso Subject: [PATCH 4.9 36/95] ext4: protect i_disksize update by i_data_sem in direct write path Date: Sun, 22 Apr 2018 15:53:05 +0200 Message-Id: <20180422135211.902450766@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eryu Guan commit 73fdad00b208b139cf43f3163fbc0f67e4c6047c upstream. i_disksize update should be protected by i_data_sem, by either taking the lock explicitly or by using ext4_update_i_disksize() helper. But the i_disksize updates in ext4_direct_IO_write() are not protected at all, which may be racing with i_disksize updates in writeback path in delalloc buffer write path. This is found by code inspection, and I didn't hit any i_disksize corruption due to this bug. Thanks to Jan Kara for catching this bug and suggesting the fix! Reported-by: Jan Kara Suggested-by: Jan Kara Signed-off-by: Eryu Guan Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3396,7 +3396,6 @@ static ssize_t ext4_direct_IO_write(stru { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct ext4_inode_info *ei = EXT4_I(inode); ssize_t ret; loff_t offset = iocb->ki_pos; size_t count = iov_iter_count(iter); @@ -3420,7 +3419,7 @@ static ssize_t ext4_direct_IO_write(stru goto out; } orphan = 1; - ei->i_disksize = inode->i_size; + ext4_update_i_disksize(inode, inode->i_size); ext4_journal_stop(handle); } @@ -3548,7 +3547,7 @@ static ssize_t ext4_direct_IO_write(stru if (ret > 0) { loff_t end = offset + ret; if (end > inode->i_size) { - ei->i_disksize = end; + ext4_update_i_disksize(inode, end); i_size_write(inode, end); /* * We're going to return a positive `ret'