Skip to content

Commit

Permalink
ip, ip6: Fix splice to raw and ping sockets
Browse files Browse the repository at this point in the history
Splicing to SOCK_RAW sockets may set MSG_SPLICE_PAGES, but in such a case,
__ip_append_data() will call skb_splice_from_iter() to access the 'from'
data, assuming it to point to a msghdr struct with an iter, instead of
using the provided getfrag function to access it.

In the case of raw_sendmsg(), however, this is not the case and 'from' will
point to a raw_frag_vec struct and raw_getfrag() will be the frag-getting
function.  A similar issue may occur with rawv6_sendmsg().

Fix this by ignoring MSG_SPLICE_PAGES if getfrag != ip_generic_getfrag as
ip_generic_getfrag() expects "from" to be a msghdr*, but the other getfrags
don't.  Note that this will prevent MSG_SPLICE_PAGES from being effective
for udplite.

This likely affects ping sockets too.  udplite looks like it should be okay
as it expects "from" to be a msghdr.

Signed-off-by: David Howells <[email protected]>
Reported-by: [email protected]
Link: https://lore.kernel.org/r/[email protected]/
Fixes: 2dc334f ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()")
Tested-by: [email protected]
cc: David Ahern <[email protected]>
cc: Jens Axboe <[email protected]>
cc: Matthew Wilcox <[email protected]>
Reviewed-by: Willem de Bruijn <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
dhowells authored and kuba-moo committed Jun 16, 2023
1 parent c08afcd commit 5a6f687
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,8 @@ static int __ip_append_data(struct sock *sk,
} else if ((flags & MSG_SPLICE_PAGES) && length) {
if (inet->hdrincl)
return -EPERM;
if (rt->dst.dev->features & NETIF_F_SG)
if (rt->dst.dev->features & NETIF_F_SG &&
getfrag == ip_generic_getfrag)
/* We need an empty buffer to attach stuff to */
paged = true;
else
Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,8 @@ static int __ip6_append_data(struct sock *sk,
} else if ((flags & MSG_SPLICE_PAGES) && length) {
if (inet_sk(sk)->hdrincl)
return -EPERM;
if (rt->dst.dev->features & NETIF_F_SG)
if (rt->dst.dev->features & NETIF_F_SG &&
getfrag == ip_generic_getfrag)
/* We need an empty buffer to attach stuff to */
paged = true;
else
Expand Down

0 comments on commit 5a6f687

Please sign in to comment.