Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3699526ybv; Mon, 10 Feb 2020 04:57:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzOFTKjtvwvEEpVI3LjSRNVcpDwiOmB4MQ0Zu6TSi8ESdipU6lWAnan25oJvNuRUDnxEslM X-Received: by 2002:aca:1108:: with SMTP id 8mr723157oir.127.1581339453814; Mon, 10 Feb 2020 04:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339453; cv=none; d=google.com; s=arc-20160816; b=P1MnEI32lxFLC2Ukr0bRV2ob4fTr1vP0HWInFb8xT4DubQzAcxW4PBaGnxu/WgjV6k R/1qPJ/v6g0yMp4HIhPXzteBCZ/G65CO1BoalnNgciSP9kaSpZnsvK70X5ba0jP7JEmT 3pLZ/6YwJg22Dj0A2DHr3sxwMbrWvFAAhXYxoiMz0kHn6AGa2LMciKqpLCmf3U5GRQ2d knwEEMP62BHS+5QalHBZ9dgMu6n9qBtwH5Rqpi2H62yMPSOsXI5PwaQ4G5ALJPC9eRAc 3DJzGX6wOW4nIoCfeWF/Trudy2+07N4QD21cI81hvNHVW2BqekwFNPvme9Ku9XRaFQ1c oS+g== 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=3dSWlwFS1xR/T+kT8294Qp+gnFVwRANsOs+vktjU3ak=; b=q0AypK17bqKhzgqLSxQR7P4drBOAx5TnpsodgOTfDOwxVdg4Va4CTbQamox7tJgdH4 kvfpo7iCW/RyZpxJVDzS4nSlt+MIkz0+DAt8EXhqkdBFMW2j49JwcDAjbetdzDpj2FZM RMDqNjVLxsfcxnlsrigvhnn3mlUtm1HAFGtiggsqfsBok4bNmpEmGWs9XlP1trXWGnFf JtJR5tSgrJL2rfx11xGx6HvJ+AJ/Mibtv3CAh+DUrIrJWx6W9C8DPLe5fBfwSbleNjSH 0N5bOK66Fq/W8ar7UYWREeNyw8B429ZUdR3FkfKDbIWvnENMSQEi4N/0HkOP1ikyaq8H w/dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FgFN02/o"; 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 z20si136554oib.26.2020.02.10.04.57.21; Mon, 10 Feb 2020 04:57:33 -0800 (PST) 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="FgFN02/o"; 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 S1729306AbgBJM5S (ORCPT + 99 others); Mon, 10 Feb 2020 07:57:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:43970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728654AbgBJMlb (ORCPT ); Mon, 10 Feb 2020 07:41:31 -0500 Received: from localhost (unknown [209.37.97.194]) (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 6044620838; Mon, 10 Feb 2020 12:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338491; bh=t8k9Q5kSvPI0BJMlh67Q6NDygDBgDn1hjsy20lgJwd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FgFN02/oxT+7knIIEFZokAmwYiVK7WGoxDlbyNCVpNaSelHBrDkQ3B3WFpL12TmpM F0tllP7ymaFyLqXr0xXxsM45nKPet0SbAGRMwZDSJtpbOTC4Ev0qeXPmKTM3hpYvfU MGAnoGsbu5nHiKY7NsZvs1mbN32dB7iPDnUwjHo4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Geis , Al Viro , Miklos Szeredi Subject: [PATCH 5.5 276/367] fix up iter on short count in fuse_direct_io() Date: Mon, 10 Feb 2020 04:33:09 -0800 Message-Id: <20200210122449.640311198@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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: Miklos Szeredi commit f658adeea45e430a24c7a157c3d5448925ac2038 upstream. fuse_direct_io() can end up advancing the iterator by more than the amount of data read or written. This case is handled by the generic code if going through ->direct_IO(), but not in the FOPEN_DIRECT_IO case. Fix by reverting the extra bytes from the iterator in case of error or a short count. To test: install lxcfs, then the following testcase int fd = open("/var/lib/lxcfs/proc/uptime", O_RDONLY); sendfile(1, fd, NULL, 16777216); sendfile(1, fd, NULL, 16777216); will spew WARN_ON() in iov_iter_pipe(). Reported-by: Peter Geis Reported-by: Al Viro Fixes: 3c3db095b68c ("fuse: use iov_iter based generic splice helpers") Cc: # v5.1 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1465,6 +1465,7 @@ ssize_t fuse_direct_io(struct fuse_io_pr } ia = NULL; if (nres < 0) { + iov_iter_revert(iter, nbytes); err = nres; break; } @@ -1473,8 +1474,10 @@ ssize_t fuse_direct_io(struct fuse_io_pr count -= nres; res += nres; pos += nres; - if (nres != nbytes) + if (nres != nbytes) { + iov_iter_revert(iter, nbytes - nres); break; + } if (count) { max_pages = iov_iter_npages(iter, fc->max_pages); ia = fuse_io_alloc(io, max_pages);