Netdev List
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Yuri Karpov <YKarpov@ispras.ru>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] net: dsa: fix NULL pointer dereference in seq_match()
Date: Thu, 1 Dec 2022 00:01:11 +0200	[thread overview]
Message-ID: <20221130220111.zfrzckiyayaoka3z@skbuf> (raw)
In-Reply-To: <20221130084431.3299054-1-YKarpov@ispras.ru>

On Wed, Nov 30, 2022 at 11:44:31AM +0300, Yuri Karpov wrote:
> ptp_parse_header() result is not checked in seq_match() that can lead
> to NULL pointer dereferense.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: c6fe0ad2c349 ("net: dsa: mv88e6xxx: add rx/tx timestamping support")
> Signed-off-by: Yuri Karpov <YKarpov@ispras.ru>
> ---
>  drivers/net/dsa/mv88e6xxx/hwtstamp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/mv88e6xxx/hwtstamp.c b/drivers/net/dsa/mv88e6xxx/hwtstamp.c
> index 331b4ca089ff..97f30795a2bb 100644
> --- a/drivers/net/dsa/mv88e6xxx/hwtstamp.c
> +++ b/drivers/net/dsa/mv88e6xxx/hwtstamp.c
> @@ -246,7 +246,7 @@ static int seq_match(struct sk_buff *skb, u16 ts_seqid)
>  
>  	hdr = ptp_parse_header(skb, type);
>  
> -	return ts_seqid == ntohs(hdr->sequence_id);
> +	return hdr ? ts_seqid == ntohs(hdr->sequence_id) : 0;

NACK.

ptp_parse_header() will never return NULL when called from seq_match().
The skb comes from mv88e6xxx_get_rxts(), which takes it from ps->rx_queue.
It was put there by mv88e6xxx_port_rxtstamp(), which prior to that, had
a check for ptp_parse_header() returning NULL in mv88e6xxx_should_tstamp().

Please don't just blindly trust your tools.

>  }
>  
>  static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
> -- 
> 2.34.1
> 

      parent reply	other threads:[~2022-11-30 22:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30  8:44 [PATCH] net: dsa: fix NULL pointer dereference in seq_match() Yuri Karpov
2022-11-30 10:07 ` Pavan Chebbi
2022-11-30 22:01 ` Vladimir Oltean [this message]

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=20221130220111.zfrzckiyayaoka3z@skbuf \
    --to=olteanv@gmail.com \
    --cc=YKarpov@ispras.ru \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox