Skip to content

Commit 38bf195

Browse files
ebiedermdavem330
authored andcommitted
connector/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). Signed-off-by: Eric W. Biederman <[email protected]> Cc: Patrick McHardy <[email protected]> Cc: Philipp Reisner <[email protected]> Acked-by: Serge E. Hallyn <[email protected]> Acked-by: Andrew G. Morgan <[email protected]> Cc: Vasiliy Kulikov <[email protected]> Cc: David Howells <[email protected]> Reviewed-by: James Morris <[email protected]> Cc: David Miller <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e026886 commit 38bf195

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

drivers/block/drbd/drbd_nl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
22972297
return;
22982298
}
22992299

2300-
if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
2300+
if (!capable(CAP_SYS_ADMIN)) {
23012301
retcode = ERR_PERM;
23022302
goto fail;
23032303
}

drivers/md/dm-log-userspace-transfer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
134134
{
135135
struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
136136

137-
if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
137+
if (!capable(CAP_SYS_ADMIN))
138138
return;
139139

140140
spin_lock(&receiving_list_lock);

drivers/video/uvesafb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
7373
struct uvesafb_task *utask;
7474
struct uvesafb_ktask *task;
7575

76-
if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
76+
if (!capable(CAP_SYS_ADMIN))
7777
return;
7878

7979
if (msg->seq >= UVESAFB_TASKS_MAX)

0 commit comments

Comments
 (0)