* [PATCH net] net: dsa: Ensure validity of dst->ds[0]
@ 2017-01-09 19:58 Florian Fainelli
2017-01-09 20:50 ` Vivien Didelot
2017-01-11 1:19 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Florian Fainelli @ 2017-01-09 19:58 UTC (permalink / raw)
To: netdev; +Cc: davem, vivien.didelot, andrew, Florian Fainelli
It is perfectly possible to have non zero indexed switches being present
in a DSA switch tree, in such a case, we will be deferencing a NULL
pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
and ensure that dst->ds[0] is valid before doing anything with it.
Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa2.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 5fff951a0a49..da3862124545 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -394,9 +394,11 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
return err;
}
- err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
- if (err)
- return err;
+ if (dst->ds[0]) {
+ err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
+ if (err)
+ return err;
+ }
/* If we use a tagging format that doesn't have an ethertype
* field, make sure that all packets from this point on get
@@ -433,7 +435,8 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
dsa_ds_unapply(dst, ds);
}
- dsa_cpu_port_ethtool_restore(dst->ds[0]);
+ if (dst->ds[0])
+ dsa_cpu_port_ethtool_restore(dst->ds[0]);
pr_info("DSA: tree %d unapplied\n", dst->tree);
dst->applied = false;
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: dsa: Ensure validity of dst->ds[0]
2017-01-09 19:58 [PATCH net] net: dsa: Ensure validity of dst->ds[0] Florian Fainelli
@ 2017-01-09 20:50 ` Vivien Didelot
2017-01-09 21:01 ` Andrew Lunn
2017-01-11 1:19 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Vivien Didelot @ 2017-01-09 20:50 UTC (permalink / raw)
To: Florian Fainelli, netdev; +Cc: davem, andrew, Florian Fainelli
Hi Florian,
Florian Fainelli <f.fainelli@gmail.com> writes:
> It is perfectly possible to have non zero indexed switches being present
> in a DSA switch tree, in such a case, we will be deferencing a NULL
> pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
> and ensure that dst->ds[0] is valid before doing anything with it.
>
> Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
The patch is correct since we are already using dst->ds[0] here.
But we should stop using that and use dst->cpu_switch instead, because
the switch with ID 0 won't necessary be the CPU switch. Now that the
Ethernet switch chips are true Linux devices, they are registered in
order depending on their bus/address. So in a setup like this:
,--MDIO--@4--------@2--
| | |
[CPU] <-> [swA] <-> [swB]
swB will have index 0 and swA will have index 1. Please correct me if
I'm wrong.
Thanks,
Vivien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: dsa: Ensure validity of dst->ds[0]
2017-01-09 20:50 ` Vivien Didelot
@ 2017-01-09 21:01 ` Andrew Lunn
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2017-01-09 21:01 UTC (permalink / raw)
To: Vivien Didelot; +Cc: Florian Fainelli, netdev, davem
On Mon, Jan 09, 2017 at 03:50:53PM -0500, Vivien Didelot wrote:
> Hi Florian,
>
> Florian Fainelli <f.fainelli@gmail.com> writes:
>
> > It is perfectly possible to have non zero indexed switches being present
> > in a DSA switch tree, in such a case, we will be deferencing a NULL
> > pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
> > and ensure that dst->ds[0] is valid before doing anything with it.
> >
> > Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
> > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>
> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
>
> The patch is correct since we are already using dst->ds[0] here.
>
> But we should stop using that and use dst->cpu_switch instead, because
> the switch with ID 0 won't necessary be the CPU switch. Now that the
> Ethernet switch chips are true Linux devices, they are registered in
> order depending on their bus/address. So in a setup like this:
>
> ,--MDIO--@4--------@2--
> | | |
> [CPU] <-> [swA] <-> [swB]
>
> swB will have index 0 and swA will have index 1. Please correct me if
> I'm wrong.
Correct, which DS has the CPU port is arbitrary.
It also gets messier when Johns finishes reworking my PoC patchset for
multiple CPU ports. You ideally want the correct CPU port for this
host interface.
Andrew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: dsa: Ensure validity of dst->ds[0]
2017-01-09 19:58 [PATCH net] net: dsa: Ensure validity of dst->ds[0] Florian Fainelli
2017-01-09 20:50 ` Vivien Didelot
@ 2017-01-11 1:19 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2017-01-11 1:19 UTC (permalink / raw)
To: f.fainelli; +Cc: netdev, vivien.didelot, andrew
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Mon, 9 Jan 2017 11:58:34 -0800
> It is perfectly possible to have non zero indexed switches being present
> in a DSA switch tree, in such a case, we will be deferencing a NULL
> pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
> and ensure that dst->ds[0] is valid before doing anything with it.
>
> Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-01-11 1:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-09 19:58 [PATCH net] net: dsa: Ensure validity of dst->ds[0] Florian Fainelli
2017-01-09 20:50 ` Vivien Didelot
2017-01-09 21:01 ` Andrew Lunn
2017-01-11 1:19 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).