lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200427135254.3ab8628d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Date:   Mon, 27 Apr 2020 13:52:54 -0700
From:   Jakub Kicinski <kuba@...nel.org>
To:     "Jason A. Donenfeld" <Jason@...c4.com>
Cc:     netdev@...r.kernel.org, Adhipati Blambangan <adhipati@...a.io>,
        David Ahern <dsahern@...il.com>,
        Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCH net v3] net: xdp: account for layer 3 packets in generic
 skb handler

On Mon, 27 Apr 2020 14:42:08 -0600 Jason A. Donenfeld wrote:
> A user reported that packets from wireguard were possibly ignored by XDP
> [1]. Apparently, the generic skb xdp handler path seems to assume that
> packets will always have an ethernet header, which really isn't always
> the case for layer 3 packets, which are produced by multiple drivers.
> This patch fixes the oversight. If the mac_len is 0, then we assume
> that it's a layer 3 packet, and in that case prepend a pseudo ethhdr to
> the packet whose h_proto is copied from skb->protocol, which will have
> the appropriate v4 or v6 ethertype. This allows us to keep XDP programs'
> assumption correct about packets always having that ethernet header, so
> that existing code doesn't break, while still allowing layer 3 devices
> to use the generic XDP handler.
> 
> [1] https://lore.kernel.org/wireguard/M5WzVK5--3-2@tuta.io/
> 
> Reported-by: Adhipati Blambangan <adhipati@...a.io>
> Cc: David Ahern <dsahern@...il.com>
> Cc: Toke Høiland-Jørgensen <toke@...hat.com>
> Signed-off-by: Jason A. Donenfeld <Jason@...c4.com>
> ---
>  net/core/dev.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 77c154107b0d..3bc9a96bc808 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -4510,9 +4510,9 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
>  	u32 metalen, act = XDP_DROP;
>  	__be16 orig_eth_type;
>  	struct ethhdr *eth;
> +	u32 mac_len = ~0;
>  	bool orig_bcast;
>  	int hlen, off;
> -	u32 mac_len;
>  
>  	/* Reinjected packets coming from act_mirred or similar should
>  	 * not get XDP generic processing.
> @@ -4544,6 +4544,12 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
>  	 * header.
>  	 */
>  	mac_len = skb->data - skb_mac_header(skb);
> +	if (!mac_len) {
> +		eth = skb_push(skb, sizeof(struct ethhdr));
> +		eth_zero_addr(eth->h_source);
> +		eth_zero_addr(eth->h_dest);
> +		eth->h_proto = skb->protocol;
> +	}
>  	hlen = skb_headlen(skb) + mac_len;
>  	xdp->data = skb->data - mac_len;
>  	xdp->data_meta = xdp->data;
> @@ -4611,6 +4617,8 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
>  		kfree_skb(skb);
>  		break;
>  	}
> +	if (!mac_len)
> +		skb_pull(skb, sizeof(struct ethhdr));

Is this going to work correctly with XDP_TX? presumably wireguard
doesn't want the ethernet L2 on egress, either? And what about
redirects?

I'm not sure we can paper over the L2 differences between interfaces.
Isn't user supposed to know what interface the program is attached to?
I believe that's the case for cls_bpf ingress, right?

>  	return act;
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ