* [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
@ 2023-08-16 14:21 Eric Dumazet
2023-08-16 14:40 ` Willem de Bruijn
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Eric Dumazet @ 2023-08-16 14:21 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Xin Long,
Marcelo Ricardo Leitner, Willem de Bruijn, Michael S. Tsirkin,
Jason Wang, Xuan Zhuo
One missing check in virtio_net_hdr_to_skb() allowed
syzbot to crash kernels again [1]
Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
because this magic value is used by the kernel.
[1]
general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
__skb_gso_segment+0x339/0x710 net/core/gso.c:124
skb_gso_segment include/net/gso.h:83 [inline]
validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
__dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
dev_queue_xmit include/linux/netdevice.h:3082 [inline]
packet_xmit+0x257/0x380 net/packet/af_packet.c:276
packet_snd net/packet/af_packet.c:3087 [inline]
packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
sock_sendmsg_nosec net/socket.c:727 [inline]
sock_sendmsg+0xd9/0x180 net/socket.c:750
____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
__sys_sendmsg+0x117/0x1e0 net/socket.c:2579
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7ff27cdb34d9
Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Xin Long <lucien.xin@gmail.com>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
include/linux/virtio_net.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index bdf8de2cdd935d31449b78e1b9c67fdcdc537bf2..7b4dd69555e497497460dcf5d72737fe5c09fd53 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -155,6 +155,10 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
if (gso_type & SKB_GSO_UDP)
nh_off -= thlen;
+ /* Kernel has a special handling for GSO_BY_FRAGS. */
+ if (gso_size == GSO_BY_FRAGS)
+ return -EINVAL;
+
/* Too small packets are not really GSO ones. */
if (skb->len - nh_off > gso_size) {
shinfo->gso_size = gso_size;
--
2.41.0.694.ge786442a9b-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
@ 2023-08-16 14:40 ` Willem de Bruijn
2023-08-16 14:54 ` Marcelo Ricardo Leitner
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Willem de Bruijn @ 2023-08-16 14:40 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Xin Long,
Marcelo Ricardo Leitner, Willem de Bruijn, Michael S. Tsirkin,
Jason Wang, Xuan Zhuo
Eric Dumazet wrote:
> One missing check in virtio_net_hdr_to_skb() allowed
> syzbot to crash kernels again [1]
>
> Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> because this magic value is used by the kernel.
>
> [1]
> general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
> <TASK>
> udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> skb_gso_segment include/net/gso.h:83 [inline]
> validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> packet_snd net/packet/af_packet.c:3087 [inline]
> packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> sock_sendmsg_nosec net/socket.c:727 [inline]
> sock_sendmsg+0xd9/0x180 net/socket.c:750
> ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> RIP: 0033:0x7ff27cdb34d9
>
> Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Xin Long <lucien.xin@gmail.com>
> Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
2023-08-16 14:40 ` Willem de Bruijn
@ 2023-08-16 14:54 ` Marcelo Ricardo Leitner
2023-08-17 2:19 ` Xuan Zhuo
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Ricardo Leitner @ 2023-08-16 14:54 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, syzbot, Xin Long, Willem de Bruijn,
Michael S. Tsirkin, Jason Wang, Xuan Zhuo
On Wed, Aug 16, 2023 at 02:21:58PM +0000, Eric Dumazet wrote:
> One missing check in virtio_net_hdr_to_skb() allowed
> syzbot to crash kernels again [1]
>
> Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> because this magic value is used by the kernel.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
2023-08-16 14:40 ` Willem de Bruijn
2023-08-16 14:54 ` Marcelo Ricardo Leitner
@ 2023-08-17 2:19 ` Xuan Zhuo
2023-08-17 6:17 ` Eric Dumazet
2023-08-17 8:54 ` Xuan Zhuo
2023-08-17 19:00 ` patchwork-bot+netdevbpf
4 siblings, 1 reply; 8+ messages in thread
From: Xuan Zhuo @ 2023-08-17 2:19 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Xin Long,
Marcelo Ricardo Leitner, Willem de Bruijn, Michael S. Tsirkin,
Jason Wang, David S . Miller, Jakub Kicinski, Paolo Abeni
On Wed, 16 Aug 2023 14:21:58 +0000, Eric Dumazet <edumazet@google.com> wrote:
> One missing check in virtio_net_hdr_to_skb() allowed
> syzbot to crash kernels again [1]
>
> Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> because this magic value is used by the kernel.
>
> [1]
> general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
> <TASK>
> udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> skb_gso_segment include/net/gso.h:83 [inline]
> validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> packet_snd net/packet/af_packet.c:3087 [inline]
> packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> sock_sendmsg_nosec net/socket.c:727 [inline]
> sock_sendmsg+0xd9/0x180 net/socket.c:750
> ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> RIP: 0033:0x7ff27cdb34d9
>
> Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Xin Long <lucien.xin@gmail.com>
> Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
> include/linux/virtio_net.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index bdf8de2cdd935d31449b78e1b9c67fdcdc537bf2..7b4dd69555e497497460dcf5d72737fe5c09fd53 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -155,6 +155,10 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> if (gso_type & SKB_GSO_UDP)
> nh_off -= thlen;
>
> + /* Kernel has a special handling for GSO_BY_FRAGS. */
> + if (gso_size == GSO_BY_FRAGS)
> + return -EINVAL;
> +
I guess the crash happens when user sends packets via af_packet and gso is set
to GSO_BY_FRAGS by user.
But I wonder is 0xffff also an invalid value on the rx path?
We know that this function virtio_net_hdr_to_skb is also used by the virtio-net
driver on the rx path. This change means that virtio-net devices should not set
gso to 0xffff. But the virtio spec doesn't say that the rx gso value 0xffff is
invalid.
So I think we should not add check in this function.
Thanks
> /* Too small packets are not really GSO ones. */
> if (skb->len - nh_off > gso_size) {
> shinfo->gso_size = gso_size;
> --
> 2.41.0.694.ge786442a9b-goog
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-17 2:19 ` Xuan Zhuo
@ 2023-08-17 6:17 ` Eric Dumazet
2023-08-17 6:48 ` Xuan Zhuo
0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2023-08-17 6:17 UTC (permalink / raw)
To: Xuan Zhuo
Cc: netdev, eric.dumazet, syzbot, Xin Long, Marcelo Ricardo Leitner,
Willem de Bruijn, Michael S. Tsirkin, Jason Wang,
David S . Miller, Jakub Kicinski, Paolo Abeni
On Thu, Aug 17, 2023 at 4:27 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> On Wed, 16 Aug 2023 14:21:58 +0000, Eric Dumazet <edumazet@google.com> wrote:
> > One missing check in virtio_net_hdr_to_skb() allowed
> > syzbot to crash kernels again [1]
> >
> > Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> > because this magic value is used by the kernel.
> >
> > [1]
> > general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> > KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> > CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> > RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> > Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> > RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> > RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> > RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> > RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> > R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> > R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> > FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> > Call Trace:
> > <TASK>
> > udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> > ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> > skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> > __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> > skb_gso_segment include/net/gso.h:83 [inline]
> > validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> > __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> > dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> > packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> > packet_snd net/packet/af_packet.c:3087 [inline]
> > packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> > sock_sendmsg_nosec net/socket.c:727 [inline]
> > sock_sendmsg+0xd9/0x180 net/socket.c:750
> > ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> > ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> > __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> > do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> > do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> > entry_SYSCALL_64_after_hwframe+0x63/0xcd
> > RIP: 0033:0x7ff27cdb34d9
> >
> > Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
> > Reported-by: syzbot <syzkaller@googlegroups.com>
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: Xin Long <lucien.xin@gmail.com>
> > Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > Cc: Willem de Bruijn <willemb@google.com>
> > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > Cc: Jason Wang <jasowang@redhat.com>
> > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> > include/linux/virtio_net.h | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > index bdf8de2cdd935d31449b78e1b9c67fdcdc537bf2..7b4dd69555e497497460dcf5d72737fe5c09fd53 100644
> > --- a/include/linux/virtio_net.h
> > +++ b/include/linux/virtio_net.h
> > @@ -155,6 +155,10 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> > if (gso_type & SKB_GSO_UDP)
> > nh_off -= thlen;
> >
> > + /* Kernel has a special handling for GSO_BY_FRAGS. */
> > + if (gso_size == GSO_BY_FRAGS)
> > + return -EINVAL;
> > +
>
>
> I guess the crash happens when user sends packets via af_packet and gso is set
> to GSO_BY_FRAGS by user.
>
> But I wonder is 0xffff also an invalid value on the rx path?
>
> We know that this function virtio_net_hdr_to_skb is also used by the virtio-net
> driver on the rx path. This change means that virtio-net devices should not set
> gso to 0xffff. But the virtio spec doesn't say that the rx gso value 0xffff is
> invalid.
>
> So I think we should not add check in this function.
I think we do.
Think about it, how gso_size == 0xffff , or even 0xfff0 could be valid ?
We are not going to add more core in core network fast path, for
something that can not happen with kernel stacks.
It is time someone clarifies virtio_specs, because 0xffff is
absolutely a no go, even before blamed commit.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-17 6:17 ` Eric Dumazet
@ 2023-08-17 6:48 ` Xuan Zhuo
0 siblings, 0 replies; 8+ messages in thread
From: Xuan Zhuo @ 2023-08-17 6:48 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, eric.dumazet, syzbot, Xin Long, Marcelo Ricardo Leitner,
Willem de Bruijn, Michael S. Tsirkin, Jason Wang,
David S . Miller, Jakub Kicinski, Paolo Abeni
On Thu, 17 Aug 2023 08:17:55 +0200, Eric Dumazet <edumazet@google.com> wrote:
> On Thu, Aug 17, 2023 at 4:27 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > On Wed, 16 Aug 2023 14:21:58 +0000, Eric Dumazet <edumazet@google.com> wrote:
> > > One missing check in virtio_net_hdr_to_skb() allowed
> > > syzbot to crash kernels again [1]
> > >
> > > Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> > > because this magic value is used by the kernel.
> > >
> > > [1]
> > > general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> > > KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> > > CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> > > RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> > > Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> > > RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> > > RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> > > RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> > > RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> > > R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> > > R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> > > FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> > > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > > CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> > > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> > > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> > > Call Trace:
> > > <TASK>
> > > udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> > > ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> > > skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> > > __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> > > skb_gso_segment include/net/gso.h:83 [inline]
> > > validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> > > __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> > > dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> > > packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> > > packet_snd net/packet/af_packet.c:3087 [inline]
> > > packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> > > sock_sendmsg_nosec net/socket.c:727 [inline]
> > > sock_sendmsg+0xd9/0x180 net/socket.c:750
> > > ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> > > ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> > > __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> > > do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> > > do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> > > entry_SYSCALL_64_after_hwframe+0x63/0xcd
> > > RIP: 0033:0x7ff27cdb34d9
> > >
> > > Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
> > > Reported-by: syzbot <syzkaller@googlegroups.com>
> > > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > > Cc: Xin Long <lucien.xin@gmail.com>
> > > Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > > Cc: Willem de Bruijn <willemb@google.com>
> > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > Cc: Jason Wang <jasowang@redhat.com>
> > > Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > ---
> > > include/linux/virtio_net.h | 4 ++++
> > > 1 file changed, 4 insertions(+)
> > >
> > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > > index bdf8de2cdd935d31449b78e1b9c67fdcdc537bf2..7b4dd69555e497497460dcf5d72737fe5c09fd53 100644
> > > --- a/include/linux/virtio_net.h
> > > +++ b/include/linux/virtio_net.h
> > > @@ -155,6 +155,10 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> > > if (gso_type & SKB_GSO_UDP)
> > > nh_off -= thlen;
> > >
> > > + /* Kernel has a special handling for GSO_BY_FRAGS. */
> > > + if (gso_size == GSO_BY_FRAGS)
> > > + return -EINVAL;
> > > +
> >
> >
> > I guess the crash happens when user sends packets via af_packet and gso is set
> > to GSO_BY_FRAGS by user.
> >
> > But I wonder is 0xffff also an invalid value on the rx path?
> >
> > We know that this function virtio_net_hdr_to_skb is also used by the virtio-net
> > driver on the rx path. This change means that virtio-net devices should not set
> > gso to 0xffff. But the virtio spec doesn't say that the rx gso value 0xffff is
> > invalid.
> >
> > So I think we should not add check in this function.
>
>
> I think we do.
>
> Think about it, how gso_size == 0xffff , or even 0xfff0 could be valid ?
>
> We are not going to add more core in core network fast path, for
> something that can not happen with kernel stacks.
>
> It is time someone clarifies virtio_specs, because 0xffff is
> absolutely a no go, even before blamed commit.
So do you mean there are some limitations for the max value of gso_size?
But the merge mode of the virtio-net can receive big packets.
So what is the limitations?
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
` (2 preceding siblings ...)
2023-08-17 2:19 ` Xuan Zhuo
@ 2023-08-17 8:54 ` Xuan Zhuo
2023-08-17 19:00 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 8+ messages in thread
From: Xuan Zhuo @ 2023-08-17 8:54 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Xin Long,
Marcelo Ricardo Leitner, Willem de Bruijn, Michael S. Tsirkin,
Jason Wang, David S . Miller, Jakub Kicinski, Paolo Abeni
On Wed, 16 Aug 2023 14:21:58 +0000, Eric Dumazet <edumazet@google.com> wrote:
> One missing check in virtio_net_hdr_to_skb() allowed
> syzbot to crash kernels again [1]
>
> Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> because this magic value is used by the kernel.
>
> [1]
> general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
> <TASK>
> udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> skb_gso_segment include/net/gso.h:83 [inline]
> validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> packet_snd net/packet/af_packet.c:3087 [inline]
> packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> sock_sendmsg_nosec net/socket.c:727 [inline]
> sock_sendmsg+0xd9/0x180 net/socket.c:750
> ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> RIP: 0033:0x7ff27cdb34d9
>
> Fixes: 3953c46c3ac7 ("sk_buff: allow segmenting based on frag sizes")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Xin Long <lucien.xin@gmail.com>
> Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Thanks.
> ---
> include/linux/virtio_net.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> index bdf8de2cdd935d31449b78e1b9c67fdcdc537bf2..7b4dd69555e497497460dcf5d72737fe5c09fd53 100644
> --- a/include/linux/virtio_net.h
> +++ b/include/linux/virtio_net.h
> @@ -155,6 +155,10 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> if (gso_type & SKB_GSO_UDP)
> nh_off -= thlen;
>
> + /* Kernel has a special handling for GSO_BY_FRAGS. */
> + if (gso_size == GSO_BY_FRAGS)
> + return -EINVAL;
> +
> /* Too small packets are not really GSO ones. */
> if (skb->len - nh_off > gso_size) {
> shinfo->gso_size = gso_size;
> --
> 2.41.0.694.ge786442a9b-goog
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
` (3 preceding siblings ...)
2023-08-17 8:54 ` Xuan Zhuo
@ 2023-08-17 19:00 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-17 19:00 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, pabeni, netdev, eric.dumazet, syzkaller, lucien.xin,
marcelo.leitner, willemb, mst, jasowang, xuanzhuo
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 16 Aug 2023 14:21:58 +0000 you wrote:
> One missing check in virtio_net_hdr_to_skb() allowed
> syzbot to crash kernels again [1]
>
> Do not allow gso_size to be set to GSO_BY_FRAGS (0xffff),
> because this magic value is used by the kernel.
>
> [1]
> general protection fault, probably for non-canonical address 0xdffffc000000000e: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000070-0x0000000000000077]
> CPU: 0 PID: 5039 Comm: syz-executor401 Not tainted 6.5.0-rc5-next-20230809-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/26/2023
> RIP: 0010:skb_segment+0x1a52/0x3ef0 net/core/skbuff.c:4500
> Code: 00 00 00 e9 ab eb ff ff e8 6b 96 5d f9 48 8b 84 24 00 01 00 00 48 8d 78 70 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e ea 21 00 00 48 8b 84 24 00 01
> RSP: 0018:ffffc90003d3f1c8 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 000000000001fffe RCX: 0000000000000000
> RDX: 000000000000000e RSI: ffffffff882a3115 RDI: 0000000000000070
> RBP: ffffc90003d3f378 R08: 0000000000000005 R09: 000000000000ffff
> R10: 000000000000ffff R11: 5ee4a93e456187d6 R12: 000000000001ffc6
> R13: dffffc0000000000 R14: 0000000000000008 R15: 000000000000ffff
> FS: 00005555563f2380(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000020020000 CR3: 000000001626d000 CR4: 00000000003506f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
> <TASK>
> udp6_ufo_fragment+0x9d2/0xd50 net/ipv6/udp_offload.c:109
> ipv6_gso_segment+0x5c4/0x17b0 net/ipv6/ip6_offload.c:120
> skb_mac_gso_segment+0x292/0x610 net/core/gso.c:53
> __skb_gso_segment+0x339/0x710 net/core/gso.c:124
> skb_gso_segment include/net/gso.h:83 [inline]
> validate_xmit_skb+0x3a5/0xf10 net/core/dev.c:3625
> __dev_queue_xmit+0x8f0/0x3d60 net/core/dev.c:4329
> dev_queue_xmit include/linux/netdevice.h:3082 [inline]
> packet_xmit+0x257/0x380 net/packet/af_packet.c:276
> packet_snd net/packet/af_packet.c:3087 [inline]
> packet_sendmsg+0x24c7/0x5570 net/packet/af_packet.c:3119
> sock_sendmsg_nosec net/socket.c:727 [inline]
> sock_sendmsg+0xd9/0x180 net/socket.c:750
> ____sys_sendmsg+0x6ac/0x940 net/socket.c:2496
> ___sys_sendmsg+0x135/0x1d0 net/socket.c:2550
> __sys_sendmsg+0x117/0x1e0 net/socket.c:2579
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> RIP: 0033:0x7ff27cdb34d9
>
> [...]
Here is the summary with links:
- [net] net: do not allow gso_size to be set to GSO_BY_FRAGS
https://git.kernel.org/netdev/net/c/b616be6b9768
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] 8+ messages in thread
end of thread, other threads:[~2023-08-17 19:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 14:21 [PATCH net] net: do not allow gso_size to be set to GSO_BY_FRAGS Eric Dumazet
2023-08-16 14:40 ` Willem de Bruijn
2023-08-16 14:54 ` Marcelo Ricardo Leitner
2023-08-17 2:19 ` Xuan Zhuo
2023-08-17 6:17 ` Eric Dumazet
2023-08-17 6:48 ` Xuan Zhuo
2023-08-17 8:54 ` Xuan Zhuo
2023-08-17 19:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).