Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2928676rwb; Mon, 15 Aug 2022 14:14:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5jp4xOUpZtUoIja4dnua6vU1HgHOEjwHutyMVNsmvYbvMEDAY0YBjjuJiHD4VGBSp82tXT X-Received: by 2002:a17:907:2894:b0:730:df55:b65f with SMTP id em20-20020a170907289400b00730df55b65fmr11272605ejc.138.1660597944497; Mon, 15 Aug 2022 14:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597944; cv=none; d=google.com; s=arc-20160816; b=EJf0t42juiP1b1WWPJK9bB4DQuT65L0pUM84EHLcL3Iy6qoodL7VmZdJj+pJ8wxMv/ 2tJg+PnQwdMLF3etIdaD3G6iuhDzscjOFFRcE/1FmZnm4sZHYbdB7LULE0VCOSY2/fse VEm5A9Fs3zKzVRdVH8EzDg6bEqW+y65TL5JgP9joRIEN1sDU4xQa/1EmU/RTA/iu5nW8 et2Njn2QfZ/t2YB+FZ90YZRWFutIhJCd+Gay545XaXRNZdqYmFemM55FYjlryZtjEPTF GhjqeXKwJIDchUlTHbOGVVoCh3byzrkfH1RNntmEIuaEqEWDFztS4vddLstN2IomnUdw AMHQ== 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=7KLp4/kjF3lFnBnsGwr/j8fnFpfH4ZCw/eoXbJ6MxAI=; b=QHNvPFoxw9FAn1llo2PIk9FzjezTmuqBfKPUSqfQ9QY4KUD06e2WAl8Mk0vPOOvW7h Z+gPsAXn7Gt7wonOQPiORG6je46cfF6hovZk+HAR98KWZ//uszSRMj1ZRIUtRMooiO5U 3738VKrj6s1LPE7MXbN5es2whBW90mv3iN+fpfEDrMLUm1T6yMIHwgzpDZm6rNb0LWDZ q62a7vL2iDbGfTay6thBnqINCmaZvDMp5S6iHOtkd7IwdHCXIzCvutJWqjHpZlxgcXwt ptmFgdYdh1OQsGLs/R7P03KXgQ2XUQFP+XBJCPooNxXkZjo2UM6MNVXgDlr5NkFBrq14 sdqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yOc+c7n5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fi20-20020a056402551400b00443e8428b01si1333798edb.508.2022.08.15.14.11.59; Mon, 15 Aug 2022 14:12:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yOc+c7n5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233561AbiHOS7L (ORCPT + 99 others); Mon, 15 Aug 2022 14:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244916AbiHOS4P (ORCPT ); Mon, 15 Aug 2022 14:56:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEE9E32D95; Mon, 15 Aug 2022 11:30:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5A22F606A1; Mon, 15 Aug 2022 18:30:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32473C433C1; Mon, 15 Aug 2022 18:30:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588240; bh=zm49u6YjALaQGCdWKi28QKevV2pSXaFcAw/nSI9Mu/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yOc+c7n5QdkJkUsxiLIeVNQd77nMTGFgJzUL3ZY21I5cs/s0ZsUN6KbkOd1JHd0Td B5GTjS+hZxrLNN9mFsxoH68AxLqVnsbaFc/cQ0i9zRfysei/qKA6eaOz2CpTRPtIMa 6jP++ozBkwdXz9WLV6xh3gKCGCwA4EGrE5bWRqhQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , "Jason A. Donenfeld" , Al Viro , Sasha Levin Subject: [PATCH 5.15 340/779] fs: check FMODE_LSEEK to control internal pipe splicing Date: Mon, 15 Aug 2022 19:59:44 +0200 Message-Id: <20220815180351.801825867@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason A. Donenfeld [ Upstream commit 97ef77c52b789ec1411d360ed99dca1efe4b2c81 ] The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here. This is an okayish heuristic, but it doesn't totally work. For example, a few chardevs should be spliceable here. And a few regular files shouldn't. This patch fixes this by instead checking whether FMODE_LSEEK is set, which represents decently enough what we need rewinding for when splicing to internal pipes. Fixes: b92ce5589374 ("[PATCH] splice: add direct fd <-> fd splicing support") Cc: Jens Axboe Signed-off-by: Jason A. Donenfeld Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/splice.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 5dbce4dcc1a7..3abcd7fbc9f2 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -814,17 +814,15 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, { struct pipe_inode_info *pipe; long ret, bytes; - umode_t i_mode; size_t len; int i, flags, more; /* - * We require the input being a regular file, as we don't want to - * randomly drop data for eg socket -> socket splicing. Use the - * piped splicing for that! + * We require the input to be seekable, as we don't want to randomly + * drop data for eg socket -> socket splicing. Use the piped splicing + * for that! */ - i_mode = file_inode(in)->i_mode; - if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode))) + if (unlikely(!(in->f_mode & FMODE_LSEEK))) return -EINVAL; /* -- 2.35.1