All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@mellanox.com>
To: Cong Wang <xiyou.wangcong@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: Saeed Mahameed <saeedm@mellanox.com>
Subject: Re: [Patch net] mlx5: check for malformed packets
Date: Sun, 2 Dec 2018 08:56:43 +0000	[thread overview]
Message-ID: <955711f0-eb24-4512-c9a3-429bdad8bcad@mellanox.com> (raw)
In-Reply-To: <20181201203837.3306-1-xiyou.wangcong@gmail.com>



On 01/12/2018 10:38 PM, Cong Wang wrote:
> is_last_ethertype_ip() is used to check IP/IPv6 protocol before
> parsing IP/IPv6 headers.
> 
> But __vlan_get_protocol() is only bound to skb->len, a malicious
> packet could exhaust all skb->len by inserting sufficient ETH_P_8021AD
> headers, and it may not even contain an IP/IPv6 header at all, so we
> have to check if we are still safe to continue to parse IP/IPv6 header.
> If not, treat it as non-IP packet.
> 
> This should not cause any crash as we stil have tail room in skb,
> but we can't just rely on it either.
> 
> Cc: Tariq Toukan <tariqt@mellanox.com>
> Cc: Saeed Mahameed <saeedm@mellanox.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 

Hi Cong,
Thanks for your patch.

> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> index 624eed345b5d..1e505013ebfd 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> @@ -693,7 +693,18 @@ static inline bool is_last_ethertype_ip(struct sk_buff *skb, int *network_depth,
>   {
>   	*proto = ((struct ethhdr *)skb->data)->h_proto;
>   	*proto = __vlan_get_protocol(skb, *proto, network_depth);
> -	return (*proto == htons(ETH_P_IP) || *proto == htons(ETH_P_IPV6));
> +
> +	if (*proto == htons(ETH_P_IP)) {
> +		if (unlikely(*network_depth > skb->len - sizeof(struct iphdr)))
> +			return false;
> +		return true;

Or just do the following?
	return *network_depth <= skb->len - sizeof(struct iphdr));

We'll lose the compiler hint though, so I'm not sure which is better.

> +	} else if (*proto == htons(ETH_P_IPV6)) {

No need for an else here, the first if block always returns.

> +		if (unlikely(*network_depth > skb->len - sizeof(struct ipv6hdr)))
> +			return false;
> +		return true;

Same applies here.

> +	}
> +
> +	return false;
>   }
>   
>   static inline void mlx5e_enable_ecn(struct mlx5e_rq *rq, struct sk_buff *skb)
> 

  reply	other threads:[~2018-12-02  8:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-01 20:38 [Patch net] mlx5: check for malformed packets Cong Wang
2018-12-02  8:56 ` Tariq Toukan [this message]
2018-12-03  5:11   ` Cong Wang
2018-12-03 18:15     ` Cong Wang
2018-12-03 18:39 ` Cong Wang
2018-12-04 19:28   ` Saeed Mahameed
2018-12-04 20:17     ` Cong Wang
2018-12-04 19:32 ` Saeed Mahameed
2018-12-04 20:21   ` Cong Wang
2018-12-05  1:16     ` Saeed Mahameed
2018-12-05  2:12       ` Cong Wang
2018-12-04 20:23 ` Cong Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=955711f0-eb24-4512-c9a3-429bdad8bcad@mellanox.com \
    --to=tariqt@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.