[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210806162234.69334902@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Date: Fri, 6 Aug 2021 16:22:34 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Guillaume Nault <gnault@...hat.com>
Cc: David Miller <davem@...emloft.net>, netdev@...r.kernel.org,
Martin Varghese <martin.varghese@...ia.com>,
Willem de Bruijn <willemb@...gle.com>
Subject: Re: [PATCH net] bareudp: Fix invalid read beyond skb's linear data
On Fri, 6 Aug 2021 17:52:06 +0200 Guillaume Nault wrote:
> Data beyond the UDP header might not be part of the skb's linear data.
> Use skb_copy_bits() instead of direct access to skb->data+X, so that
> we read the correct bytes even on a fragmented skb.
>
> Fixes: 4b5f67232d95 ("net: Special handling for IP & MPLS.")
> Signed-off-by: Guillaume Nault <gnault@...hat.com>
> ---
> drivers/net/bareudp.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
> index a7ee0af1af90..54e321a695ce 100644
> --- a/drivers/net/bareudp.c
> +++ b/drivers/net/bareudp.c
> @@ -71,12 +71,18 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
> family = AF_INET6;
>
> if (bareudp->ethertype == htons(ETH_P_IP)) {
> - struct iphdr *iphdr;
> + __u8 ipversion;
>
> - iphdr = (struct iphdr *)(skb->data + BAREUDP_BASE_HLEN);
> - if (iphdr->version == 4) {
> - proto = bareudp->ethertype;
> - } else if (bareudp->multi_proto_mode && (iphdr->version == 6)) {
> + if (skb_copy_bits(skb, BAREUDP_BASE_HLEN, &ipversion,
> + sizeof(ipversion))) {
No preference just curious - could skb_header_pointer() be better suited?
> + bareudp->dev->stats.rx_dropped++;
> + goto drop;
> + }
> + ipversion >>= 4;
> +
> + if (ipversion == 4) {
> + proto = htons(ETH_P_IP);
> + } else if (ipversion == 6 && bareudp->multi_proto_mode) {
> proto = htons(ETH_P_IPV6);
> } else {
> bareudp->dev->stats.rx_dropped++;
Powered by blists - more mailing lists