From: Julian Orth <ju.orth@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: [PATCH v2 08/10] netlink: require CAP_NET_ADMIN for socket changes
Date: Sun, 9 Sep 2018 17:14:00 +0200 [thread overview]
Message-ID: <20180909151402.6033-9-ju.orth@gmail.com> (raw)
In-Reply-To: <20180909151402.6033-1-ju.orth@gmail.com>
The calling process must have CAP_NET_ADMIN in the user namespace of the
transit namespace.
---
src/netlink.c | 11 +++++++++++
src/uapi/wireguard.h | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/src/netlink.c b/src/netlink.c
index f74c23a..e7f8c69 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -304,6 +304,13 @@ static int get_device_done(struct netlink_callback *cb)
return 0;
}
+static int test_net_capable(struct net *net)
+{
+ if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
+ return -EPERM;
+ return 0;
+}
+
static int set_socket(struct wireguard_device *wg, struct nlattr **attrs)
{
struct wireguard_peer *peer;
@@ -329,6 +336,10 @@ static int set_socket(struct wireguard_device *wg, struct nlattr **attrs)
else
port = wg->incoming_port;
+ ret = test_net_capable(net ? : wg->transit_net);
+ if (ret)
+ goto out;
+
if (wg->incoming_port == port && (!net || wg->transit_net == net))
goto out;
diff --git a/src/uapi/wireguard.h b/src/uapi/wireguard.h
index 21bf92e..40d800f 100644
--- a/src/uapi/wireguard.h
+++ b/src/uapi/wireguard.h
@@ -77,6 +77,10 @@
* must be provided. All other top-level items are optional. At most one of
* WGDEVICE_A_TRANSIT_NETNS_PID and WGDEVICE_A_TRANSIT_NETNS_FD may be provided.
*
+ * If WGDEVICE_A_TRANSIT_NETNS_PID/FD and/or WGDEVICE_A_LISTEN_PORT are
+ * provided, then the calling process must have CAP_NET_ADMIN the transit
+ * namespace.
+ *
*
* WGDEVICE_A_IFINDEX: NLA_U32
* WGDEVICE_A_IFNAME: NLA_NUL_STRING, maxlen IFNAMESIZ - 1
--
2.18.0
next prev parent reply other threads:[~2018-09-09 15:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-09 15:13 [PATCH v2 00/10] Allow changing the transit namespace Julian Orth
2018-09-09 15:13 ` [PATCH v2 01/10] device: protect socket_init with device_update_lock Julian Orth
2018-09-09 15:13 ` [PATCH v2 02/10] device: rename creating_net to transit_net Julian Orth
2018-09-09 15:13 ` [PATCH v2 03/10] device: store a copy of the device net Julian Orth
2018-09-09 15:13 ` [PATCH v2 04/10] socket: allow modification of transit_net Julian Orth
2018-09-09 15:13 ` [PATCH v2 05/10] netlink: allow modification of transit net Julian Orth
2018-09-09 15:13 ` [PATCH v2 06/10] tools: " Julian Orth
2018-09-09 15:13 ` [PATCH v2 07/10] tests: add test for transit-net Julian Orth
2018-09-09 15:14 ` Julian Orth [this message]
2018-09-09 15:14 ` [PATCH v2 09/10] netlink: allow bypassing CAP_NET_ADMIN Julian Orth
2018-09-09 15:14 ` [PATCH v2 10/10] tools: add support for transit-credentials Julian Orth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180909151402.6033-9-ju.orth@gmail.com \
--to=ju.orth@gmail.com \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).