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
2121 #define GENL_CMD_CAP_DO 0x02
2222 #define GENL_CMD_CAP_DUMP 0x04
2323 #define GENL_CMD_CAP_HASPOL 0x08
24+#define GENL_UNS_ADMIN_PERM 0x10
2425
2526 /*
2627 * 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
580580 !netlink_capable(skb, CAP_NET_ADMIN))
581581 return -EPERM;
582582
583+ if ((ops->flags & GENL_UNS_ADMIN_PERM) &&
584+ !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
585+ return -EPERM;
586+
583587 if ((nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP) {
584588 int rc;
585589
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
654654
655655 static const struct genl_ops dp_packet_genl_ops[] = {
656656 { .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. */
658658 .policy = packet_policy,
659659 .doit = ovs_packet_cmd_execute
660660 }
@@ -1391,12 +1391,12 @@ static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { · 730 unmodified lines
13911391
13921392 static const struct genl_ops dp_flow_genl_ops[] = {
13931393 { .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. */
13951395 .policy = flow_policy,
13961396 .doit = ovs_flow_cmd_new
13971397 },
13981398 { .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. */
14001400 .policy = flow_policy,
14011401 .doit = ovs_flow_cmd_del
14021402 },
@@ -1407,7 +1407,7 @@ static const struct genl_ops dp_flow_genl_ops[] = { · 4 unmodified lines
14071407 .dumpit = ovs_flow_cmd_dump
14081408 },
14091409 { .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. */
14111411 .policy = flow_policy,
14121412 .doit = ovs_flow_cmd_set,
14131413 },
@@ -1777,12 +1777,12 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { · 363 unmodified lines
17771777
17781778 static const struct genl_ops dp_datapath_genl_ops[] = {
17791779 { .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. */
17811781 .policy = datapath_policy,
17821782 .doit = ovs_dp_cmd_new
17831783 },
17841784 { .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. */
17861786 .policy = datapath_policy,
17871787 .doit = ovs_dp_cmd_del
17881788 },
@@ -1793,7 +1793,7 @@ static const struct genl_ops dp_datapath_genl_ops[] = { · 4 unmodified lines
17931793 .dumpit = ovs_dp_cmd_dump
17941794 },
17951795 { .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. */
17971797 .policy = datapath_policy,
17981798 .doit = ovs_dp_cmd_set,
17991799 },
@@ -2158,12 +2158,12 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { · 358 unmodified lines
21582158
21592159 static const struct genl_ops dp_vport_genl_ops[] = {
21602160 { .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. */
21622162 .policy = vport_policy,
21632163 .doit = ovs_vport_cmd_new
21642164 },
21652165 { .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. */
21672167 .policy = vport_policy,
21682168 .doit = ovs_vport_cmd_del
21692169 },
@@ -2174,7 +2174,7 @@ static const struct genl_ops dp_vport_genl_ops[] = { · 4 unmodified lines
21742174 .dumpit = ovs_vport_cmd_dump
21752175 },
21762176 { .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. */
21782178 .policy = vport_policy,
21792179 .doit = ovs_vport_cmd_set,
21802180 },

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