Commit a50a151e authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: ipconfig: ic_dev can be NULL in ic_close_devs

ic_close_dev contains a generalization of the logic to not close a
network interface if it's the host port for a DSA switch. This logic is
disguised behind an iteration through the lowers of ic_dev in
ic_close_dev.

When no interface for ipconfig can be found, ic_dev is NULL, and
ic_close_dev:
- dereferences a NULL pointer when assigning selected_dev
- would attempt to search through the lower interfaces of a NULL
  net_device pointer

So we should protect against that case.

The "lower_dev" iterator variable was shortened to "lower" in order to
keep the 80 character limit.

Fixes: f68cbaed ("net: ipconfig: avoid use-after-free in ic_close_devs")
Fixes: 46acf7bd ("Revert "net: ipv4: handle DSA enabled master network devices"")
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Tested-by: default avatarHeiko Thiery <heiko.thiery@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6debc0fd
...@@ -309,7 +309,7 @@ static int __init ic_open_devs(void) ...@@ -309,7 +309,7 @@ static int __init ic_open_devs(void)
*/ */
static void __init ic_close_devs(void) static void __init ic_close_devs(void)
{ {
struct net_device *selected_dev = ic_dev->dev; struct net_device *selected_dev = ic_dev ? ic_dev->dev : NULL;
struct ic_device *d, *next; struct ic_device *d, *next;
struct net_device *dev; struct net_device *dev;
...@@ -317,16 +317,18 @@ static void __init ic_close_devs(void) ...@@ -317,16 +317,18 @@ static void __init ic_close_devs(void)
next = ic_first_dev; next = ic_first_dev;
while ((d = next)) { while ((d = next)) {
bool bring_down = (d != ic_dev); bool bring_down = (d != ic_dev);
struct net_device *lower_dev; struct net_device *lower;
struct list_head *iter; struct list_head *iter;
next = d->next; next = d->next;
dev = d->dev; dev = d->dev;
netdev_for_each_lower_dev(selected_dev, lower_dev, iter) { if (selected_dev) {
if (dev == lower_dev) { netdev_for_each_lower_dev(selected_dev, lower, iter) {
bring_down = false; if (dev == lower) {
break; bring_down = false;
break;
}
} }
} }
if (bring_down) { if (bring_down) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment