Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3453401pxk; Mon, 5 Oct 2020 10:01:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/BPxGuD6uzgX4Pts3dD4U7U8br1kWjRzjMGutYH4qvEyRA6OIGkF1S0XtZMXl+mZ5GcWB X-Received: by 2002:aa7:c984:: with SMTP id c4mr647924edt.42.1601917290831; Mon, 05 Oct 2020 10:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601917290; cv=none; d=google.com; s=arc-20160816; b=A596VxhdB8bDKATd1D04Pc52s0O2DJrPEWwRISBZmro0PvaZLADUEMZyAqavMZHnqp hfdYzrcwVMPqlj6ohM2OhqYszNWpXTG7c4TlhJBj+XsS4tuwWa4O9fZH7OBSTeqsm3Ms mS5nhOTuOgni8ipUIunULtsyCX509sWEc50fUA8T2bVURY4aPU6bQKYeo+1Yh/kCKh/j PZJ8SS48BTBjJfbZxT8mioZzJDySzlIVeVMheLJqojNksWRD8+9k2xB1TxEGAaNJQqA6 CD8rZ24to2JvBKYzTqXOU378xv+a7HqvObNuT5o4UItWKW4X6c2ziM6RnoBkTyaRJUcm HrrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6uTWuM8/HYWBaeX6HokjSzqtpsAVRporrBZ8VE/fGKQ=; b=aup1pXA5EnWhE5YgKiBQzMprAnZ8wR1nyRXH3+CqV0zZli0OCUBR0iKPfvSb0ZznyW cTA2SveZb6oxn9K5CRoWl7pVlubfatLewOMleMSmhaylIhhR4By3N4sl3YY+wi+t268J ZNt8E9ZHd13J56HMccojwDNHucMXP92NTddmaF3ghMw4rPNsHJlAJzg+zzNQg35ARz8/ tz8iE4gkpr8P2EAZ9oMl+6hzzW9jPzBrW0jLXNwbn6SalU7G4Hq+5/S/28GbrpIUPuDz QHBd1IsUJnMhUesd8/hEeAs7OO/dAlFtQUXGsx5JX3shCwsZfsHd+Pb3ZES5JqfYcTgV PA0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pddKAzbG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs18si162063ejb.8.2020.10.05.10.01.07; Mon, 05 Oct 2020 10:01:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pddKAzbG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbgJEPk6 (ORCPT + 99 others); Mon, 5 Oct 2020 11:40:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:54664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727521AbgJEP3H (ORCPT ); Mon, 5 Oct 2020 11:29:07 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 8CDA621481; Mon, 5 Oct 2020 15:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601911747; bh=KnfAmQCDLWxrgUP4TjvPtfODWHnIpaoEfhe3KY3zoWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pddKAzbG2mzUjJJQtdJHOAYkGSAdfQfBDrNShX6CdQZLfv2M4iulQwqn14Hv7Bw/Y Kn9xysfoRGvvU8WEX7DydQ8Pdx6CVBSlJGqh/LhEJ2AfSX4CfnAGHTXvy8mtNNqGeV qrMhpfuqQv+y1FRh+EXJRPIREz4BVReTFcNIurh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Al Viro , Sasha Levin Subject: [PATCH 5.4 23/57] fuse: fix the ->direct_IO() treatment of iov_iter Date: Mon, 5 Oct 2020 17:26:35 +0200 Message-Id: <20201005142110.910869859@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201005142109.796046410@linuxfoundation.org> References: <20201005142109.796046410@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro [ Upstream commit 933a3752babcf6513117d5773d2b70782d6ad149 ] the callers rely upon having any iov_iter_truncate() done inside ->direct_IO() countered by iov_iter_reexpand(). Reported-by: Qian Cai Tested-by: Qian Cai Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/fuse/file.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index f8d8a8e34b808..ab4fc1255aca8 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3074,11 +3074,10 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ssize_t ret = 0; struct file *file = iocb->ki_filp; struct fuse_file *ff = file->private_data; - bool async_dio = ff->fc->async_dio; loff_t pos = 0; struct inode *inode; loff_t i_size; - size_t count = iov_iter_count(iter); + size_t count = iov_iter_count(iter), shortened = 0; loff_t offset = iocb->ki_pos; struct fuse_io_priv *io; @@ -3086,17 +3085,9 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) inode = file->f_mapping->host; i_size = i_size_read(inode); - if ((iov_iter_rw(iter) == READ) && (offset > i_size)) + if ((iov_iter_rw(iter) == READ) && (offset >= i_size)) return 0; - /* optimization for short read */ - if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) { - if (offset >= i_size) - return 0; - iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); - count = iov_iter_count(iter); - } - io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); if (!io) return -ENOMEM; @@ -3112,15 +3103,22 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * By default, we want to optimize all I/Os with async request * submission to the client filesystem if supported. */ - io->async = async_dio; + io->async = ff->fc->async_dio; io->iocb = iocb; io->blocking = is_sync_kiocb(iocb); + /* optimization for short read */ + if (io->async && !io->write && offset + count > i_size) { + iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); + shortened = count - iov_iter_count(iter); + count -= shortened; + } + /* * We cannot asynchronously extend the size of a file. * In such case the aio will behave exactly like sync io. */ - if ((offset + count > i_size) && iov_iter_rw(iter) == WRITE) + if ((offset + count > i_size) && io->write) io->blocking = true; if (io->async && io->blocking) { @@ -3138,6 +3136,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) } else { ret = __fuse_direct_read(io, iter, &pos); } + iov_iter_reexpand(iter, iov_iter_count(iter) + shortened); if (io->async) { bool blocking = io->blocking; -- 2.25.1