Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3328935rwa; Tue, 23 Aug 2022 02:58:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR5A/LLJQ2P6zYRFq+dsYqqkBRzk/oJKuViRMBFMA9phJBkCSJ1r0y+MNTH+aJ7GPXwnwV8t X-Received: by 2002:a05:6402:716:b0:446:2a40:9138 with SMTP id w22-20020a056402071600b004462a409138mr2912903edx.82.1661248719211; Tue, 23 Aug 2022 02:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248719; cv=none; d=google.com; s=arc-20160816; b=KuBCd48v4t4CoYmuiZ905AyWG/8CGjD0qtfZbgeozBLmemNZsftVV6dDBcfcZmeO/L Pydh//8YF2dJE7aM1TWxEK6Haq/71Lk5lffAjfB3cJZJP/kJvLgwwjKQ6SC/ujDhx0IJ QPX0Ijk1TMYQuN4VqJazsEw4I/AMqtGXzuQq2i2aHYzBVkJrbBhHpeXXgmUMlO9FaS+e zPiE3PkDWesE8egG4lMcGojIk6ZmCGwCjVt2UEOaKBNOx7/wE0xOnorav67q9jwSqgSG A130LSoT+c4q1m/SP7JaQzq4t0B1bydhiJaVyeC6YBrpJ4sDvUxNKdmDKLVs8e6GVgEc zJcQ== 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=aGEG7/fKpaapgut08TMPcmt0BaevC5Hfc04DGzOgSFw=; b=sE4W9Vkx3vl2zK+yzs4GlHjKDjuM/w27JLHWoqSiy7UkG0MeuJO1Og1Z8LmBbzANet 6iLMhbvEV1IE8lb7NNbbI7sfJtVyBwHvrUm65d0nEXeQxI28Q50raQi0ruqYzNKxS7wg xkgVT+vqpR5Aj7Hd9nxPxfeDXL6b0K+9WVd6CrEqn0WC5uAG5iXACHYaLgX+PkVFXACH tgJR9hOg9GG4n4PE2Wzj7ZqAoXrWuSjczBcYzQTYqJC9mqkTb/okT8rks3zO/KxrXvSu bLIdDG8IbkAjuL/VZwbq6WzIlZNJsgZAntU1fpKkOkhOrkyM8CrPz+B6bNgidw/jzxAO 656Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p1DqDv4j; 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 b5-20020a056402084500b00445fba6c607si2162387edz.140.2022.08.23.02.58.13; Tue, 23 Aug 2022 02:58:39 -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=p1DqDv4j; 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 S243827AbiHWJmZ (ORCPT + 99 others); Tue, 23 Aug 2022 05:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351676AbiHWJkB (ORCPT ); Tue, 23 Aug 2022 05:40:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 451BA98C9E; Tue, 23 Aug 2022 01:41:19 -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 55B8861540; Tue, 23 Aug 2022 08:40:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E456C433D6; Tue, 23 Aug 2022 08:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244029; bh=o680fSd5QgG2dGfNBgWcGxeyA9nWVhvUlqlhj7sYoHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1DqDv4j42uJXkt/aSj3FkTEK4SFWS/nbBb1VZiX/1Q0nCXB16iz/YHdyI7Hre+VT Br4ncJWwodvBwNQc0dOxTNu/ON0xdh7wpDg60Kd2R5daVOSWn3G6+rSr8n7kLGLtqK qLqthDCz72z089suhoeM/zC3PMt41qR+hqn+GwQA= 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.14 075/229] fs: check FMODE_LSEEK to control internal pipe splicing Date: Tue, 23 Aug 2022 10:23:56 +0200 Message-Id: <20220823080056.398968527@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 c84ac7e97e21..04d25af25a42 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -898,17 +898,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