ip, ip6: Fix splice to raw and ping sockets
Subsystems (3)
PATCH 1/1 ip, ip6: Fix splice to raw and ping sockets
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.
--- net/ipv4/ip_output.c | 3 ++- net/ipv6/ip6_output.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +2 -1
@@ -1040,7 +1040,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
net/ipv6/ip6_output.c +2 -1
@@ -1592,7 +1592,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
Jakub Kicinski
maintainerQuoted 9 lines · On Wed, 14 Jun 2023 09:04:16 +0100 David Howells wrote:
Splicing to
SOCK_RAWsockets may setMSG_SPLICE_PAGES, but in such a case,__ip_append_data()will callskb_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 araw_frag_vecstruct andraw_getfrag()will be the frag-getting function. A similar issue may occur withrawv6_sendmsg().
Quoted 7 lines
Fix this by ignoring
MSG_SPLICE_PAGESif getfrag !=ip_generic_getfragasip_generic_getfrag()expects "from" to be a msghdr*, but the other getfrags don't. Note that this will preventMSG_SPLICE_PAGESfrom 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.
Willem, looks good?
Willem de Bruijn
Reviewed-byQuoted 16 lines · Jakub Kicinski
Quoted 14 lines · On Wed, 14 Jun 2023 09:04:16 +0100 David Howells wrote:
Splicing to
SOCK_RAWsockets may setMSG_SPLICE_PAGES, but in such a case,__ip_append_data()will callskb_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 araw_frag_vecstruct andraw_getfrag()will be the frag-getting function. A similar issue may occur withrawv6_sendmsg().Fix this by ignoring
MSG_SPLICE_PAGESif getfrag !=ip_generic_getfragasip_generic_getfrag()expects "from" to be a msghdr*, but the other getfrags don't. Note that this will preventMSG_SPLICE_PAGESfrom being effective for udplite.
Quoted 4 lines
Quoted 2 lines
This likely affects ping sockets too. udplite looks like it should be okay as it expects "from" to be a msghdr.
Willem, looks good?
Disabling splicing if not ip_generic_getfrag sounds great to me.
Quoted 1 line · Willem de Bruijn
Disabling splicing if not
ip_generic_getfragsounds great to me.
I have a patch in the works that passes msghdr through getfrag that allows this to work if we definitely want to splice into raw and icmp sockets.
David
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 14 Jun 2023 09:04:16 +0100 you wrote:
Splicing to
SOCK_RAWsockets may setMSG_SPLICE_PAGES, but in such a case,__ip_append_data()will callskb_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 araw_frag_vecstruct andraw_getfrag()will be the frag-getting function. A similar issue may occur withrawv6_sendmsg().[...]
Here is the summary with links:
- [net-next] ip, ip6: Fix splice to raw and ping sockets
https://git.kernel.org/netdev/net-next/c/5a6f6873606e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html