All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net] net: dsa: Discard frames from unused ports
@ 2018-04-07 18:37 Andrew Lunn
  2018-04-07 19:57 ` Florian Fainelli
  2018-04-08 14:35 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lunn @ 2018-04-07 18:37 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Florian Fainelli, Vivien Didelot, Andrew Lunn

The Marvell switches under some conditions will pass a frame to the
host with the port being the CPU port. Such frames are invalid, and
should be dropped. Not dropping them can result in a crash when
incrementing the receive statistics for an invalid port.

Reported-by: Chris Healy <cphealy@gmail.com>
Fixes: 91da11f870f0 ("net: Distributed Switch Architecture protocol support")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
v2:
Use an earlier revision for the fixes tag.
Add unlikely annotation
---
 net/dsa/dsa_priv.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 70de7895e5b8..053731473c99 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -126,6 +126,7 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
 	struct dsa_port *cpu_dp = dev->dsa_ptr;
 	struct dsa_switch_tree *dst = cpu_dp->dst;
 	struct dsa_switch *ds;
+	struct dsa_port *slave_port;
 
 	if (device < 0 || device >= DSA_MAX_SWITCHES)
 		return NULL;
@@ -137,7 +138,12 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
 	if (port < 0 || port >= ds->num_ports)
 		return NULL;
 
-	return ds->ports[port].slave;
+	slave_port = &ds->ports[port];
+
+	if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
+		return NULL;
+
+	return slave_port->slave;
 }
 
 /* port.c */
-- 
2.16.3

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

* Re: [PATCH v2 net] net: dsa: Discard frames from unused ports
  2018-04-07 18:37 [PATCH v2 net] net: dsa: Discard frames from unused ports Andrew Lunn
@ 2018-04-07 19:57 ` Florian Fainelli
  2018-04-08 14:35 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2018-04-07 19:57 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Vivien Didelot



On 04/07/2018 11:37 AM, Andrew Lunn wrote:
> The Marvell switches under some conditions will pass a frame to the
> host with the port being the CPU port. Such frames are invalid, and
> should be dropped. Not dropping them can result in a crash when
> incrementing the receive statistics for an invalid port.
> 
> Reported-by: Chris Healy <cphealy@gmail.com>
> Fixes: 91da11f870f0 ("net: Distributed Switch Architecture protocol support")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

It looks like the stable scripts now test build against several kernel
versions so we should be able to know which stable versions need a
specific fix that does not involve dsa_master_find_slave().

Thanks Andrew!

> ---
> v2:
> Use an earlier revision for the fixes tag.
> Add unlikely annotation
> ---
>  net/dsa/dsa_priv.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
> index 70de7895e5b8..053731473c99 100644
> --- a/net/dsa/dsa_priv.h
> +++ b/net/dsa/dsa_priv.h
> @@ -126,6 +126,7 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
>  	struct dsa_port *cpu_dp = dev->dsa_ptr;
>  	struct dsa_switch_tree *dst = cpu_dp->dst;
>  	struct dsa_switch *ds;
> +	struct dsa_port *slave_port;
>  
>  	if (device < 0 || device >= DSA_MAX_SWITCHES)
>  		return NULL;
> @@ -137,7 +138,12 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
>  	if (port < 0 || port >= ds->num_ports)
>  		return NULL;
>  
> -	return ds->ports[port].slave;
> +	slave_port = &ds->ports[port];
> +
> +	if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
> +		return NULL;
> +
> +	return slave_port->slave;
>  }
>  
>  /* port.c */
> 

-- 
Florian

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

* Re: [PATCH v2 net] net: dsa: Discard frames from unused ports
  2018-04-07 18:37 [PATCH v2 net] net: dsa: Discard frames from unused ports Andrew Lunn
  2018-04-07 19:57 ` Florian Fainelli
@ 2018-04-08 14:35 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-04-08 14:35 UTC (permalink / raw)
  To: andrew; +Cc: netdev, f.fainelli, vivien.didelot

From: Andrew Lunn <andrew@lunn.ch>
Date: Sat,  7 Apr 2018 20:37:40 +0200

> The Marvell switches under some conditions will pass a frame to the
> host with the port being the CPU port. Such frames are invalid, and
> should be dropped. Not dropping them can result in a crash when
> incrementing the receive statistics for an invalid port.
> 
> Reported-by: Chris Healy <cphealy@gmail.com>
> Fixes: 91da11f870f0 ("net: Distributed Switch Architecture protocol support")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
> v2:
> Use an earlier revision for the fixes tag.
> Add unlikely annotation

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2018-04-08 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-07 18:37 [PATCH v2 net] net: dsa: Discard frames from unused ports Andrew Lunn
2018-04-07 19:57 ` Florian Fainelli
2018-04-08 14:35 ` David Miller

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.