Skip to contentSkip to conversation

IB/sa: Restrict SA Netlink to admin users

PATCH Superseded [email protected] 4 participants 7 messages Aug 6, 2015 – Aug 11, 2015 5 messages not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/sa: Restrict SA Netlink to admin users

From: Ira Weiny <[email protected]>

The recently added SA Netlink service requires admin privileges to receive kernel requests. This is only partially sufficient to protect the kernel from malicious users. This patch fixes two issues.

1) Path responses from user space could be spoofed if the sequence number was properly guessed.
2) The set timeout request message could be issued by any user.

Ignore these messages if not submitted by an admin user.

Fixes 6619209af36c ("IB/sa: Route SA pathrecord query through netlink")

---

Doug let me know if you would prefer that I get Kaike to squash this into the original patch.

 drivers/infiniband/core/sa_query.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/infiniband/core/sa_query.c +17 -0
index 70ceec4df02a..52be6d71b2f4 100644
@@ -49,6 +49,7 @@
 #include <net/netlink.h>
 #include <uapi/rdma/ib_user_sa.h>
 #include <rdma/ib_marshall.h>
+#include <net/sock.h>
 #include "sa.h"
 
 MODULE_AUTHOR("Roland Dreier");
@@ -699,6 +700,12 @@ static int ib_nl_handle_set_timeout(struct sk_buff *skb,
 	struct nlattr *tb[LS_NLA_TYPE_MAX + 1];
 	int ret;
 
+	if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) {
+		pr_warn_ratelimited("SA netlink: invalid perm for set timeout: `%s'.\n",
+				    current->comm);
+		return -EPERM;
+	}
+
 	ret = nla_parse(tb, LS_NLA_TYPE_MAX, nlmsg_data(nlh), nlmsg_len(nlh),
 			NULL);
 	attr = (const struct nlattr *)tb[LS_NLA_TYPE_TIMEOUT];
@@ -706,6 +713,9 @@ static int ib_nl_handle_set_timeout(struct sk_buff *skb,
 		goto settimeout_out;
 
 	timeout = *(int *) nla_data(attr);
+
+	pr_info("SA netlink: timeout: %d\n", timeout);
+
 	if (timeout < IB_SA_LOCAL_SVC_TIMEOUT_MIN)
 		timeout = IB_SA_LOCAL_SVC_TIMEOUT_MIN;
 	if (timeout > IB_SA_LOCAL_SVC_TIMEOUT_MAX)
@@ -754,6 +764,12 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 	int found = 0;
 	int ret;
 
+	if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) {
+		pr_warn_ratelimited("SA netlink: invalid perm for response: `%s'.\n",
+				    current->comm);
+		return -EPERM;
+	}
+
 	spin_lock_irqsave(&ib_nl_request_lock, flags);
 	list_for_each_entry(query, &ib_nl_request_list, list) {
 		/*
@@ -770,6 +786,7 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 
 	if (!found) {
 		spin_unlock_irqrestore(&ib_nl_request_lock, flags);
+		pr_err_ratelimited("SA netlink: got unmatched response\n");
 		goto resp_out;
 	}
 
Signature · 6 lines
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive

drivers/infiniband/core/sa_query.c static int ib_nl_handle_resolve_resp(struct sk_buff *skb, · line 775

Quoted 13 lines · On 07/08/2015 00:08, [email protected] wrote:
drivers/infiniband/core/sa_query.c +6 -0
@@ -754,6 +764,12 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 	int found = 0;
 	int ret;
 
+	if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) {
+		pr_warn_ratelimited("SA netlink: invalid perm for response: `%s'.\n",
+				    current->comm);
+		return -EPERM;
+	}
+
 	spin_lock_irqsave(&ib_nl_request_lock, flags);
 	list_for_each_entry(query, &ib_nl_request_list, list) {
 		/*

Maybe I'm missing something, but I thought you would want to check the capability with init_user_ns as the target, since the SA queries will affect all namespaces, not just the one that sent the response.

Haggai
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
In reply to a message not in the archive
Quoted 5 lines · Haggai Eran
Quoted 4 lines · On 07/08/2015 00:08, [email protected] wrote:
drivers/infiniband/core/sa_query.c +0 -0
@@ -754,6 +764,12 @@ static int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 	int found = 0;
 	int ret;
 
Quoted 13 lines

drivers/infiniband/core/sa_query.c static int ib_nl_handle_resolve_resp(struct sk_buff *skb, · line 775

Quoted 9 lines
drivers/infiniband/core/sa_query.c +6 -0
+	if (!ns_capable(sock_net(skb->sk)->user_ns, CAP_NET_ADMIN)) {
+		pr_warn_ratelimited("SA netlink: invalid perm for response: `%s'.\n",
+				    current->comm);
+		return -EPERM;
+	}
+
 	spin_lock_irqsave(&ib_nl_request_lock, flags);
 	list_for_each_entry(query, &ib_nl_request_list, list) {
 		/*

Maybe I'm missing something, but I thought you would want to check the capability with init_user_ns as the target, since the SA queries will affect all namespaces, not just the one that sent the response.

I'm not an expert in namespaces but these checks are only concerned with the network namespace of the process which is acting as an SA proxy (via netlink).

AFAIK a user can't elevate a network namespace that the SA proxy is running in. While you are correct that this data does affect all namespaces who are using a particular port, this does not matter. The SA data for that port is applicable no matter which network namespace an application running on that port is in.

Furthermore, the check in netlink_bind also uses the socket namespace to restrict the use of multicast. This plus my checks should allow an admin to place the SA proxy (ibacm in our test cases) in an alternate network namespace if they so desire. But this is independent to the namespace which may be used for data applications.

All that said, I did find the netlink_net_capable helper call which I should have used instead. I'll work up a v2 today.

Thanks,
Ira

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to a message not in the archive
Quoted 5 lines · ira.weiny

Furthermore, the check in netlink_bind also uses the socket namespace to restrict the use of multicast. This plus my checks should allow an admin to place the SA proxy (ibacm in our test cases) in an alternate network namespace if they so desire. But this is independent to the namespace which may be used for data applications.

I think Haggai is on to something, there is certainly a problem here, that netlink_bind will let a namespace subscribe is a certainly a problem for what Haggai is working on.

For now, I think, only root (or CAP_ whatever) in the init namespace should have access to this feature. Not sure how to check that.

Even allowing a namespace to subscribe is problematic because it will cause timeouts to hit.. Not sure what to do about that..

Also, why the incremental patch? The original isn't ready for mainline without the message validation stuff..

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
In reply to a message not in the archive
Quoted 15 lines

From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Jason Gunthorpe
Sent: Tuesday, August 11, 2015 1:38 AM
To: Weiny, Ira
Cc: Haggai Eran; [email protected]; [email protected]
Subject: Re: [PATCH] IB/sa: Restrict SA Netlink to admin users

Quoted 5 lines · ira.weiny

Furthermore, the check in netlink_bind also uses the socket namespace to restrict the use of multicast. This plus my checks should allow an admin to place the SA proxy (ibacm in our test cases) in an alternate network namespace if they so desire. But this is independent to the namespace which may be used for data applications.

Quoted 6 lines

I think Haggai is on to something, there is certainly a problem here, that netlink_bind will let a namespace subscribe is a certainly a problem for what Haggai is working on.

For now, I think, only root (or CAP_ whatever) in the init namespace should have access to this feature. Not sure how to check that.

netlink_capable(skb, CAP_NET_ADMIN) will do the trick.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#11 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jason Gunthorpe
Quoted 5 lines · ira.weiny

Furthermore, the check in netlink_bind also uses the socket namespace to restrict the use of multicast. This plus my checks should allow an admin to place the SA proxy (ibacm in our test cases) in an alternate network namespace if they so desire. But this is independent to the namespace which may be used for data applications.

I think Haggai is on to something, there is certainly a problem here, that netlink_bind will let a namespace subscribe is a certainly a problem for what Haggai is working on.

Ok, After thinking about this more I agree. Haggai has a point about the arp tables. Like I said I'm not a namespace expert.

Quoted 3 lines

For now, I think, only root (or CAP_ whatever) in the init namespace should have access to this feature. Not sure how to check that.

For these 2 checks it is easy to change to netlink_capable instead of netlink_net_capable.

Quoted 3 lines

Even allowing a namespace to subscribe is problematic because it will cause timeouts to hit.. Not sure what to do about that..

Ok, I look into how to deal with the netlink_bind. I _think_ this may require the RDMA netlink to provide a custom bind call. :-(

Quoted 3 lines

Also, why the incremental patch? The original isn't ready for mainline without the message validation stuff..

Mainly because Kaike was on vacation and I was not sure what Doug would prefer. Kaike and I have discussed a couple of changes he had queued up so we will need a v9 so we will merge this into his next v9 submission.

Ira

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#10 lore raw
In reply to a message not in the archive
Quoted 15 lines · Kaike
Quoted 15 lines

From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Jason Gunthorpe
Sent: Tuesday, August 11, 2015 1:38 AM
To: Weiny, Ira
Cc: Haggai Eran; [email protected]; [email protected]
Subject: Re: [PATCH] IB/sa: Restrict SA Netlink to admin users

Quoted 5 lines · ira.weiny

Furthermore, the check in netlink_bind also uses the socket namespace to restrict the use of multicast. This plus my checks should allow an admin to place the SA proxy (ibacm in our test cases) in an alternate network namespace if they so desire. But this is independent to the namespace which may be used for data applications.

Quoted 8 lines
Quoted 6 lines

I think Haggai is on to something, there is certainly a problem here, that netlink_bind will let a namespace subscribe is a certainly a problem for what Haggai is working on.

For now, I think, only root (or CAP_ whatever) in the init namespace should have access to this feature. Not sure how to check that.

netlink_capable(skb, CAP_NET_ADMIN) will do the trick.

For these calls yes. For the bind call I think we need to investigate more.

Ira

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html