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 4B116C00454 for ; Wed, 11 Dec 2019 15:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 211CF222C4 for ; Wed, 11 Dec 2019 15:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077968; bh=i5BGrY1ElwEElS/X7wKf37aj7r/syxINuT+nIDrQYPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iLvhDc82FDmspFeUB2+OyCFH4aiowKGB7mSf4mTCsrMRuYOrC2YN1aYLt5zoFiF25 fPLGu/79n0MnyAFqkSfN7sj9fQ0yWzlVmn+Oz2F8sBVS+xHUGVmlpaOU1l5FtlncJk B0tgGyM0oBFPjl7begNcNjgozGRh3mIDiTJ2L+6c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732928AbfLKP0H (ORCPT ); Wed, 11 Dec 2019 10:26:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:58974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733057AbfLKP0F (ORCPT ); Wed, 11 Dec 2019 10:26:05 -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 C0231222C4; Wed, 11 Dec 2019 15:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077965; bh=i5BGrY1ElwEElS/X7wKf37aj7r/syxINuT+nIDrQYPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=daaeIyrITpVgQJue3l/TMsfVcbTbrmWHY4c0ZVUICXkMNwJujD4ZX84qFj2/X68m0 zcI6WYwHWqGejY4cwcK7KnKGIsoMp1Fp5h49Wy2rsQcgKMHdPCCFeSYb5OhWhXTDMv y2MWPXuQHdQR6mEisHeFiM8OcW6HxP8O7JkMJrHM= 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 4.19 239/243] iomap: Fix pipe page leakage during splicing Date: Wed, 11 Dec 2019 16:06:41 +0100 Message-Id: <20191211150355.471454825@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1913,8 +1913,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);