Thread (79 messages) 79 messages, 7 authors, 2023-04-14
STALE1147d
Revisions (3)
  1. rfc [diff vs current]
  2. v2 current
  3. v3 [diff vs current]

[RFC PATCH v2 17/48] ip, udp: Make sendmsg(MSG_SPLICE_PAGES) copy unspliceable data

From: David Howells <dhowells@redhat.com>
Date: 2023-03-29 14:18:03
Also in: linux-fsdevel, linux-mm, lkml
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

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(+)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 07736da70eab..e4aeaab704c8 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1263,6 +1263,7 @@ static int __ip_append_data(struct sock *sk,
 			struct msghdr *msg = from;
 			struct page *page = NULL, **pages = &page;
 			size_t off;
+			bool put = false;
 
 			copy = iov_iter_extract_pages(&msg->msg_iter, &pages,
 						      copy, 1, 0, &off);
@@ -1271,7 +1272,25 @@ static int __ip_append_data(struct sock *sk,
 				goto error;
 			}
 
+			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) {
+					err = copy ?: -ENOMEM;
+					goto error;
+				}
+				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)
 				goto error;
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help