History

openvswitch: allow management from inside user namespaces

Operations with the GENL_ADMIN_PERM flag fail permissions checks because this flag means we call netlink_capable, which uses the init user ns. Instead, let's introduce a new flag, GENL_UNS_ADMIN_PERM for operations which should be allowed inside a user namespace. The motivation for this is to be able to run openvswitch in unprivileged containers. I've tested this and it seems to work, but I really have no idea about the security consequences of this patch, so thoughts would be much appreciated. v2: use the GENL_UNS_ADMIN_PERM flag instead of a check in each function v3: use separate ifs for UNS_ADMIN_PERM and ADMIN_PERM, instead of one massive one

Tycho Andersen committed 10 years ago

Commit 4a926021 parent 4456ed03 files · +15 −10Browse files

Unified · Split

3 files
  1. include/uapi/linux/genetlink.h +1 −0
  2. net/netlink/genetlink.c +4 −0
  3. net/openvswitch/datapath.c +10 −10
include/uapi/linux/genetlink.h+1−0
@@ -21,6 +21,7 @@ struct genlmsghdr { · 20 unmodified lines
21#define GENL_CMD_CAP_DO 0x0221#define GENL_CMD_CAP_DO 0x02
22#define GENL_CMD_CAP_DUMP 0x0422#define GENL_CMD_CAP_DUMP 0x04
23#define GENL_CMD_CAP_HASPOL 0x0823#define GENL_CMD_CAP_HASPOL 0x08
24#define GENL_UNS_ADMIN_PERM 0x10
24 25
25/*26/*
26 * List of reserved static generic netlink identifiers:27 * List of reserved static generic netlink identifiers:
net/netlink/genetlink.c+4−0
@@ -580,6 +580,10 @@ static int genl_family_rcv_msg(struct genl_family *family, · 579 unmodified lines
580 !netlink_capable(skb, CAP_NET_ADMIN))580 !netlink_capable(skb, CAP_NET_ADMIN))
581 return -EPERM;581 return -EPERM;
582 582
583 if ((ops->flags & GENL_UNS_ADMIN_PERM) &&
584 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
585 return -EPERM;
586
583 if ((nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP) {587 if ((nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP) {
584 int rc;588 int rc;
585 589
net/openvswitch/datapath.c+10−10
@@ -654,7 +654,7 @@ static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = { · 653 unmodified lines
654 654
655static const struct genl_ops dp_packet_genl_ops[] = {655static const struct genl_ops dp_packet_genl_ops[] = {
656 { .cmd = OVS_PACKET_CMD_EXECUTE,656 { .cmd = OVS_PACKET_CMD_EXECUTE,
657 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */657 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
658 .policy = packet_policy,658 .policy = packet_policy,
659 .doit = ovs_packet_cmd_execute659 .doit = ovs_packet_cmd_execute
660 }660 }
@@ -1391,12 +1391,12 @@ static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { · 730 unmodified lines
1391 1391
1392static const struct genl_ops dp_flow_genl_ops[] = {1392static const struct genl_ops dp_flow_genl_ops[] = {
1393 { .cmd = OVS_FLOW_CMD_NEW,1393 { .cmd = OVS_FLOW_CMD_NEW,
1394 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1394 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1395 .policy = flow_policy,1395 .policy = flow_policy,
1396 .doit = ovs_flow_cmd_new1396 .doit = ovs_flow_cmd_new
1397 },1397 },
1398 { .cmd = OVS_FLOW_CMD_DEL,1398 { .cmd = OVS_FLOW_CMD_DEL,
1399 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1399 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1400 .policy = flow_policy,1400 .policy = flow_policy,
1401 .doit = ovs_flow_cmd_del1401 .doit = ovs_flow_cmd_del
1402 },1402 },
@@ -1407,7 +1407,7 @@ static const struct genl_ops dp_flow_genl_ops[] = { · 4 unmodified lines
1407 .dumpit = ovs_flow_cmd_dump1407 .dumpit = ovs_flow_cmd_dump
1408 },1408 },
1409 { .cmd = OVS_FLOW_CMD_SET,1409 { .cmd = OVS_FLOW_CMD_SET,
1410 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1410 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1411 .policy = flow_policy,1411 .policy = flow_policy,
1412 .doit = ovs_flow_cmd_set,1412 .doit = ovs_flow_cmd_set,
1413 },1413 },
@@ -1777,12 +1777,12 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { · 363 unmodified lines
1777 1777
1778static const struct genl_ops dp_datapath_genl_ops[] = {1778static const struct genl_ops dp_datapath_genl_ops[] = {
1779 { .cmd = OVS_DP_CMD_NEW,1779 { .cmd = OVS_DP_CMD_NEW,
1780 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1780 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1781 .policy = datapath_policy,1781 .policy = datapath_policy,
1782 .doit = ovs_dp_cmd_new1782 .doit = ovs_dp_cmd_new
1783 },1783 },
1784 { .cmd = OVS_DP_CMD_DEL,1784 { .cmd = OVS_DP_CMD_DEL,
1785 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1785 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1786 .policy = datapath_policy,1786 .policy = datapath_policy,
1787 .doit = ovs_dp_cmd_del1787 .doit = ovs_dp_cmd_del
1788 },1788 },
@@ -1793,7 +1793,7 @@ static const struct genl_ops dp_datapath_genl_ops[] = { · 4 unmodified lines
1793 .dumpit = ovs_dp_cmd_dump1793 .dumpit = ovs_dp_cmd_dump
1794 },1794 },
1795 { .cmd = OVS_DP_CMD_SET,1795 { .cmd = OVS_DP_CMD_SET,
1796 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */1796 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1797 .policy = datapath_policy,1797 .policy = datapath_policy,
1798 .doit = ovs_dp_cmd_set,1798 .doit = ovs_dp_cmd_set,
1799 },1799 },
@@ -2158,12 +2158,12 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { · 358 unmodified lines
2158 2158
2159static const struct genl_ops dp_vport_genl_ops[] = {2159static const struct genl_ops dp_vport_genl_ops[] = {
2160 { .cmd = OVS_VPORT_CMD_NEW,2160 { .cmd = OVS_VPORT_CMD_NEW,
2161 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */2161 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2162 .policy = vport_policy,2162 .policy = vport_policy,
2163 .doit = ovs_vport_cmd_new2163 .doit = ovs_vport_cmd_new
2164 },2164 },
2165 { .cmd = OVS_VPORT_CMD_DEL,2165 { .cmd = OVS_VPORT_CMD_DEL,
2166 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */2166 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2167 .policy = vport_policy,2167 .policy = vport_policy,
2168 .doit = ovs_vport_cmd_del2168 .doit = ovs_vport_cmd_del
2169 },2169 },
@@ -2174,7 +2174,7 @@ static const struct genl_ops dp_vport_genl_ops[] = { · 4 unmodified lines
2174 .dumpit = ovs_vport_cmd_dump2174 .dumpit = ovs_vport_cmd_dump
2175 },2175 },
2176 { .cmd = OVS_VPORT_CMD_SET,2176 { .cmd = OVS_VPORT_CMD_SET,
2177 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */2177 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2178 .policy = vport_policy,2178 .policy = vport_policy,
2179 .doit = ovs_vport_cmd_set,2179 .doit = ovs_vport_cmd_set,
2180 },2180 },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t