From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Fainelli Subject: Re: [PATCH net] net: dsa: Discard frames from unused ports Date: Wed, 4 Apr 2018 17:49:10 -0700 Message-ID: References: <1522886204-1545-1-git-send-email-andrew@lunn.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev , Vivien Didelot To: Andrew Lunn , David Miller Return-path: Received: from mail-qk0-f195.google.com ([209.85.220.195]:34202 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbeDEAtW (ORCPT ); Wed, 4 Apr 2018 20:49:22 -0400 Received: by mail-qk0-f195.google.com with SMTP id g7so12426067qkm.1 for ; Wed, 04 Apr 2018 17:49:22 -0700 (PDT) In-Reply-To: <1522886204-1545-1-git-send-email-andrew@lunn.ch> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 04/04/2018 04:56 PM, 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 > Fixes: 5f6b4e14cada ("net: dsa: User per-cpu 64-bit statistics") Are you sure this is the commit that introduced the problem? > Signed-off-by: Andrew Lunn > --- > 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..6c1bf3d9f652 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 (slave_port->type != DSA_PORT_TYPE_USER) Can we optimize this with an unlikely()? > + return NULL; > + > + return slave_port->slave; > } > > /* port.c */ > -- Florian