Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: dsa: fix NULL pointer dereference in seq_match()
@ 2022-11-30  8:44 Yuri Karpov
  2022-11-30 10:07 ` Pavan Chebbi
  2022-11-30 22:01 ` Vladimir Oltean
  0 siblings, 2 replies; 3+ messages in thread
From: Yuri Karpov @ 2022-11-30  8:44 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Yuri Karpov, Florian Fainelli, Vladimir Oltean, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvc-project

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;
 }
 
 static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: dsa: fix NULL pointer dereference in seq_match()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Pavan Chebbi @ 2022-11-30 10:07 UTC (permalink / raw)
  To: Yuri Karpov
  Cc: Andrew Lunn, Florian Fainelli, Vladimir Oltean, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvc-project

[-- Attachment #1: Type: text/plain, Size: 1168 bytes --]

On Wed, Nov 30, 2022 at 2:15 PM Yuri Karpov <YKarpov@ispras.ru> 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;
>  }

You need to have the target tree in the subject. But change looks good to me.

Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>

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

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: dsa: fix NULL pointer dereference in seq_match()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Oltean @ 2022-11-30 22:01 UTC (permalink / raw)
  To: Yuri Karpov
  Cc: Andrew Lunn, Florian Fainelli, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, lvc-project

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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-30 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox