Commit d15040a3 authored by David S. Miller's avatar David S. Miller

Merge branch 'bridge-ioctl-fixes'

Nikolay Aleksandrov says:

====================
net: bridge: fix recent ioctl changes

These are three fixes for the recent bridge removal of ndo_do_ioctl
done by commit ad2f99ae ("net: bridge: move bridge ioctls out of
.ndo_do_ioctl"). Patch 01 fixes a deadlock of the new bridge ioctl
hook lock and rtnl by taking a netdev reference and always taking the
bridge ioctl lock first then rtnl from within the bridge hook.
Patch 02 fixes old_deviceless() bridge calls device name argument, and
patch 03 checks in dev_ifsioc()'s SIOCBRADD/DELIF cases if the netdevice is
actually a bridge before interpreting its private ptr as net_bridge.

Patch 01 was tested by running old bridge-utils commands with lockdep
enabled. Patch 02 was tested again by using bridge-utils and using the
respective ioctl calls on a "up" bridge device. Patch 03 was tested by
using the addif ioctl on a non-bridge device (e.g. loopback).
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4167a960 9384eacd
...@@ -456,7 +456,7 @@ int br_add_bridge(struct net *net, const char *name) ...@@ -456,7 +456,7 @@ int br_add_bridge(struct net *net, const char *name)
dev_net_set(dev, net); dev_net_set(dev, net);
dev->rtnl_link_ops = &br_link_ops; dev->rtnl_link_ops = &br_link_ops;
res = register_netdev(dev); res = register_netdevice(dev);
if (res) if (res)
free_netdev(dev); free_netdev(dev);
return res; return res;
...@@ -467,7 +467,6 @@ int br_del_bridge(struct net *net, const char *name) ...@@ -467,7 +467,6 @@ int br_del_bridge(struct net *net, const char *name)
struct net_device *dev; struct net_device *dev;
int ret = 0; int ret = 0;
rtnl_lock();
dev = __dev_get_by_name(net, name); dev = __dev_get_by_name(net, name);
if (dev == NULL) if (dev == NULL)
ret = -ENXIO; /* Could not find device */ ret = -ENXIO; /* Could not find device */
...@@ -485,7 +484,6 @@ int br_del_bridge(struct net *net, const char *name) ...@@ -485,7 +484,6 @@ int br_del_bridge(struct net *net, const char *name)
else else
br_dev_delete(dev, NULL); br_dev_delete(dev, NULL);
rtnl_unlock();
return ret; return ret;
} }
......
...@@ -351,7 +351,7 @@ static int old_deviceless(struct net *net, void __user *uarg) ...@@ -351,7 +351,7 @@ static int old_deviceless(struct net *net, void __user *uarg)
if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (copy_from_user(buf, uarg, IFNAMSIZ)) if (copy_from_user(buf, (void __user *)args[1], IFNAMSIZ))
return -EFAULT; return -EFAULT;
buf[IFNAMSIZ-1] = 0; buf[IFNAMSIZ-1] = 0;
...@@ -369,33 +369,44 @@ static int old_deviceless(struct net *net, void __user *uarg) ...@@ -369,33 +369,44 @@ static int old_deviceless(struct net *net, void __user *uarg)
int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd, int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd,
struct ifreq *ifr, void __user *uarg) struct ifreq *ifr, void __user *uarg)
{ {
int ret = -EOPNOTSUPP;
rtnl_lock();
switch (cmd) { switch (cmd) {
case SIOCGIFBR: case SIOCGIFBR:
case SIOCSIFBR: case SIOCSIFBR:
return old_deviceless(net, uarg); ret = old_deviceless(net, uarg);
break;
case SIOCBRADDBR: case SIOCBRADDBR:
case SIOCBRDELBR: case SIOCBRDELBR:
{ {
char buf[IFNAMSIZ]; char buf[IFNAMSIZ];
if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) {
return -EPERM; ret = -EPERM;
break;
}
if (copy_from_user(buf, uarg, IFNAMSIZ)) if (copy_from_user(buf, uarg, IFNAMSIZ)) {
return -EFAULT; ret = -EFAULT;
break;
}
buf[IFNAMSIZ-1] = 0; buf[IFNAMSIZ-1] = 0;
if (cmd == SIOCBRADDBR) if (cmd == SIOCBRADDBR)
return br_add_bridge(net, buf); ret = br_add_bridge(net, buf);
else
return br_del_bridge(net, buf); ret = br_del_bridge(net, buf);
} }
break;
case SIOCBRADDIF: case SIOCBRADDIF:
case SIOCBRDELIF: case SIOCBRDELIF:
return add_del_if(br, ifr->ifr_ifindex, cmd == SIOCBRADDIF); ret = add_del_if(br, ifr->ifr_ifindex, cmd == SIOCBRADDIF);
break;
} }
return -EOPNOTSUPP;
rtnl_unlock();
return ret;
} }
...@@ -379,7 +379,14 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data, ...@@ -379,7 +379,14 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
case SIOCBRDELIF: case SIOCBRDELIF:
if (!netif_device_present(dev)) if (!netif_device_present(dev))
return -ENODEV; return -ENODEV;
return br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL); if (!netif_is_bridge_master(dev))
return -EOPNOTSUPP;
dev_hold(dev);
rtnl_unlock();
err = br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
dev_put(dev);
rtnl_lock();
return err;
case SIOCSHWTSTAMP: case SIOCSHWTSTAMP:
err = net_hwtstamp_validate(ifr); err = net_hwtstamp_validate(ifr);
......
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