Message ID | b169b3bb105b4691b778ccb991f58853c95d106c.1703126594.git.nabijaczleweli@nabijaczleweli.xyz |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp156958dyi; Wed, 20 Dec 2023 19:12:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmwmoRzSmzdyu1HiWMeNxS/jC4fCg3UqcNGA0bKNhdui+Rj4IaWYZ6Pt5LmCRvpVt3ClTd X-Received: by 2002:a17:906:c143:b0:a1c:4c3e:99e2 with SMTP id dp3-20020a170906c14300b00a1c4c3e99e2mr31053ejc.22.1703128371447; Wed, 20 Dec 2023 19:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703128371; cv=none; d=google.com; s=arc-20160816; b=O6H8NS/gEscHodvuFc3qKYRjAU7n8MFANzHK0OPcqSelyDZ3N4+oOwB21ggQY0RG5Q /h7zI88F8h7qCMmKSre1Ew5bzh9maYIfTMaiJEO32n3IEemnYLiOM2ecXsqoxQi5a3ny /z4huEyc97TnCn4zZBsxhrXBwLPd3faI1/EgCNPCWaG8zlh4G/uIj0socIzxEDog08of 5RYviTe4FE+l/XMmVcdvQVwHi1UAjdMLN0IDf1P6VD59n10dNTc7kFUhfe5ct9dH/oHm DW9sL1kxukwREDTuAOvNWzJBjxpLbqD5tKYP7ef6YBLxYAM3/Hte361LJYWFcjaCFJri 8C0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:from:date:dkim-signature; bh=pZkAeEO1pZbR7A5dFiKcQ9hLeacAhknGGuQ+RSVfkuk=; fh=1Wj/MAh+jnvZF/aMM1lYrKEgLZZd91YUwFaRXMvcDWA=; b=PkdZiQEg74h3PjTcgQ0vpE3g0vvQk7iFQDNvLb1LDeg8auBY/uU210icc+0URexcsy vpuay7OTuMulSYWADPSNqqHFik03+1/c4NnUavxVQfk2S7WZFpPoA7OgDlrzsI93Vq6p Bj6MMeyicX7BEi85mwX+aSg9WdJT9qWgK3dihGsTYne8vQkiPfEbQEijv6evU7yVAiI5 xpXWzBCjOAEYRfCqqkrF61fJGjotB4ymmC3bny7hLyK5t/Sw19QHgv02jq+2G1AIgpUl xGm4P1XtC/jZfdnkcUsgFzd6fTKQ2CRDtDLUyh6xK08vcuztx0radNE+JHb75IwkD9TC PjkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=HINY7x7B; spf=pass (google.com: domain of linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l2-20020a170907914200b00a23382ae4c2si409781ejs.259.2023.12.20.19.12.51 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 19:12:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=HINY7x7B; spf=pass (google.com: domain of linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7785-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E51FF1F21B42 for <ouuuleilei@gmail.com>; Thu, 21 Dec 2023 03:12:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AF45219F4; Thu, 21 Dec 2023 03:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b="HINY7x7B" X-Original-To: linux-kernel@vger.kernel.org Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70CD81802F; Thu, 21 Dec 2023 03:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1703128160; bh=eC4NraofFatu6EgrcpX+Ng78r0bAeuupM1IBexlD5Ys=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=HINY7x7BkBUHP9olDZg9BvZ7avlAArx1U47t/vMBnlm8bvXRPUqPOZGu4BP0calNW +qP5WwTZ7m8A6P0Eq0SomxcbT3bjO6+HGgOP3fN8XBVcWzNmwFOfvjG7Sy7qSkxi95 UdNRo5p0d4TaG+0RL5UoMtpy5b0pXrCyKu3RtpYWkylfBHmzNcSw9W8ZERB9ODPDYR omIHfyZXYy55TAZgy23srefzgvzBFACrKKO/7laPUDUgEnO8pbk/d/MzSRLofYJ8GQ 7GjOD2R6/n3A4BCOHdRplwqDvcVp2EjmqpFuxRRdwcDpkQxflvSW1R2lop763rEJCb C6x+K8LGUIZTw== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id E02471377A; Thu, 21 Dec 2023 04:09:20 +0100 (CET) Date: Thu, 21 Dec 2023 04:09:20 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= <nabijaczleweli@nabijaczleweli.xyz> Cc: Jens Axboe <axboe@kernel.dk>, Christian Brauner <brauner@kernel.org>, Alexander Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/11] splice: splice_to_socket: always request MSG_DONTWAIT Message-ID: <b169b3bb105b4691b778ccb991f58853c95d106c.1703126594.git.nabijaczleweli@nabijaczleweli.xyz> References: <cover.1703126594.git.nabijaczleweli@nabijaczleweli.xyz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7ll6ly7udayb4srv" Content-Disposition: inline In-Reply-To: <cover.1703126594.git.nabijaczleweli@nabijaczleweli.xyz> User-Agent: NeoMutt/20231103-116-3b855e-dirty X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785859535250206241 X-GMAIL-MSGID: 1785859535250206241 |
Series |
Avoid unprivileged splice(file->)/(->socket) pipe exclusion
|
|
Commit Message
Ahelenia Ziemiańska
Dec. 21, 2023, 3:09 a.m. UTC
The pipe is locked at the top of the function, so sock_sendmsg
sleeps for space with the pipe lock held ‒ given:
cat > to_socket.c <<^D
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
int main()
{
int sp[2];
socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, sp);
while(write(sp[1], sp, 1) == 1)
;
fcntl(sp[1], F_SETFL, 0);
for (;;)
splice(0, 0, sp[1], 0, 128 * 1024 * 1024, 0);
}
^D
cc to_socket.c -o to_socket
mkfifo fifo
sleep 10 > fifo &
./to_socket < fifo &
echo zupa > fifo
to_socket used to sleep in splice and the shell used to enter an
uninterruptible sleep in closing the fifo in dup2(10, 1);
now the splice returns -EAGAIN and the whole program completes.
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
fs/splice.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c index 9d29664f23ee..2871c6f9366f 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -869,13 +869,11 @@ ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out, if (!bc) break; - msg.msg_flags = MSG_SPLICE_PAGES; + msg.msg_flags = MSG_SPLICE_PAGES | MSG_DONTWAIT; if (flags & SPLICE_F_MORE) msg.msg_flags |= MSG_MORE; if (remain && pipe_occupancy(pipe->head, tail) > 0) msg.msg_flags |= MSG_MORE; - if (out->f_flags & O_NONBLOCK) - msg.msg_flags |= MSG_DONTWAIT; iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, bc, len - remain);