Received: by 10.192.165.148 with SMTP id m20csp2528239imm; Sun, 22 Apr 2018 08:55:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+PHG6rKyPIT//QH+5RTypuL6PzGQ7CKaNtmDTRQMQNYOfRPbTHqkpYtVSQ5sTt0VNzm1g3 X-Received: by 10.99.53.132 with SMTP id c126mr8430327pga.37.1524412554306; Sun, 22 Apr 2018 08:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524412554; cv=none; d=google.com; s=arc-20160816; b=lcn/Kk72+164RQytSc66ZAyD1rsUkEk4qY0DtQxHJ6HF400fxbFum9NSiJgIQzFWE3 dGfJeI8MaXNYvXionhGtBFLmiRnMEfS/JuOQxMU7BFbSDbaanm2xdxZSHcBoARLMG8Gg Cnve4HyF8RmIHM4hEcpZoaAYWo3GHkNOyjqnofJjqn1qs1rxbZQEwzfcHaSjrdenl72b P1+Beo7WzXB/1WLyXpVMqHj1UsgXquQBv8dyoyzAF9Z+uBwcQu/c/WJXvbnGUy2yx8Hq nMNKhEufdxrDMbQQwLQj6PAC1jdPZfqudcMFcL5U7b47vN4jPOtZez0BS+za2k7d7PNa 3FGg== 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=u8HTTyj2tzazjkZU6pHgYixFODBkixxa6GJ65wQU3R8=; b=iYpbQM9oDE7GCsSWCsoFq78Fy/GANO6Usp3VMG4Z++0vFXJNWcnsZUKS1IUumYhIBP LqftiTjXvjkLbpkC/3YNNEGykqSqbIyLeZvqcDZdu+0S4u91lcagUmVC2vp6mVHfvnqU YevJLYq3dkKdWQIAWuE/ow+4oTGZQIvER0CfouXYNTWl688uPy2nIdep+TfyqLVuEYWQ uknZL6txhnYJszvHLAUsLN67Zj8GmvKHi6jgzDaTcuZqV6o903xBuqnK8NBESrbRNg2P QWgbVGZIo8VAd38pA9k3vuo+7bgfER+9qvsqfDUIDXRqwKPeXOPRznlZUgW0CGi+aGh/ 1yxw== 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 m18si9465571pfi.296.2018.04.22.08.55.40; Sun, 22 Apr 2018 08:55:54 -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 S1754524AbeDVPyk (ORCPT + 99 others); Sun, 22 Apr 2018 11:54:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47112 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754444AbeDVN7w (ORCPT ); Sun, 22 Apr 2018 09:59:52 -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 6EE969C; Sun, 22 Apr 2018 13:59:51 +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.16 089/196] ext4: protect i_disksize update by i_data_sem in direct write path Date: Sun, 22 Apr 2018 15:51:49 +0200 Message-Id: <20180422135108.905407465@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@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.16-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 @@ -3658,7 +3658,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); @@ -3682,7 +3681,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); } @@ -3790,7 +3789,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'