All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Raslan Darawsheh <rasland@nvidia.com>
Cc: <thomas@monjalon.net>, <dev@dpdk.org>, <haijie1@huawei.com>
Subject: Re: [PATCH] app/testpmd: fix VLAN header parsing
Date: Sun, 23 Mar 2025 09:00:32 -0700	[thread overview]
Message-ID: <20250323090032.06d6aa45@hermes.local> (raw)
In-Reply-To: <20250323122822.90407-1-rasland@nvidia.com>

On Sun, 23 Mar 2025 14:28:22 +0200
Raslan Darawsheh <rasland@nvidia.com> wrote:

> Signed-off-by: Raslan Darawsheh <rasland@nvidia.com>
> ---
>  app/test-pmd/csumonly.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
> index 5b906eaa53..302cc4cc66 100644
> --- a/app/test-pmd/csumonly.c
> +++ b/app/test-pmd/csumonly.c
> @@ -468,6 +468,7 @@ get_ethertype_by_ptype(struct rte_ether_hdr *eth_hdr, uint32_t ptype)
>  {
>  	struct rte_vlan_hdr *vlan_hdr;
>  	uint16_t ethertype;
> +	uint32_t i = 0;
>  
>  	switch (ptype) {
>  	case RTE_PTYPE_L3_IPV4:
> @@ -486,10 +487,11 @@ get_ethertype_by_ptype(struct rte_ether_hdr *eth_hdr, uint32_t ptype)
>  		return _htons(RTE_ETHER_TYPE_IPV6);
>  	default:
>  		ethertype = eth_hdr->ether_type;
> -		while (eth_hdr->ether_type == _htons(RTE_ETHER_TYPE_VLAN) ||
> -			eth_hdr->ether_type == _htons(RTE_ETHER_TYPE_QINQ)) {
> +		while (ethertype == _htons(RTE_ETHER_TYPE_VLAN) ||
> +			ethertype == _htons(RTE_ETHER_TYPE_QINQ)) {
>  			vlan_hdr = (struct rte_vlan_hdr *)
> -				((char *)eth_hdr + sizeof(*eth_hdr));
> +				((char *)eth_hdr + sizeof(*eth_hdr) +
> +				(i * sizeof(struct rte_vlan_hdr)));
>  			ethertype = vlan_hdr->eth_proto;
>  		}
>  		return ethertype;

A loop like this is prone to getting attacked with a malicious packet.
You should cut it off after a few vlan headers.
Also. what if packet is truncated, shouldn't be reading past end of data.
And what if packet is fragmented, you need to use rte_pktmbuf_read()

  parent reply	other threads:[~2025-03-23 16:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-23 12:28 [PATCH] app/testpmd: fix VLAN header parsing Raslan Darawsheh
2025-03-23 13:14 ` Morten Brørup
2025-03-24  7:34   ` Raslan Darawsheh
2025-03-24  7:43     ` Morten Brørup
2025-03-24  7:44     ` Morten Brørup
2025-03-24  8:32       ` Raslan Darawsheh
2025-03-24  8:45         ` Morten Brørup
2025-03-23 16:00 ` Stephen Hemminger [this message]
2025-03-24  7:37   ` Raslan Darawsheh
2025-03-23 16:39 ` Thomas Monjalon
2025-03-24  7:38   ` Raslan Darawsheh
2025-03-24  8:50 ` [PATCH v2] " Raslan Darawsheh
2025-03-24  9:04   ` Morten Brørup
2025-03-24  9:40     ` Raslan Darawsheh
2025-03-24  9:33 ` [PATCH v3] " Raslan Darawsheh
2025-03-24 13:18   ` Morten Brørup
2025-03-24 16:59     ` Thomas Monjalon

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=20250323090032.06d6aa45@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=haijie1@huawei.com \
    --cc=rasland@nvidia.com \
    --cc=thomas@monjalon.net \
    /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.