Skip to contentSkip to conversation

userns: Replace netlink uses of cap_raised with capable.

PATCH In review Eric W. Biederman 4 participants 5 messages Apr 4, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 userns: Replace netlink uses of cap_raised with capable.

In 2009 Philip Reiser notied that a few users of netlink connector interface needed a capability check and added the idiom cap_raised(nsp->eff_cap, CAP_SYS_ADMIN) to a few of them, on the premise that netlink was asynchronous.

In 2011 Patrick McHardy noticed we were being silly because netlink is synchronous and removed eff_cap from the netlink_skb_params and changed the idiom to cap_raised(current_cap(), CAP_SYS_ADMIN).

Looking at those spots with a fresh eye we should be calling capable(CAP_SYS_ADMIN). The only reason I can see for not calling capable is that it once appeared we were not in the same task as the caller which would have made calling capable() impossible.

In the initial user_namespace the only difference between between cap_raised(current_cap(), CAP_SYS_ADMIN) and capable(CAP_SYS_ADMIN) are a few sanity checks and the fact that capable(CAP_SYS_ADMIN) sets PF_SUPERPRIV if we use the capability.

Since we are going to be using root privilege setting PF_SUPERPRIV seems the right thing to do.

The motivation for this that patch is that in a child user namespace cap_raised(current_cap(),...) tests your capabilities with respect to that child user namespace not capabilities in the initial user namespace and thus will allow processes that should be unprivielged to use the kernel services that are only protected with cap_raised(current_cap(),..).

To fix possible user_namespace issues and to just clean up the code replace cap_raised(current_cap(), CAP_SYS_ADMIN) with capable(CAP_SYS_ADMIN).

Cc Patrick McHardy <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Serge E. Hallyn <[email protected]>
Cc Andrew Morgan <[email protected]>
Cc Vasiliy Kulikov <[email protected]>
Cc David Howells <[email protected]>
---
 drivers/block/drbd/drbd_nl.c           |    2 +-
 drivers/md/dm-log-userspace-transfer.c |    2 +-
 drivers/video/uvesafb.c                |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/block/drbd/drbd_nl.c +1 -1
index abfaaca..946166e 100644
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
 		return;
 	}
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
+	if (!capable(CAP_SYS_ADMIN)) {
 		retcode = ERR_PERM;
 		goto fail;
 	}
drivers/md/dm-log-userspace-transfer.c +1 -1
index 1f23e04..08d9a20 100644
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
 {
 	struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	spin_lock(&receiving_list_lock);
drivers/video/uvesafb.c +1 -1
index 260cca7..9f7d27a 100644
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
 	struct uvesafb_task *utask;
 	struct uvesafb_ktask *task;
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	if (msg->seq >= UVESAFB_TASKS_MAX)
Signature · 1 line
1.7.2.5
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric W. Biederman

In 2009 Philip Reiser notied that a few users of netlink connector interface needed a capability check and added the idiom cap_raised(nsp->eff_cap, CAP_SYS_ADMIN) to a few of them, on the premise that netlink was asynchronous.

Quoted 8 lines

In 2011 Patrick McHardy noticed we were being silly because netlink is synchronous and removed eff_cap from the netlink_skb_params and changed the idiom to cap_raised(current_cap(), CAP_SYS_ADMIN).

Looking at those spots with a fresh eye we should be calling capable(CAP_SYS_ADMIN). The only reason I can see for not calling capable is that it once appeared we were not in the same task as the caller which would have made calling capable() impossible.

And (just to make sure) that is now absolutely not the case?

Quoted 15 lines

In the initial user_namespace the only difference between between cap_raised(current_cap(), CAP_SYS_ADMIN) and capable(CAP_SYS_ADMIN) are a few sanity checks and the fact that capable(CAP_SYS_ADMIN) sets PF_SUPERPRIV if we use the capability.

Since we are going to be using root privilege setting PF_SUPERPRIV seems the right thing to do.

The motivation for this that patch is that in a child user namespace cap_raised(current_cap(),...) tests your capabilities with respect to that child user namespace not capabilities in the initial user namespace and thus will allow processes that should be unprivielged to use the kernel services that are only protected with cap_raised(current_cap(),..).

Quoted 7 lines

To fix possible user_namespace issues and to just clean up the code replace cap_raised(current_cap(), CAP_SYS_ADMIN) with capable(CAP_SYS_ADMIN).

Cc Patrick McHardy <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Serge E. Hallyn <[email protected]>

thanks,
-serge

Quoted 51 lines
Cc Andrew Morgan <[email protected]>
Cc Vasiliy Kulikov <[email protected]>
Cc David Howells <[email protected]>
---
 drivers/block/drbd/drbd_nl.c           |    2 +-
 drivers/md/dm-log-userspace-transfer.c |    2 +-
 drivers/video/uvesafb.c                |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/block/drbd/drbd_nl.c +1 -1
index abfaaca..946166e 100644
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
 		return;
 	}
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
+	if (!capable(CAP_SYS_ADMIN)) {
 		retcode = ERR_PERM;
 		goto fail;
 	}
drivers/md/dm-log-userspace-transfer.c +1 -1
index 1f23e04..08d9a20 100644
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
 {
 	struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	spin_lock(&receiving_list_lock);
drivers/video/uvesafb.c +1 -1
index 260cca7..9f7d27a 100644
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
 	struct uvesafb_task *utask;
 	struct uvesafb_ktask *task;
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	if (msg->seq >= UVESAFB_TASKS_MAX)
Signature · 1 line
1.7.2.5
#2 lore raw
Quoted 11 lines · Serge E. Hallyn
Quoted 10 lines · Eric W. Biederman

In 2009 Philip Reiser notied that a few users of netlink connector interface needed a capability check and added the idiom cap_raised(nsp->eff_cap, CAP_SYS_ADMIN) to a few of them, on the premise that netlink was asynchronous.

In 2011 Patrick McHardy noticed we were being silly because netlink is synchronous and removed eff_cap from the netlink_skb_params and changed the idiom to cap_raised(current_cap(), CAP_SYS_ADMIN).

Quoted 6 lines
Quoted 4 lines

Looking at those spots with a fresh eye we should be calling capable(CAP_SYS_ADMIN). The only reason I can see for not calling capable is that it once appeared we were not in the same task as the caller which would have made calling capable() impossible.

And (just to make sure) that is now absolutely not the case?

Absolutely. Netlink is synchronous.

I reread netlink_unicast_kernel() in net/netlink/af_netlink.c while researching this patch.

Netlink has been synchronous since 2007. In a world of perfect knowledge transmission these calls could have been calls to capable from the very beginning.

Quoted 79 lines
Quoted 15 lines

In the initial user_namespace the only difference between between cap_raised(current_cap(), CAP_SYS_ADMIN) and capable(CAP_SYS_ADMIN) are a few sanity checks and the fact that capable(CAP_SYS_ADMIN) sets PF_SUPERPRIV if we use the capability.

Since we are going to be using root privilege setting PF_SUPERPRIV seems the right thing to do.

The motivation for this that patch is that in a child user namespace cap_raised(current_cap(),...) tests your capabilities with respect to that child user namespace not capabilities in the initial user namespace and thus will allow processes that should be unprivielged to use the kernel services that are only protected with cap_raised(current_cap(),..).

Quoted 7 lines

To fix possible user_namespace issues and to just clean up the code replace cap_raised(current_cap(), CAP_SYS_ADMIN) with capable(CAP_SYS_ADMIN).

Cc Patrick McHardy <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Serge E. Hallyn <[email protected]>

thanks,
-serge

Quoted 51 lines
Cc Andrew Morgan <[email protected]>
Cc Vasiliy Kulikov <[email protected]>
Cc David Howells <[email protected]>
---
 drivers/block/drbd/drbd_nl.c           |    2 +-
 drivers/md/dm-log-userspace-transfer.c |    2 +-
 drivers/video/uvesafb.c                |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/block/drbd/drbd_nl.c +1 -1
index abfaaca..946166e 100644
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
 		return;
 	}
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
+	if (!capable(CAP_SYS_ADMIN)) {
 		retcode = ERR_PERM;
 		goto fail;
 	}
drivers/md/dm-log-userspace-transfer.c +1 -1
index 1f23e04..08d9a20 100644
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
 {
 	struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	spin_lock(&receiving_list_lock);
drivers/video/uvesafb.c +1 -1
index 260cca7..9f7d27a 100644
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
 	struct uvesafb_task *utask;
 	struct uvesafb_ktask *task;
 
-	if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+	if (!capable(CAP_SYS_ADMIN))
 		return;
 
 	if (msg->seq >= UVESAFB_TASKS_MAX)
Signature · 1 line
1.7.2.5
#3 lore raw

Cheers

Andrew

Quoted 108 lines · Eric W. Biederman
Quoted 11 lines · Serge E. Hallyn
Quoted 10 lines · Eric W. Biederman

In 2009 Philip Reiser notied that a few users of netlink connector interface needed a capability check and added the idiom cap_raised(nsp->eff_cap, CAP_SYS_ADMIN) to a few of them, on the premise that netlink was asynchronous.

In 2011 Patrick McHardy noticed we were being silly because netlink is synchronous and removed eff_cap from the netlink_skb_params and changed the idiom to cap_raised(current_cap(), CAP_SYS_ADMIN).

Quoted 6 lines
Quoted 4 lines

Looking at those spots with a fresh eye we should be calling capable(CAP_SYS_ADMIN).  The only reason I can see for not calling capable is that it once appeared we were not in the same task as the caller which would have made calling capable() impossible.

And (just to make sure) that is now absolutely not the case?

Absolutely.  Netlink is synchronous.

I reread netlink_unicast_kernel() in net/netlink/af_netlink.c while researching this patch.

Netlink has been synchronous since 2007.  In a world of perfect knowledge transmission these calls could have been calls to capable from the very beginning.

Quoted 79 lines
Quoted 15 lines

In the initial user_namespace the only difference between  between cap_raised(current_cap(), CAP_SYS_ADMIN) and capable(CAP_SYS_ADMIN) are a few sanity checks and the fact that capable(CAP_SYS_ADMIN) sets PF_SUPERPRIV if we use the capability.

Since we are going to be using root privilege setting PF_SUPERPRIV seems the right thing to do.

The motivation for this that patch is that in a child user namespace cap_raised(current_cap(),...) tests your capabilities with respect to that child user namespace not capabilities in the initial user namespace and thus will allow processes that should be unprivielged to use the kernel services that are only protected with cap_raised(current_cap(),..).

Quoted 7 lines

To fix possible user_namespace issues and to just clean up the code replace cap_raised(current_cap(), CAP_SYS_ADMIN) with capable(CAP_SYS_ADMIN).

Cc Patrick McHardy <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Serge E. Hallyn <[email protected]>

thanks,
-serge

Quoted 51 lines
Cc Andrew Morgan <[email protected]>
Cc Vasiliy Kulikov <[email protected]>
Cc David Howells <[email protected]>

---
 drivers/block/drbd/drbd_nl.c           |    2 +-
 drivers/md/dm-log-userspace-transfer.c |    2 +-
 drivers/video/uvesafb.c                |    2 +-

 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/block/drbd/drbd_nl.c +1 -1
index abfaaca..946166e 100644
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
              return;
      }
 
-    if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
+    if (!capable(CAP_SYS_ADMIN)) {
              retcode = ERR_PERM;
              goto fail;
      }
drivers/md/dm-log-userspace-transfer.c +1 -1
index 1f23e04..08d9a20 100644
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  {
      struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
 
-    if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+    if (!capable(CAP_SYS_ADMIN))
              return;
 
      spin_lock(&receiving_list_lock);
drivers/video/uvesafb.c +1 -2
index 260cca7..9f7d27a 100644
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
      struct uvesafb_task *utask;
      struct uvesafb_ktask *task;
 
-    if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
+    if (!capable(CAP_SYS_ADMIN))
              return;
 
      if (msg->seq >= UVESAFB_TASKS_MAX)
--

1.7.2.5

Reviewed-by on v1 1/1
#4 lore raw
In reply to Eric W. Biederman
Quoted 7 lines · Eric W. Biederman

In the initial user_namespace the only difference between between cap_raised(current_cap(), CAP_SYS_ADMIN) and capable(CAP_SYS_ADMIN) are a few sanity checks and the fact that capable(CAP_SYS_ADMIN) sets PF_SUPERPRIV if we use the capability.

Since we are going to be using root privilege setting PF_SUPERPRIV seems the right thing to do.

Agreed.

- James

Signature · 2 lines
James Morris
<[email protected]>