Message ID | 20230331160914.1608208-17-dhowells@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B849DC761AF for <linux-mm@archiver.kernel.org>; Fri, 31 Mar 2023 16:10:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 553DE6B008C; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 503726B0092; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CB916B0093; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2D27D6B008C for <linux-mm@kvack.org>; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B86F411A6 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:10:16 +0000 (UTC) X-FDA: 80629680432.13.8D14B2B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 5643E20025 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:10:14 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QB/XkKcw"; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680279014; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t1cUbUkat/Gf1dtGRXqhXt4i30LjR64ymk07qbS2yB8=; b=3w3wKTkkqCqXfBk3Qfymm9mLv4ZUosqnLNAnflwCkW91b24V++jLqLE9xDSdk5S1B6fyLH B3Qvu23K5Fobl3HbfJsVjWaqinsO9txTBs0i1oRd3BuekyjzH30z3Asjn4HbYcKOXAKirj rRs3CCQsIEsOWkypaN4KTCL+KENtrEI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="QB/XkKcw"; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680279014; a=rsa-sha256; cv=none; b=gvApFvEdAdc5wcZ/zgEsXctnFtRN5MTzlAGED0b7RtfpEEwI/dkPN2N1CxlJfvi/Eqeooe 87Ylg54PbvBzPcmb6K5GEPgrdSLK8kQwzuJtm2FAVqdgZYpxbGW3qGRraBdVDo825Au4JJ 4/WgXbxdAr9jd2Bxxfhfpt5IWLxKnRc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t1cUbUkat/Gf1dtGRXqhXt4i30LjR64ymk07qbS2yB8=; b=QB/XkKcwSCmDMDZ89e3D7GLaoPdL6NsXyaot9zQpUUXnILp9IrLDjoxx2vMH++LSH1kn/Y RrHE9JEPBm8z9QZNWsWbFs5Lka9B1iiaPM7mxYDP9dZ+0k0dQyMyjxfgD3lx20dTKTswKc nLjQgimmigJPQtZLugaWiMjNQIPSCKk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-488-2g961z0wNy-7npZvx0P1sg-1; Fri, 31 Mar 2023 12:10:10 -0400 X-MC-Unique: 2g961z0wNy-7npZvx0P1sg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8816185A78B; Fri, 31 Mar 2023 16:10:06 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD6FD1121314; Fri, 31 Mar 2023 16:10:04 +0000 (UTC) From: David Howells <dhowells@redhat.com> To: Matthew Wilcox <willy@infradead.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: David Howells <dhowells@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>, Christoph Hellwig <hch@infradead.org>, Jens Axboe <axboe@kernel.dk>, Jeff Layton <jlayton@kernel.org>, Christian Brauner <brauner@kernel.org>, Chuck Lever III <chuck.lever@oracle.com>, Linus Torvalds <torvalds@linux-foundation.org>, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Willem de Bruijn <willemdebruijn.kernel@gmail.com> Subject: [PATCH v3 16/55] ip, udp: Make sendmsg(MSG_SPLICE_PAGES) copy unspliceable data Date: Fri, 31 Mar 2023 17:08:35 +0100 Message-Id: <20230331160914.1608208-17-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 7trmiqt7y18b4865rsuyy6wpzd5s13qo X-Rspamd-Queue-Id: 5643E20025 X-HE-Tag: 1680279014-139117 X-HE-Meta: U2FsdGVkX194RleDz1fRa+w/tiBOTxlpvEFMGaW2Ov/OFKpq+rnKZyAst0Jf1L4fEcX6VtOmQ0eiUVTLY87hzHZiQElo/Rlb2DnfRmh9i87HQP4ZG3ZxicEKjHB/UyeRnRwLmB6wPsBC7W5yICia6AeOh0ote4W4eXFmYTsv97zlZGzzQgMicTpq1tMn9hkyoBxmCbnoFKJmpCvyV5LFjYz1hQppjsUOmcMhnawXzb56fO7FBxr9RoG3rwLHlnViHLUnp8Igqj2IEl4YwJ4JG/DjaosEaeB/69IQr4wrvd5udvVPt5AVKZhKBlEXsaqMZpov4Cu0K+ZJdRSa5MBE7VJ648xK/4/5QovN/2AHinbxHycZb/fMGsKGm4LxtPUFwlHA8Asr0WtGyTP9Izrn4KbWhZeiUhh1NbWmaENp16s9zg1JHntFfvn0yPnqEEUH28PQ/mRvuNhZwPE/MQBTDzBSbtcZ5NJ+a9/Pu8t9mWLYnGLCgAdWhGrzUVHCLPHSMUCua1UbDWGG2wQ7Z8XaZ3V26BMNdeMAlONOZkv4UwcNLfW2u3jx7jZlTWDCV01+E25Ly69VjrxY8uvFqIwhwg5P+MLqg8NgmXP6E9eCpHpjulfQ8XICql4rZO7Vc6DGE54+0jeDXQkKqKTKw5vgCrZnMfkFbgDcs7gfXLq76Cqu8KSvWg3kJtTEIJTqUf5/wio31aXRKRUP2TNte8VsWYurf/Lnj633kXjvNuxiw2jNjFyHoPouUrAXFMWufVgxh84YuahHUoJyXy+W/XEDmBEMnlabqXZXZPoP7nPSs9P30bGbTg8NF7xPPNXe3sERqLRW98TfxYw6F+N3d6g+P2eMCG9TDyKHAznjnpAMiaQ1fqPTE0YqUNUAhkUToHZ6uvxtnQDngirjxA8WsqWAxOmdu8M5xDq5lka8zSnOAedqLiZghtKJ2McCb1BcApmb1T0bbzsO/9KdCEECwBP uWMj//pQ isA1jnQrD6Jt0ym1kH0VdGsrlBhMJr48G5RNuMKtAyUpyfXzNbXVvAc2/IWXd+BUOZl3dXs7aiLmoWmWEf1sJqwt5GEiZdyedrsQ9wPeD+9PeOtMKRV9ZzzeDfGOq/OPXC5P6aLtA5WeDZtnix8FCIfUhgFlafKRt3uoneLn7AHlf0jydvUvqXsKPW2GuTEpIP0fl+mLIHQ8kiBGMbqLlil8oTQ4UVbZIaOyqbplJ5n6v1SxCDFIl6zywcxUoU89hq6BEh1+Eu+aE+3d/WcD3xkktIyfAvCWy2AOAT9bc+y1Sv9gOAv24SKLwKr1sBqrZ53Ytlj470PlR7q1NEH1QvwYZTX9B6FZ23vBrfVISABC4Qzwc1IaHRFmv8eudDuMo7WaPaK6Wh59XrH+ZsyLFDuwJe9btAFDS3iNP0+9vXhffXoeEKBMU5m/IrqBczlieDwEY9INHMtW9fRgV/2vxHRhvVjYbVUhsWlBVSOZ4QNyIZDdsPbOZvAGZVB/iMRpKHvxHKhtwWcqCbHHuJa6OF3CBng== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> |
Series |
splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES)
|
expand
|
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index e2eaba817c1f..41a954ac9e1a 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1004,13 +1004,32 @@ static int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, struct page *page = NULL, **pages = &page; ssize_t copy = *pcopy; size_t off; + bool put = false; int err; copy = iov_iter_extract_pages(&msg->msg_iter, &pages, copy, 1, 0, &off); if (copy <= 0) return copy ?: -EIO; + if (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, copy, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, copy); + return -ENOMEM; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } + err = skb_append_pagefrags(skb, page, off, copy); + if (put) + put_page(page); if (err < 0) { iov_iter_revert(&msg->msg_iter, copy); return err;
If sendmsg() with MSG_SPLICE_PAGES encounters a page that shouldn't be spliced - a slab page, for instance, or one with a zero count - make __ip_append_data() copy it. Signed-off-by: David Howells <dhowells@redhat.com> cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com> cc: "David S. Miller" <davem@davemloft.net> cc: Eric Dumazet <edumazet@google.com> cc: Jakub Kicinski <kuba@kernel.org> cc: Paolo Abeni <pabeni@redhat.com> cc: Jens Axboe <axboe@kernel.dk> cc: Matthew Wilcox <willy@infradead.org> cc: netdev@vger.kernel.org --- net/ipv4/ip_output.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)