Commit dfc47ef8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

net: Push capable(CAP_NET_ADMIN) into the rtnl methods

- In rtnetlink_rcv_msg convert the capable(CAP_NET_ADMIN) check
  to ns_capable(net->user-ns, CAP_NET_ADMIN).  Allowing unprivileged
  users to make netlink calls to modify their local network
  namespace.

- In the rtnetlink doit methods add capable(CAP_NET_ADMIN) so
  that calls that are not safe for unprivileged users are still
  protected.

Later patches will remove the extra capable calls from methods
that are safe for unprivilged users.
Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 464dc801
...@@ -240,6 +240,9 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh) ...@@ -240,6 +240,9 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
struct nlattr *tb[IFLA_BRPORT_MAX]; struct nlattr *tb[IFLA_BRPORT_MAX];
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
protinfo = nlmsg_find_attr(nlh, sizeof(*ifm), IFLA_PROTINFO); protinfo = nlmsg_find_attr(nlh, sizeof(*ifm), IFLA_PROTINFO);
......
...@@ -751,6 +751,9 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -751,6 +751,9 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,
struct cgw_job *gwj; struct cgw_job *gwj;
int err = 0; int err = 0;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (nlmsg_len(nlh) < sizeof(*r)) if (nlmsg_len(nlh) < sizeof(*r))
return -EINVAL; return -EINVAL;
...@@ -839,6 +842,9 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -839,6 +842,9 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct can_can_gw ccgw; struct can_can_gw ccgw;
int err = 0; int err = 0;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (nlmsg_len(nlh) < sizeof(*r)) if (nlmsg_len(nlh) < sizeof(*r))
return -EINVAL; return -EINVAL;
......
...@@ -275,6 +275,9 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) ...@@ -275,6 +275,9 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
struct nlattr *tb[FRA_MAX+1]; struct nlattr *tb[FRA_MAX+1];
int err = -EINVAL, unresolved = 0; int err = -EINVAL, unresolved = 0;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh)))
goto errout; goto errout;
...@@ -424,6 +427,9 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) ...@@ -424,6 +427,9 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
struct nlattr *tb[FRA_MAX+1]; struct nlattr *tb[FRA_MAX+1];
int err = -EINVAL; int err = -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh))) if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*frh)))
goto errout; goto errout;
......
...@@ -1620,6 +1620,9 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1620,6 +1620,9 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct net_device *dev = NULL; struct net_device *dev = NULL;
int err = -EINVAL; int err = -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
ASSERT_RTNL(); ASSERT_RTNL();
if (nlmsg_len(nlh) < sizeof(*ndm)) if (nlmsg_len(nlh) < sizeof(*ndm))
goto out; goto out;
...@@ -1684,6 +1687,9 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1684,6 +1687,9 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct net_device *dev = NULL; struct net_device *dev = NULL;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
ASSERT_RTNL(); ASSERT_RTNL();
err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL); err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
if (err < 0) if (err < 0)
...@@ -1962,6 +1968,9 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1962,6 +1968,9 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct nlattr *tb[NDTA_MAX+1]; struct nlattr *tb[NDTA_MAX+1];
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ndtmsg), tb, NDTA_MAX, err = nlmsg_parse(nlh, sizeof(*ndtmsg), tb, NDTA_MAX,
nl_neightbl_policy); nl_neightbl_policy);
if (err < 0) if (err < 0)
......
...@@ -1547,6 +1547,9 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1547,6 +1547,9 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct nlattr *tb[IFLA_MAX+1]; struct nlattr *tb[IFLA_MAX+1];
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -1590,6 +1593,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1590,6 +1593,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
int err; int err;
LIST_HEAD(list_kill); LIST_HEAD(list_kill);
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
if (err < 0) if (err < 0)
return err; return err;
...@@ -1720,6 +1726,9 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1720,6 +1726,9 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct nlattr *linkinfo[IFLA_INFO_MAX+1]; struct nlattr *linkinfo[IFLA_INFO_MAX+1];
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
replay: replay:
#endif #endif
...@@ -2057,6 +2066,9 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -2057,6 +2066,9 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
u8 *addr; u8 *addr;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL); err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
if (err < 0) if (err < 0)
return err; return err;
...@@ -2123,6 +2135,9 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -2123,6 +2135,9 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
int err = -EINVAL; int err = -EINVAL;
__u8 *addr; __u8 *addr;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (nlmsg_len(nlh) < sizeof(*ndm)) if (nlmsg_len(nlh) < sizeof(*ndm))
return -EINVAL; return -EINVAL;
...@@ -2488,7 +2503,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2488,7 +2503,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
sz_idx = type>>2; sz_idx = type>>2;
kind = type&3; kind = type&3;
if (kind != 2 && !capable(CAP_NET_ADMIN)) if (kind != 2 && !ns_capable(net->user_ns, CAP_NET_ADMIN))
return -EPERM; return -EPERM;
if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
......
...@@ -1662,6 +1662,9 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -1662,6 +1662,9 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct nlmsghdr *reply_nlh = NULL; struct nlmsghdr *reply_nlh = NULL;
const struct reply_func *fn; const struct reply_func *fn;
if ((nlh->nlmsg_type == RTM_SETDCB) && !capable(CAP_NET_ADMIN))
return -EPERM;
if (!net_eq(net, &init_net)) if (!net_eq(net, &init_net))
return -EINVAL; return -EINVAL;
......
...@@ -573,6 +573,9 @@ static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -573,6 +573,9 @@ static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct dn_ifaddr __rcu **ifap; struct dn_ifaddr __rcu **ifap;
int err = -EINVAL; int err = -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!net_eq(net, &init_net)) if (!net_eq(net, &init_net))
goto errout; goto errout;
...@@ -614,6 +617,9 @@ static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -614,6 +617,9 @@ static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct dn_ifaddr *ifa; struct dn_ifaddr *ifa;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!net_eq(net, &init_net)) if (!net_eq(net, &init_net))
return -EINVAL; return -EINVAL;
......
...@@ -520,6 +520,9 @@ static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void * ...@@ -520,6 +520,9 @@ static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *
struct rtattr **rta = arg; struct rtattr **rta = arg;
struct rtmsg *r = NLMSG_DATA(nlh); struct rtmsg *r = NLMSG_DATA(nlh);
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!net_eq(net, &init_net)) if (!net_eq(net, &init_net))
return -EINVAL; return -EINVAL;
...@@ -540,6 +543,9 @@ static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void * ...@@ -540,6 +543,9 @@ static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *
struct rtattr **rta = arg; struct rtattr **rta = arg;
struct rtmsg *r = NLMSG_DATA(nlh); struct rtmsg *r = NLMSG_DATA(nlh);
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!net_eq(net, &init_net)) if (!net_eq(net, &init_net))
return -EINVAL; return -EINVAL;
......
...@@ -539,6 +539,9 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg ...@@ -539,6 +539,9 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
ASSERT_RTNL(); ASSERT_RTNL();
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -646,6 +649,9 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg ...@@ -646,6 +649,9 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
ASSERT_RTNL(); ASSERT_RTNL();
if (!capable(CAP_NET_ADMIN))
return -EPERM;
ifa = rtm_to_ifaddr(net, nlh); ifa = rtm_to_ifaddr(net, nlh);
if (IS_ERR(ifa)) if (IS_ERR(ifa))
return PTR_ERR(ifa); return PTR_ERR(ifa);
......
...@@ -613,6 +613,9 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar ...@@ -613,6 +613,9 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar
struct fib_table *tb; struct fib_table *tb;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = rtm_to_fib_config(net, skb, nlh, &cfg); err = rtm_to_fib_config(net, skb, nlh, &cfg);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -635,6 +638,9 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar ...@@ -635,6 +638,9 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *ar
struct fib_table *tb; struct fib_table *tb;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = rtm_to_fib_config(net, skb, nlh, &cfg); err = rtm_to_fib_config(net, skb, nlh, &cfg);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -3514,6 +3514,9 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -3514,6 +3514,9 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct in6_addr *pfx; struct in6_addr *pfx;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
if (err < 0) if (err < 0)
return err; return err;
...@@ -3584,6 +3587,9 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -3584,6 +3587,9 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
u8 ifa_flags; u8 ifa_flags;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -425,6 +425,9 @@ static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -425,6 +425,9 @@ static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh,
u32 label; u32 label;
int err = 0; int err = 0;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX, ifal_policy); err = nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX, ifal_policy);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -2446,6 +2446,9 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *a ...@@ -2446,6 +2446,9 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *a
struct fib6_config cfg; struct fib6_config cfg;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = rtm_to_fib6_config(skb, nlh, &cfg); err = rtm_to_fib6_config(skb, nlh, &cfg);
if (err < 0) if (err < 0)
return err; return err;
...@@ -2461,6 +2464,9 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *a ...@@ -2461,6 +2464,9 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *a
struct fib6_config cfg; struct fib6_config cfg;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
err = rtm_to_fib6_config(skb, nlh, &cfg); err = rtm_to_fib6_config(skb, nlh, &cfg);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -70,6 +70,9 @@ static int addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr) ...@@ -70,6 +70,9 @@ static int addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr)
int err; int err;
u8 pnaddr; u8 pnaddr;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -230,6 +233,9 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr) ...@@ -230,6 +233,9 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *attr)
int err; int err;
u8 dst; u8 dst;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
......
...@@ -987,6 +987,9 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -987,6 +987,9 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
u32 portid = skb ? NETLINK_CB(skb).portid : 0; u32 portid = skb ? NETLINK_CB(skb).portid : 0;
int ret = 0, ovr = 0; int ret = 0, ovr = 0;
if ((n->nlmsg_type != RTM_GETACTION) && !capable(CAP_NET_ADMIN))
return -EPERM;
ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL); ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -139,6 +139,8 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -139,6 +139,8 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
int err; int err;
int tp_created = 0; int tp_created = 0;
if ((n->nlmsg_type != RTM_GETTFILTER) && !capable(CAP_NET_ADMIN))
return -EPERM;
replay: replay:
t = nlmsg_data(n); t = nlmsg_data(n);
protocol = TC_H_MIN(t->tcm_info); protocol = TC_H_MIN(t->tcm_info);
......
...@@ -980,6 +980,9 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -980,6 +980,9 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
struct Qdisc *p = NULL; struct Qdisc *p = NULL;
int err; int err;
if ((n->nlmsg_type != RTM_GETQDISC) && !capable(CAP_NET_ADMIN))
return -EPERM;
dev = __dev_get_by_index(net, tcm->tcm_ifindex); dev = __dev_get_by_index(net, tcm->tcm_ifindex);
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
...@@ -1043,6 +1046,9 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -1043,6 +1046,9 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
struct Qdisc *q, *p; struct Qdisc *q, *p;
int err; int err;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
replay: replay:
/* Reinit, just in case something touches this. */ /* Reinit, just in case something touches this. */
tcm = nlmsg_data(n); tcm = nlmsg_data(n);
...@@ -1379,6 +1385,9 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -1379,6 +1385,9 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
u32 qid = TC_H_MAJ(clid); u32 qid = TC_H_MAJ(clid);
int err; int err;
if ((n->nlmsg_type != RTM_GETTCLASS) && !capable(CAP_NET_ADMIN))
return -EPERM;
dev = __dev_get_by_index(net, tcm->tcm_ifindex); dev = __dev_get_by_index(net, tcm->tcm_ifindex);
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
......
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