]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.4/net-dsa-ensure-validity-of-dst-ds.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.4 / net-dsa-ensure-validity-of-dst-ds.patch
1 From foo@baz Thu Jan 12 21:37:26 CET 2017
2 From: Florian Fainelli <f.fainelli@gmail.com>
3 Date: Mon, 9 Jan 2017 11:58:34 -0800
4 Subject: net: dsa: Ensure validity of dst->ds[0]
5
6 From: Florian Fainelli <f.fainelli@gmail.com>
7
8
9 [ Upstream commit faf3a932fbeb77860226a8323eacb835edc98648 ]
10
11 It is perfectly possible to have non zero indexed switches being present
12 in a DSA switch tree, in such a case, we will be deferencing a NULL
13 pointer while dsa_cpu_port_ethtool_{setup,restore}. Be more defensive
14 and ensure that dst->ds[0] is valid before doing anything with it.
15
16 Fixes: 0c73c523cf73 ("net: dsa: Initialize CPU port ethtool ops per tree")
17 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
18 Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 ---
22 net/dsa/dsa2.c | 11 +++++++----
23 1 file changed, 7 insertions(+), 4 deletions(-)
24
25 --- a/net/dsa/dsa2.c
26 +++ b/net/dsa/dsa2.c
27 @@ -394,9 +394,11 @@ static int dsa_dst_apply(struct dsa_swit
28 return err;
29 }
30
31 - err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
32 - if (err)
33 - return err;
34 + if (dst->ds[0]) {
35 + err = dsa_cpu_port_ethtool_setup(dst->ds[0]);
36 + if (err)
37 + return err;
38 + }
39
40 /* If we use a tagging format that doesn't have an ethertype
41 * field, make sure that all packets from this point on get
42 @@ -433,7 +435,8 @@ static void dsa_dst_unapply(struct dsa_s
43 dsa_ds_unapply(dst, ds);
44 }
45
46 - dsa_cpu_port_ethtool_restore(dst->ds[0]);
47 + if (dst->ds[0])
48 + dsa_cpu_port_ethtool_restore(dst->ds[0]);
49
50 pr_info("DSA: tree %d unapplied\n", dst->tree);
51 dst->applied = false;