Received: by 10.192.165.148 with SMTP id m20csp2453665imm; Sun, 22 Apr 2018 07:22:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IkHvdPQvLH5JDduxn6702TSMjglU9s2wdfC9mW4JXPH+tPmLrsXLCcPSJcgMSWB0LjOf1 X-Received: by 10.101.77.198 with SMTP id q6mr14489071pgt.61.1524406941793; Sun, 22 Apr 2018 07:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406941; cv=none; d=google.com; s=arc-20160816; b=drbUH7dr9DpmhkcHPlgUkDBBZS3ffRpVTWS0pHoDi7eUxV18wAwgk+d4lAFeBdnxKx z9uCtqDl9Qurr/lLA996OEE58dycQRxekoEJ8oMkuanPquTgHPsGpIHPt6TeCuJD7Q4Q cpqRwV1CZSaOquodxw5aqDzDBiGDXdAmDQx9/kruEDLOcWlK5P7f6HE9eZbA37R+3Rkg GKz5Z6i2CuWxcxuCJTFwcWlH3cX88cFye5BHPViDyhzc9f11L48nQv81T5+rXo/AWYUT 5Nd4ThLxuqrtKrr0GfRDUuLd1sPJPmzqNh5Aw8eoc+bIjx0GDokOFSm8WScdEkMi5VlW gCAA== 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=f0VGSEOtkZ/kuuHkRfcG3VeuzphAhV/ZmoSdQ/u4LaA=; b=Vf0YLaCjq94Ngm7vcbwat83pjYdKTtyFjxON3iLJ+9xnFL0Rz6Kso9kOoHwhIJkAYO dvVNC+Uq+97zIzhVpfKE817XC1+WLsLG0os9RsCW6XEyNqDWPm7zDl6Gex9K7UF+fE1c DZoLAYPwE7OwvO0snencD/lFty0tJS6on36HOPYFzOKuipvROHyWDW+MU/O3axZrc/hH d1zQB/DRs1RVaVgTx8+aeti8ZAXNnsZ58Ap364OxrH+vxR4BvNIrHSnjxVv2x30es+Vs qdMtQgFMHYg4t+GRKDyLnZ9u/j08PSKyGsKRkV92W1LmQkNkczYdpUuD8cePMxMmtn86 dprA== 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.22.07; Sun, 22 Apr 2018 07:22:21 -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 S1757317AbeDVOTt (ORCPT + 99 others); Sun, 22 Apr 2018 10:19:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59900 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757264AbeDVOTn (ORCPT ); Sun, 22 Apr 2018 10:19:43 -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 D59C215; Sun, 22 Apr 2018 14:19:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Theodore Tso , Nathan Chancellor Subject: [PATCH 4.4 76/97] ext4: fix crashes in dioread_nolock mode Date: Sun, 22 Apr 2018 15:53:54 +0200 Message-Id: <20180422135309.388978783@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 74dae4278546b897eb81784fdfcce872ddd8b2b8 upstream. Competing overwrite DIO in dioread_nolock mode will just overwrite pointer to io_end in the inode. This may result in data corruption or extent conversion happening from IO completion interrupt because we don't properly set buffer_defer_completion() when unlocked DIO races with locked DIO to unwritten extent. Since unlocked DIO doesn't need io_end for anything, just avoid allocating it and corrupting pointer from inode for locked DIO. A cleaner fix would be to avoid these games with io_end pointer from the inode but that requires more intrusive changes so we leave that for later. Cc: stable@vger.kernel.org Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Nathan Chancellor Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3256,29 +3256,29 @@ static ssize_t ext4_ext_direct_IO(struct * case, we allocate an io_end structure to hook to the iocb. */ iocb->private = NULL; - ext4_inode_aio_set(inode, NULL); - if (!is_sync_kiocb(iocb)) { - io_end = ext4_init_io_end(inode, GFP_NOFS); - if (!io_end) { - ret = -ENOMEM; - goto retake_lock; - } - /* - * Grab reference for DIO. Will be dropped in ext4_end_io_dio() - */ - iocb->private = ext4_get_io_end(io_end); - /* - * we save the io structure for current async direct - * IO, so that later ext4_map_blocks() could flag the - * io structure whether there is a unwritten extents - * needs to be converted when IO is completed. - */ - ext4_inode_aio_set(inode, io_end); - } - if (overwrite) { get_block_func = ext4_get_block_write_nolock; } else { + ext4_inode_aio_set(inode, NULL); + if (!is_sync_kiocb(iocb)) { + io_end = ext4_init_io_end(inode, GFP_NOFS); + if (!io_end) { + ret = -ENOMEM; + goto retake_lock; + } + /* + * Grab reference for DIO. Will be dropped in + * ext4_end_io_dio() + */ + iocb->private = ext4_get_io_end(io_end); + /* + * we save the io structure for current async direct + * IO, so that later ext4_map_blocks() could flag the + * io structure whether there is a unwritten extents + * needs to be converted when IO is completed. + */ + ext4_inode_aio_set(inode, io_end); + } get_block_func = ext4_get_block_write; dio_flags = DIO_LOCKING; }