Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3458405rwa; Tue, 23 Aug 2022 05:13:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR5iv7NFOIj5VamuXM5fv6xRvhCW0UVFwut0C7xIIhBTSalCR8VPMLbS3NfFVaxY9IB4Slxv X-Received: by 2002:a05:6402:42ca:b0:446:8f11:3b96 with SMTP id i10-20020a05640242ca00b004468f113b96mr3439041edc.353.1661256825652; Tue, 23 Aug 2022 05:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661256825; cv=none; d=google.com; s=arc-20160816; b=gUXkCoUFHcOPUVeK/7OiBQP9BQhgmHyGGlavEJ8RHcJ91S0mjicv8TvAIk+TqzUSyg xnTpY9xyOmQb4e0P0KrGFPC4934gOnvUqgCwCcY7g6Iw59BpcPQCHZXg3M5lpTsePBDy oDYW6BVXyfUuAfsEiXMx7tQnBkjviFpNLm2Ybzn7SFxlLLuunCAqAYiSmd8AYsguxvUl pwzbRWv1M85dFsXZaQ9jHOpb3zCm6PcJTXidOhThdA4dlFrhVo8Pe2tnflMwMnNWM8AM H8mgjWG5yLMvGxq/0p1y3q+SkmDCMMPsdo3za5dOGkaNsC2GW8HOYGgPCXnUTX53vdMt W2kQ== 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=AxxwL3QVB2fhOcdhMldBojOFceKSQsXt03366iDb3FI=; b=FmYVHUsjfyhlqsTQs0uthnDb4ghQAU3QO9qb5i/ji/zh2U7TTlOLB1hF3Mjk03II32 f7fDYqNQZ8YxZ2mCPXA+DA2CY2ltiu22T6XF203kygofj4x4W/5KM690WM8Vdg1VLAyc 34ylv4cz+L/FUZHG2srRAh1NUeELOnmF8GDD4dXCqByRzGa8k4VbRrmS95DHWP2pvpuq KaPrEcTxL+RduzWYSETGdiHgpXVcrXCUyBP6zNzmsF0j4wK897k+LHqsu21Rnso0Vv+E Ygs3eY3vhKaBeckXggNZvg5e+m8hmQlauelf4h43aTiVqvcGeaFUqFLCt8RqEHTdvstc 8bkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nTsmqJ3A; 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 f40-20020a05640232a800b00446ed54c7efsi2104850eda.266.2022.08.23.05.13.20; Tue, 23 Aug 2022 05:13:45 -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=nTsmqJ3A; 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 S1355151AbiHWKjg (ORCPT + 99 others); Tue, 23 Aug 2022 06:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352857AbiHWKXr (ORCPT ); Tue, 23 Aug 2022 06:23:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00DF7832E3; Tue, 23 Aug 2022 02:04:39 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1CD72B8105C; Tue, 23 Aug 2022 09:04:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 758D0C433C1; Tue, 23 Aug 2022 09:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245476; bh=M0pBvuUrXO6gcVio/ZNcbGY7XiS3JfWArod8klC12M0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nTsmqJ3AGGyQg3Kg514YE6q0yhO/7FZhG3n54lSd3G/HiDm5xB3mKcbYzpzsThlUj +/poIydguYjauGVRtDPlnuwbrsgUQdbme7wXtZH3PzIpM4PRUR9wJL+8Ex5sa2oaBA 1CjMGBE5zCdExoO6a1TVt6/KCI+ADbWvjisUhAKk= 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 4.19 090/287] fs: check FMODE_LSEEK to control internal pipe splicing Date: Tue, 23 Aug 2022 10:24:19 +0200 Message-Id: <20220823080103.337117504@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 fd28c7da3c83..ef1604e307f1 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -899,17 +899,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