From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3729FC43603 for ; Wed, 11 Dec 2019 15:11:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F360A22B48 for ; Wed, 11 Dec 2019 15:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077076; bh=npnDyANGudtfyjzeUNt85NO+xvI9VzCqSiWB+t0mvG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JcU9fW62/Kl9EkIe9LfrlZQI6yPSHSyAvTBQpt3OgOYDUMGSSiEmh6tYJbi0DxTZw NSv9fnfN/0s+d9PX9fN7XuS8WaKo/tlI/2iBhn24DJ3eGsHUjbBv5d/rb5vFEZLFkg ikm4SKc52+c+YEFUThSpCN6AReEPSSxgHHIjHThw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729999AbfLKPLP (ORCPT ); Wed, 11 Dec 2019 10:11:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:59720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730264AbfLKPLM (ORCPT ); Wed, 11 Dec 2019 10:11:12 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C62A424654; Wed, 11 Dec 2019 15:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077071; bh=npnDyANGudtfyjzeUNt85NO+xvI9VzCqSiWB+t0mvG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0kjaIGC+2xENpTluVEnpXTgTvBpK8GPmZqiRc1opFhTFTqr3YlSIx+5tUGDSPx0Sm KBP/6RSPaXNyqVuwmz3z5ImNN8ZMaz5hdymmU4HUiji54AP8tH/H5jZLNt/uoXpnpa fAvpvfeyMrQtWjC7rsXx5cQyBt1ez4ns+72b4VpU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+991400e8eba7e00a26e1@syzkaller.appspotmail.com, Jan Kara , "Darrick J. Wong" , Christoph Hellwig Subject: [PATCH 5.4 86/92] iomap: Fix pipe page leakage during splicing Date: Wed, 11 Dec 2019 16:06:17 +0100 Message-Id: <20191211150301.783180819@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.977775294@linuxfoundation.org> References: <20191211150221.977775294@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: Jan Kara commit 419e9c38aa075ed0cd3c13d47e15954b686bcdb6 upstream. When splicing using iomap_dio_rw() to a pipe, we may leak pipe pages because bio_iov_iter_get_pages() records that the pipe will have full extent worth of data however if file size is not block size aligned iomap_dio_rw() returns less than what bio_iov_iter_get_pages() set up and splice code gets confused leaking a pipe page with the file tail. Handle the situation similarly to the old direct IO implementation and revert iter to actually returned read amount which makes iter consistent with value returned from iomap_dio_rw() and thus the splice code is happy. Fixes: ff6a9292e6f6 ("iomap: implement direct I/O") CC: stable@vger.kernel.org Reported-by: syzbot+991400e8eba7e00a26e1@syzkaller.appspotmail.com Signed-off-by: Jan Kara Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Greg Kroah-Hartman --- fs/iomap/direct-io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -497,8 +497,15 @@ iomap_dio_rw(struct kiocb *iocb, struct } pos += ret; - if (iov_iter_rw(iter) == READ && pos >= dio->i_size) + if (iov_iter_rw(iter) == READ && pos >= dio->i_size) { + /* + * We only report that we've read data up to i_size. + * Revert iter to a state corresponding to that as + * some callers (such as splice code) rely on it. + */ + iov_iter_revert(iter, pos - dio->i_size); break; + } } while ((count = iov_iter_count(iter)) > 0); blk_finish_plug(&plug);