netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] tap/tun: harden by dropping short frame
@ 2024-07-24 17:04 Dongli Zhang
  2024-07-24 17:04 ` [PATCH net 1/2] tap: add missing verification for " Dongli Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dongli Zhang @ 2024-07-24 17:04 UTC (permalink / raw)
  To: netdev
  Cc: willemdebruijn.kernel, jasowang, davem, edumazet, kuba, pabeni,
	ast, daniel, hawk, john.fastabend, linux-kernel, bpf, si-wei.liu

This is to harden all of tap/tun to avoid any short frame smaller than the
Ethernet header (ETH_HLEN).

While the xen-netback already rejects short frame smaller than ETH_HLEN ...

 914 static void xenvif_tx_build_gops(struct xenvif_queue *queue,
 915                                      int budget,
 916                                      unsigned *copy_ops,
 917                                      unsigned *map_ops)
 918 {
... ...
1007                 if (unlikely(txreq.size < ETH_HLEN)) {
1008                         netdev_dbg(queue->vif->dev,
1009                                    "Bad packet size: %d\n", txreq.size);
1010                         xenvif_tx_err(queue, &txreq, extra_count, idx);
1011                         break;
1012                 }

... the short frame may not be dropped by vhost-net/tap/tun.

This fixes CVE-2024-41090 and CVE-2024-41091.

Thank you very much!

Dongli Zhang



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

* [PATCH net 1/2] tap: add missing verification for short frame
  2024-07-24 17:04 [PATCH net 0/2] tap/tun: harden by dropping short frame Dongli Zhang
@ 2024-07-24 17:04 ` Dongli Zhang
  2024-07-24 17:04 ` [PATCH net 2/2] tun: " Dongli Zhang
  2024-07-25 15:19 ` [PATCH net 0/2] tap/tun: harden by dropping " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Dongli Zhang @ 2024-07-24 17:04 UTC (permalink / raw)
  To: netdev
  Cc: willemdebruijn.kernel, jasowang, davem, edumazet, kuba, pabeni,
	ast, daniel, hawk, john.fastabend, linux-kernel, bpf, si-wei.liu

From: Si-Wei Liu <si-wei.liu@oracle.com>

The cited commit missed to check against the validity of the frame length
in the tap_get_user_xdp() path, which could cause a corrupted skb to be
sent downstack. Even before the skb is transmitted, the
tap_get_user_xdp()-->skb_set_network_header() may assume the size is more
than ETH_HLEN. Once transmitted, this could either cause out-of-bound
access beyond the actual length, or confuse the underlayer with incorrect
or inconsistent header length in the skb metadata.

In the alternative path, tap_get_user() already prohibits short frame which
has the length less than Ethernet header size from being transmitted.

This is to drop any frame shorter than the Ethernet header size just like
how tap_get_user() does.

CVE: CVE-2024-41090
Link: https://lore.kernel.org/netdev/1717026141-25716-1-git-send-email-si-wei.liu@oracle.com/
Fixes: 0efac27791ee ("tap: accept an array of XDP buffs through sendmsg()")
Cc: stable@vger.kernel.org
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/tap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index bfdd3875fe86..77574f7a3bd4 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -1177,6 +1177,11 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
 	struct sk_buff *skb;
 	int err, depth;
 
+	if (unlikely(xdp->data_end - xdp->data < ETH_HLEN)) {
+		err = -EINVAL;
+		goto err;
+	}
+
 	if (q->flags & IFF_VNET_HDR)
 		vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
 
-- 
2.34.1


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

* [PATCH net 2/2] tun: add missing verification for short frame
  2024-07-24 17:04 [PATCH net 0/2] tap/tun: harden by dropping short frame Dongli Zhang
  2024-07-24 17:04 ` [PATCH net 1/2] tap: add missing verification for " Dongli Zhang
@ 2024-07-24 17:04 ` Dongli Zhang
  2024-07-25 15:19 ` [PATCH net 0/2] tap/tun: harden by dropping " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Dongli Zhang @ 2024-07-24 17:04 UTC (permalink / raw)
  To: netdev
  Cc: willemdebruijn.kernel, jasowang, davem, edumazet, kuba, pabeni,
	ast, daniel, hawk, john.fastabend, linux-kernel, bpf, si-wei.liu

The cited commit missed to check against the validity of the frame length
in the tun_xdp_one() path, which could cause a corrupted skb to be sent
downstack. Even before the skb is transmitted, the
tun_xdp_one-->eth_type_trans() may access the Ethernet header although it
can be less than ETH_HLEN. Once transmitted, this could either cause
out-of-bound access beyond the actual length, or confuse the underlayer
with incorrect or inconsistent header length in the skb metadata.

In the alternative path, tun_get_user() already prohibits short frame which
has the length less than Ethernet header size from being transmitted for
IFF_TAP.

This is to drop any frame shorter than the Ethernet header size just like
how tun_get_user() does.

CVE: CVE-2024-41091
Inspired-by: https://lore.kernel.org/netdev/1717026141-25716-1-git-send-email-si-wei.liu@oracle.com/
Fixes: 043d222f93ab ("tuntap: accept an array of XDP buffs through sendmsg()")
Cc: Si-Wei Liu <si-wei.liu@oracle.com>
Cc: stable@vger.kernel.org
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Reviewed-by: Si-Wei Liu <si-wei.liu@oracle.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/tun.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9b24861464bc..1d06c560c5e6 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2455,6 +2455,9 @@ static int tun_xdp_one(struct tun_struct *tun,
 	bool skb_xdp = false;
 	struct page *page;
 
+	if (unlikely(datasize < ETH_HLEN))
+		return -EINVAL;
+
 	xdp_prog = rcu_dereference(tun->xdp_prog);
 	if (xdp_prog) {
 		if (gso->gso_type) {
-- 
2.34.1


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

* Re: [PATCH net 0/2] tap/tun: harden by dropping short frame
  2024-07-24 17:04 [PATCH net 0/2] tap/tun: harden by dropping short frame Dongli Zhang
  2024-07-24 17:04 ` [PATCH net 1/2] tap: add missing verification for " Dongli Zhang
  2024-07-24 17:04 ` [PATCH net 2/2] tun: " Dongli Zhang
@ 2024-07-25 15:19 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-07-25 15:19 UTC (permalink / raw)
  To: Dongli Zhang
  Cc: netdev, willemdebruijn.kernel, jasowang, davem, edumazet, kuba,
	pabeni, ast, daniel, hawk, john.fastabend, linux-kernel, bpf,
	si-wei.liu

Hello:

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

On Wed, 24 Jul 2024 10:04:50 -0700 you wrote:
> This is to harden all of tap/tun to avoid any short frame smaller than the
> Ethernet header (ETH_HLEN).
> 
> While the xen-netback already rejects short frame smaller than ETH_HLEN ...
> 
>  914 static void xenvif_tx_build_gops(struct xenvif_queue *queue,
>  915                                      int budget,
>  916                                      unsigned *copy_ops,
>  917                                      unsigned *map_ops)
>  918 {
> ... ...
> 1007                 if (unlikely(txreq.size < ETH_HLEN)) {
> 1008                         netdev_dbg(queue->vif->dev,
> 1009                                    "Bad packet size: %d\n", txreq.size);
> 1010                         xenvif_tx_err(queue, &txreq, extra_count, idx);
> 1011                         break;
> 1012                 }
> 
> [...]

Here is the summary with links:
  - [net,1/2] tap: add missing verification for short frame
    https://git.kernel.org/netdev/net/c/ed7f2afdd0e0
  - [net,2/2] tun: add missing verification for short frame
    https://git.kernel.org/netdev/net/c/049584807f1d

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] 4+ messages in thread

end of thread, other threads:[~2024-07-25 15:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-24 17:04 [PATCH net 0/2] tap/tun: harden by dropping short frame Dongli Zhang
2024-07-24 17:04 ` [PATCH net 1/2] tap: add missing verification for " Dongli Zhang
2024-07-24 17:04 ` [PATCH net 2/2] tun: " Dongli Zhang
2024-07-25 15:19 ` [PATCH net 0/2] tap/tun: harden by dropping " 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).