ovpn: support operations on interfaces in foreign netns
Subsystems (5)
PATCH 1/2 ovpn: support operations on interfaces in foreign netns
ovpn currently looks up the target interface in the network namespace associated with the netlink socket. This prevents a userspace process from controlling an ovpn interface located in another namespace.
Add the optional OVPN_A_TARGET_NETNSID attribute. When present, resolve the namespace ID relative to the netlink socket's namespace and perform the interface lookup there. When absent, preserve the existing lookup behavior.
Allow the attribute in all peer and key request policies, including peer dump requests.
--- Documentation/netlink/specs/ovpn.yaml | 26 ++++++++++++++++ drivers/net/ovpn/netlink-gen.c | 45 ++++++++++++++++----------- drivers/net/ovpn/netlink.c | 16 ++++++++++ include/uapi/linux/ovpn.h | 1 + 4 files changed, 70 insertions(+), 18 deletions(-)
Documentation/netlink/specs/ovpn.yaml +26 -0
@@ -337,12 +337,19 @@ attribute-sets: type: nest doc: Peer specific cipher configuration nested-attributes: keyconf + - + name: target-netnsid + type: s32 + doc: >- + ID of the network namespace containing the ovpn interface to operate on - name: ovpn-peer-new-input subset-of: ovpn attributes: - name: ifindex + - + name: target-netnsid - name: peer nested-attributes: peer-new-input
@@ -352,6 +359,8 @@ attribute-sets: attributes: - name: ifindex + - + name: target-netnsid - name: peer nested-attributes: peer-set-input
@@ -361,6 +370,8 @@ attribute-sets: attributes: - name: ifindex + - + name: target-netnsid - name: peer nested-attributes: peer-del-input
@@ -370,6 +381,8 @@ attribute-sets: attributes: - name: ifindex + - + name: target-netnsid - name: keyconf nested-attributes: keyconf-get
@@ -379,6 +392,8 @@ attribute-sets: attributes: - name: ifindex + - + name: target-netnsid - name: keyconf nested-attributes: keyconf-swap-input
@@ -388,6 +403,8 @@ attribute-sets: attributes: - name: ifindex + - + name: target-netnsid - name: keyconf nested-attributes: keyconf-del-input
@@ -405,6 +422,7 @@ operations: request: attributes: - ifindex + - target-netnsid - peer - name: peer-set
@@ -417,6 +435,7 @@ operations: request: attributes: - ifindex + - target-netnsid - peer - name: peer-get
@@ -429,6 +448,7 @@ operations: request: attributes: - ifindex + - target-netnsid - peer reply: attributes:
@@ -437,6 +457,7 @@ operations: request: attributes: - ifindex + - target-netnsid reply: attributes: - peer
@@ -451,6 +472,7 @@ operations: request: attributes: - ifindex + - target-netnsid - peer - name: peer-del-ntf
@@ -469,6 +491,7 @@ operations: request: attributes: - ifindex + - target-netnsid - keyconf - name: key-get
@@ -481,6 +504,7 @@ operations: request: attributes: - ifindex + - target-netnsid - keyconf reply: attributes:
@@ -496,6 +520,7 @@ operations: request: attributes: - ifindex + - target-netnsid - keyconf - name: key-swap-ntf
@@ -515,6 +540,7 @@ operations: request: attributes: - ifindex + - target-netnsid - keyconf -
drivers/net/ovpn/netlink-gen.c +27 -18
145 lines not on this page · raw message
drivers/net/ovpn/netlink.c +16 -0
@@ -38,6 +38,7 @@ ovpn_get_dev_from_attrs(struct net *net, const struct genl_info *info, {struct ovpn_priv *ovpn;struct net_device *dev; +struct net *target_net =NULL ;int ifindex;if (GENL_REQ_ATTR_CHECK (info,OVPN_A_IFINDEX ))
@@ -45,12 +46,25 @@ ovpn_get_dev_from_attrs(struct net *net, const struct genl_info *info, ifindex =nla_get_u32 (info->attrs[OVPN_A_IFINDEX ]); +if (info->attrs[OVPN_A_TARGET_NETNSID ]) { + target_net =get_net_ns_by_id (net,nla_get_s32 (info->attrs[OVPN_A_TARGET_NETNSID ])); +if (!target_net) { +NL_SET_ERR_MSG_MOD (info->extack, +"invalid target network namespace ID" ); +NL_SET_BAD_ATTR (info->extack, + info->attrs[OVPN_A_TARGET_NETNSID ]); +return ERR_PTR (-EINVAL ); + } + net = target_net; + } +rcu_read_lock (); dev =dev_get_by_index_rcu (net, ifindex);if (!dev) {rcu_read_unlock ();NL_SET_ERR_MSG_MOD (info->extack,"ifindex does not match any interface" ); +put_net (target_net);return ERR_PTR (-ENODEV ); }
@@ -59,12 +73,14 @@ ovpn_get_dev_from_attrs(struct net *net, const struct genl_info *info,NL_SET_ERR_MSG_MOD (info->extack,"specified interface is not ovpn" );NL_SET_BAD_ATTR (info->extack, info->attrs[OVPN_A_IFINDEX ]); +put_net (target_net);return ERR_PTR (-EINVAL ); } ovpn =netdev_priv (dev);netdev_hold (dev, tracker,GFP_ATOMIC );rcu_read_unlock (); +put_net (target_net);return ovpn; }
include/uapi/linux/ovpn.h +1 -0
@@ -85,6 +85,7 @@ enum {OVPN_A_IFINDEX =1 ,OVPN_A_PEER ,OVPN_A_KEYCONF , +OVPN_A_TARGET_NETNSID , __OVPN_A_MAX,OVPN_A_MAX = (__OVPN_A_MAX -1 )
Signature · 8 lines
2.43.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH 2/2 selftests: ovpn: test operations in a foreign netns
Extend ovpn-cli with -n to resolve an interface in a named network namespace and include OVPN_A_TARGET_NETNSID in peer and key requests.
Test peer get and dump requests issued outside the interface network namespace, including local lookup and invalid NSID failures.
--- tools/testing/selftests/net/ovpn/Makefile | 1 + tools/testing/selftests/net/ovpn/ovpn-cli.c | 266 +++++++++++++++++- .../testing/selftests/net/ovpn/test-netns.sh | 81 ++++++ 3 files changed, 337 insertions(+), 11 deletions(-) create mode 100755 tools/testing/selftests/net/ovpn/test-netns.sh
tools/testing/selftests/net/ovpn/Makefile +1 -0
@@ -39,6 +39,7 @@ TEST_PROGS := \ test-float.sh \ test-large-mtu.sh \ test-mark.sh \ + test-netns.sh \ test-symmetric-id-float.sh \ test-symmetric-id-tcp.sh \ test-symmetric-id.sh \
tools/testing/selftests/net/ovpn/ovpn-cli.c +255 -11
359 lines not on this page · raw message
tools/testing/selftests/net/ovpn/test-netns.sh new file +81 -0
81 lines not on this page · raw message
Signature · 8 lines
2.43.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Re: [Openvpn-devel] [PATCH ovpn net-next 2/2] selftests: ovpn: test operations in a foreign netns
Hi,
Quoted 7 lines · Marco Baffo
Extend ovpn-cli with -n to resolve an interface in a named network namespace and include
OVPN_A_TARGET_NETNSIDin peer and key requests.Test peer get and dump requests issued outside the interface network namespace, including local lookup and invalid NSID failures.
Signed-off-by Marco Baffo <[email protected]>
As discussed offline, this batch will be resent with the following modifications:
* patch 1/2 - no changes
* patch 2/2 - modify existing tests rather than introducing a totally new test
* patch 3/2 - add a new patch that modifies userspace notification by adding the TARGET NETNS ID and disambiguate the carried ifindex.
Regards,
Signature · 8 lines
Antonio Quartulli _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel