All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets
@ 2023-06-14  8:04 David Howells
  2023-06-16  5:23 ` Jakub Kicinski
  2023-06-16 19:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: David Howells @ 2023-06-14  8:04 UTC (permalink / raw)
  To: netdev
  Cc: dhowells, syzbot+d8486855ef44506fd675, Willem de Bruijn,
	David Ahern, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Jens Axboe, Matthew Wilcox, linux-kernel

    
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 <dhowells@redhat.com>
Reported-by: syzbot+d8486855ef44506fd675@syzkaller.appspotmail.com
Link: https://lore.kernel.org/r/000000000000ae4cbf05fdeb8349@google.com/
Fixes: 2dc334f1a63a ("splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()")
Tested-by: syzbot+d8486855ef44506fd675@syzkaller.appspotmail.com
cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
cc: David Ahern <dsahern@kernel.org>
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  |    3 ++-
 net/ipv6/ip6_output.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 244fb9365d87..4b39ea99f00b 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -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
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index c722cb881b2d..dd845139882c 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets
  2023-06-14  8:04 [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets David Howells
@ 2023-06-16  5:23 ` Jakub Kicinski
  2023-06-16  8:34   ` Willem de Bruijn
  2023-06-16  9:59   ` David Howells
  2023-06-16 19:00 ` patchwork-bot+netdevbpf
  1 sibling, 2 replies; 5+ messages in thread
From: Jakub Kicinski @ 2023-06-16  5:23 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: David Howells, netdev, syzbot+d8486855ef44506fd675, David Ahern,
	David S. Miller, Eric Dumazet, Paolo Abeni, Jens Axboe,
	Matthew Wilcox, linux-kernel

On Wed, 14 Jun 2023 09:04:16 +0100 David Howells wrote:
> 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.

Willem, looks good?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets
  2023-06-16  5:23 ` Jakub Kicinski
@ 2023-06-16  8:34   ` Willem de Bruijn
  2023-06-16  9:59   ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2023-06-16  8:34 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David Howells, netdev, syzbot+d8486855ef44506fd675, David Ahern,
	David S. Miller, Eric Dumazet, Paolo Abeni, Jens Axboe,
	Matthew Wilcox, linux-kernel

On Fri, Jun 16, 2023 at 7:23 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 14 Jun 2023 09:04:16 +0100 David Howells wrote:
> > 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.
>
> Willem, looks good?

Reviewed-by: Willem de Bruijn <willemb@google.com>

Disabling splicing if not ip_generic_getfrag sounds great to me.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets
  2023-06-16  5:23 ` Jakub Kicinski
  2023-06-16  8:34   ` Willem de Bruijn
@ 2023-06-16  9:59   ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: David Howells @ 2023-06-16  9:59 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: dhowells, Jakub Kicinski, netdev, syzbot+d8486855ef44506fd675,
	David Ahern, David S. Miller, Eric Dumazet, Paolo Abeni,
	Jens Axboe, Matthew Wilcox, linux-kernel

Willem de Bruijn <willemdebruijn.kernel@gmail.com> wrote:

> Disabling splicing if not ip_generic_getfrag sounds 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets
  2023-06-14  8:04 [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets David Howells
  2023-06-16  5:23 ` Jakub Kicinski
@ 2023-06-16 19:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-16 19:00 UTC (permalink / raw)
  To: David Howells
  Cc: netdev, syzbot+d8486855ef44506fd675, willemdebruijn.kernel,
	dsahern, davem, edumazet, kuba, pabeni, axboe, willy,
	linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 14 Jun 2023 09:04:16 +0100 you wrote:
> 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().
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-16 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14  8:04 [PATCH net-next] ip, ip6: Fix splice to raw and ping sockets David Howells
2023-06-16  5:23 ` Jakub Kicinski
2023-06-16  8:34   ` Willem de Bruijn
2023-06-16  9:59   ` David Howells
2023-06-16 19:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.