Skip to content

Commit c49c41a

Browse files
committed
Merge branch 'for-linus' of git://selinuxproject.org/~jmorris/linux-security
* 'for-linus' of git://selinuxproject.org/~jmorris/linux-security: capabilities: remove __cap_full_set definition security: remove the security_netlink_recv hook as it is equivalent to capable() ptrace: do not audit capability check when outputing /proc/pid/stat capabilities: remove task_ns_* functions capabitlies: ns_capable can use the cap helpers rather than lsm call capabilities: style only - move capable below ns_capable capabilites: introduce new has_ns_capabilities_noaudit capabilities: call has_ns_capability from has_capability capabilities: remove all _real_ interfaces capabilities: introduce security_capable_noaudit capabilities: reverse arguments to security_capable capabilities: remove the task from capable LSM hook entirely selinux: sparse fix: fix several warnings in the security server cod selinux: sparse fix: fix warnings in netlink code selinux: sparse fix: eliminate warnings for selinuxfs selinux: sparse fix: declare selinux_disable() in security.h selinux: sparse fix: move selinux_complete_init selinux: sparse fix: make selinux_secmark_refcount static SELinux: Fix RCU deref check warning in sel_netport_insert() Manually fix up a semantic mis-merge wrt security_netlink_recv(): - the interface was removed in commit fd77846 ("security: remove the security_netlink_recv hook as it is equivalent to capable()") - a new user of it appeared in commit a38f790 ("crypto: Add userspace configuration API") causing no automatic merge conflict, but Eric Paris pointed out the issue.
2 parents 892d208 + f423e5b commit c49c41a

24 files changed

Lines changed: 120 additions & 189 deletions

File tree

‎crypto/crypto_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int crypto_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
382382
type -= CRYPTO_MSG_BASE;
383383
link = &crypto_dispatch[type];
384384

385-
if (security_netlink_recv(skb, CAP_NET_ADMIN))
385+
if (!capable(CAP_NET_ADMIN))
386386
return -EPERM;
387387

388388
if ((type == (CRYPTO_MSG_GETALG - CRYPTO_MSG_BASE) &&

‎drivers/pci/pci-sysfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pci_read_config(struct file *filp, struct kobject *kobj,
432432
u8 *data = (u8*) buf;
433433

434434
/* Several chips lock up trying to read undefined config space */
435-
if (security_capable(&init_user_ns, filp->f_cred, CAP_SYS_ADMIN) == 0) {
435+
if (security_capable(filp->f_cred, &init_user_ns, CAP_SYS_ADMIN) == 0) {
436436
size = dev->cfg_size;
437437
} else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
438438
size = 128;

‎drivers/scsi/scsi_netlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
112112
goto next_msg;
113113
}
114114

115-
if (security_netlink_recv(skb, CAP_SYS_ADMIN)) {
115+
if (!capable(CAP_SYS_ADMIN)) {
116116
err = -EPERM;
117117
goto next_msg;
118118
}

‎fs/proc/array.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
380380

381381
state = *get_task_state(task);
382382
vsize = eip = esp = 0;
383-
permitted = ptrace_may_access(task, PTRACE_MODE_READ);
383+
permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
384384
mm = get_task_mm(task);
385385
if (mm) {
386386
vsize = task_vsize(mm);

‎include/linux/capability.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ struct user_namespace;
380380
struct user_namespace *current_user_ns(void);
381381

382382
extern const kernel_cap_t __cap_empty_set;
383-
extern const kernel_cap_t __cap_full_set;
384383
extern const kernel_cap_t __cap_init_eff_set;
385384

386385
/*
@@ -544,9 +543,10 @@ extern bool has_capability(struct task_struct *t, int cap);
544543
extern bool has_ns_capability(struct task_struct *t,
545544
struct user_namespace *ns, int cap);
546545
extern bool has_capability_noaudit(struct task_struct *t, int cap);
546+
extern bool has_ns_capability_noaudit(struct task_struct *t,
547+
struct user_namespace *ns, int cap);
547548
extern bool capable(int cap);
548549
extern bool ns_capable(struct user_namespace *ns, int cap);
549-
extern bool task_ns_capable(struct task_struct *t, int cap);
550550
extern bool nsown_capable(int cap);
551551

552552
/* audit system wants to get cap info from files as well */

‎include/linux/cred.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ static inline void put_cred(const struct cred *_cred)
358358
#define current_security() (current_cred_xxx(security))
359359

360360
#ifdef CONFIG_USER_NS
361-
#define current_user_ns() (current_cred_xxx(user_ns))
361+
#define current_user_ns() (current_cred_xxx(user_ns))
362+
#define task_user_ns(task) (task_cred_xxx((task), user_ns))
362363
#else
363364
extern struct user_namespace init_user_ns;
364-
#define current_user_ns() (&init_user_ns)
365+
#define current_user_ns() (&init_user_ns)
366+
#define task_user_ns(task) (&init_user_ns)
365367
#endif
366368

367369

‎include/linux/ptrace.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ extern void __ptrace_link(struct task_struct *child,
127127
struct task_struct *new_parent);
128128
extern void __ptrace_unlink(struct task_struct *child);
129129
extern void exit_ptrace(struct task_struct *tracer);
130-
#define PTRACE_MODE_READ 1
131-
#define PTRACE_MODE_ATTACH 2
130+
#define PTRACE_MODE_READ 0x01
131+
#define PTRACE_MODE_ATTACH 0x02
132+
#define PTRACE_MODE_NOAUDIT 0x04
132133
/* Returns 0 on success, -errno on denial. */
133134
extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
134135
/* Returns true on success, false on denial. */

‎include/linux/security.h‎

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct user_namespace;
5454
* These functions are in security/capability.c and are used
5555
* as the default capabilities functions
5656
*/
57-
extern int cap_capable(struct task_struct *tsk, const struct cred *cred,
58-
struct user_namespace *ns, int cap, int audit);
57+
extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
58+
int cap, int audit);
5959
extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
6060
extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
6161
extern int cap_ptrace_traceme(struct task_struct *parent);
@@ -96,7 +96,6 @@ struct xfrm_user_sec_ctx;
9696
struct seq_file;
9797

9898
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
99-
extern int cap_netlink_recv(struct sk_buff *skb, int cap);
10099

101100
void reset_security_ops(void);
102101

@@ -799,12 +798,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
799798
* @skb contains the sk_buff structure for the netlink message.
800799
* Return 0 if the information was successfully saved and message
801800
* is allowed to be transmitted.
802-
* @netlink_recv:
803-
* Check permission before processing the received netlink message in
804-
* @skb.
805-
* @skb contains the sk_buff structure for the netlink message.
806-
* @cap indicates the capability required
807-
* Return 0 if permission is granted.
808801
*
809802
* Security hooks for Unix domain networking.
810803
*
@@ -1268,7 +1261,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
12681261
* @capable:
12691262
* Check whether the @tsk process has the @cap capability in the indicated
12701263
* credentials.
1271-
* @tsk contains the task_struct for the process.
12721264
* @cred contains the credentials to use.
12731265
* @ns contains the user namespace we want the capability in
12741266
* @cap contains the capability <include/linux/capability.h>.
@@ -1392,8 +1384,8 @@ struct security_operations {
13921384
const kernel_cap_t *effective,
13931385
const kernel_cap_t *inheritable,
13941386
const kernel_cap_t *permitted);
1395-
int (*capable) (struct task_struct *tsk, const struct cred *cred,
1396-
struct user_namespace *ns, int cap, int audit);
1387+
int (*capable) (const struct cred *cred, struct user_namespace *ns,
1388+
int cap, int audit);
13971389
int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
13981390
int (*quota_on) (struct dentry *dentry);
13991391
int (*syslog) (int type);
@@ -1563,7 +1555,6 @@ struct security_operations {
15631555
struct sembuf *sops, unsigned nsops, int alter);
15641556

15651557
int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
1566-
int (*netlink_recv) (struct sk_buff *skb, int cap);
15671558

15681559
void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
15691560

@@ -1675,12 +1666,10 @@ int security_capset(struct cred *new, const struct cred *old,
16751666
const kernel_cap_t *effective,
16761667
const kernel_cap_t *inheritable,
16771668
const kernel_cap_t *permitted);
1678-
int security_capable(struct user_namespace *ns, const struct cred *cred,
1679-
int cap);
1680-
int security_real_capable(struct task_struct *tsk, struct user_namespace *ns,
1669+
int security_capable(const struct cred *cred, struct user_namespace *ns,
16811670
int cap);
1682-
int security_real_capable_noaudit(struct task_struct *tsk,
1683-
struct user_namespace *ns, int cap);
1671+
int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
1672+
int cap);
16841673
int security_quotactl(int cmds, int type, int id, struct super_block *sb);
16851674
int security_quota_on(struct dentry *dentry);
16861675
int security_syslog(int type);
@@ -1817,7 +1806,6 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode);
18171806
int security_getprocattr(struct task_struct *p, char *name, char **value);
18181807
int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
18191808
int security_netlink_send(struct sock *sk, struct sk_buff *skb);
1820-
int security_netlink_recv(struct sk_buff *skb, int cap);
18211809
int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
18221810
int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
18231811
void security_release_secctx(char *secdata, u32 seclen);
@@ -1875,32 +1863,15 @@ static inline int security_capset(struct cred *new,
18751863
return cap_capset(new, old, effective, inheritable, permitted);
18761864
}
18771865

1878-
static inline int security_capable(struct user_namespace *ns,
1879-
const struct cred *cred, int cap)
1880-
{
1881-
return cap_capable(current, cred, ns, cap, SECURITY_CAP_AUDIT);
1882-
}
1883-
1884-
static inline int security_real_capable(struct task_struct *tsk, struct user_namespace *ns, int cap)
1866+
static inline int security_capable(const struct cred *cred,
1867+
struct user_namespace *ns, int cap)
18851868
{
1886-
int ret;
1887-
1888-
rcu_read_lock();
1889-
ret = cap_capable(tsk, __task_cred(tsk), ns, cap, SECURITY_CAP_AUDIT);
1890-
rcu_read_unlock();
1891-
return ret;
1869+
return cap_capable(cred, ns, cap, SECURITY_CAP_AUDIT);
18921870
}
18931871

1894-
static inline
1895-
int security_real_capable_noaudit(struct task_struct *tsk, struct user_namespace *ns, int cap)
1896-
{
1897-
int ret;
1898-
1899-
rcu_read_lock();
1900-
ret = cap_capable(tsk, __task_cred(tsk), ns, cap,
1901-
SECURITY_CAP_NOAUDIT);
1902-
rcu_read_unlock();
1903-
return ret;
1872+
static inline int security_capable_noaudit(const struct cred *cred,
1873+
struct user_namespace *ns, int cap) {
1874+
return cap_capable(cred, ns, cap, SECURITY_CAP_NOAUDIT);
19041875
}
19051876

19061877
static inline int security_quotactl(int cmds, int type, int id,
@@ -2517,11 +2488,6 @@ static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
25172488
return cap_netlink_send(sk, skb);
25182489
}
25192490

2520-
static inline int security_netlink_recv(struct sk_buff *skb, int cap)
2521-
{
2522-
return cap_netlink_recv(skb, cap);
2523-
}
2524-
25252491
static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
25262492
{
25272493
return -EOPNOTSUPP;

‎kernel/audit.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,13 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
601601
case AUDIT_TTY_SET:
602602
case AUDIT_TRIM:
603603
case AUDIT_MAKE_EQUIV:
604-
if (security_netlink_recv(skb, CAP_AUDIT_CONTROL))
604+
if (!capable(CAP_AUDIT_CONTROL))
605605
err = -EPERM;
606606
break;
607607
case AUDIT_USER:
608608
case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
609609
case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
610-
if (security_netlink_recv(skb, CAP_AUDIT_WRITE))
610+
if (!capable(CAP_AUDIT_WRITE))
611611
err = -EPERM;
612612
break;
613613
default: /* bad msg */

‎kernel/capability.c‎

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -287,74 +287,84 @@ SYSCALL_DEFINE2(capset, cap_user_header_t, header, const cap_user_data_t, data)
287287
}
288288

289289
/**
290-
* has_capability - Does a task have a capability in init_user_ns
290+
* has_ns_capability - Does a task have a capability in a specific user ns
291291
* @t: The task in question
292+
* @ns: target user namespace
292293
* @cap: The capability to be tested for
293294
*
294295
* Return true if the specified task has the given superior capability
295-
* currently in effect to the initial user namespace, false if not.
296+
* currently in effect to the specified user namespace, false if not.
296297
*
297298
* Note that this does not set PF_SUPERPRIV on the task.
298299
*/
299-
bool has_capability(struct task_struct *t, int cap)
300+
bool has_ns_capability(struct task_struct *t,
301+
struct user_namespace *ns, int cap)
300302
{
301-
int ret = security_real_capable(t, &init_user_ns, cap);
303+
int ret;
304+
305+
rcu_read_lock();
306+
ret = security_capable(__task_cred(t), ns, cap);
307+
rcu_read_unlock();
302308

303309
return (ret == 0);
304310
}
305311

306312
/**
307-
* has_capability - Does a task have a capability in a specific user ns
313+
* has_capability - Does a task have a capability in init_user_ns
308314
* @t: The task in question
309-
* @ns: target user namespace
310315
* @cap: The capability to be tested for
311316
*
312317
* Return true if the specified task has the given superior capability
313-
* currently in effect to the specified user namespace, false if not.
318+
* currently in effect to the initial user namespace, false if not.
314319
*
315320
* Note that this does not set PF_SUPERPRIV on the task.
316321
*/
317-
bool has_ns_capability(struct task_struct *t,
318-
struct user_namespace *ns, int cap)
322+
bool has_capability(struct task_struct *t, int cap)
319323
{
320-
int ret = security_real_capable(t, ns, cap);
321-
322-
return (ret == 0);
324+
return has_ns_capability(t, &init_user_ns, cap);
323325
}
324326

325327
/**
326-
* has_capability_noaudit - Does a task have a capability (unaudited)
328+
* has_ns_capability_noaudit - Does a task have a capability (unaudited)
329+
* in a specific user ns.
327330
* @t: The task in question
331+
* @ns: target user namespace
328332
* @cap: The capability to be tested for
329333
*
330334
* Return true if the specified task has the given superior capability
331-
* currently in effect to init_user_ns, false if not. Don't write an
332-
* audit message for the check.
335+
* currently in effect to the specified user namespace, false if not.
336+
* Do not write an audit message for the check.
333337
*
334338
* Note that this does not set PF_SUPERPRIV on the task.
335339
*/
336-
bool has_capability_noaudit(struct task_struct *t, int cap)
340+
bool has_ns_capability_noaudit(struct task_struct *t,
341+
struct user_namespace *ns, int cap)
337342
{
338-
int ret = security_real_capable_noaudit(t, &init_user_ns, cap);
343+
int ret;
344+
345+
rcu_read_lock();
346+
ret = security_capable_noaudit(__task_cred(t), ns, cap);
347+
rcu_read_unlock();
339348

340349
return (ret == 0);
341350
}
342351

343352
/**
344-
* capable - Determine if the current task has a superior capability in effect
353+
* has_capability_noaudit - Does a task have a capability (unaudited) in the
354+
* initial user ns
355+
* @t: The task in question
345356
* @cap: The capability to be tested for
346357
*
347-
* Return true if the current task has the given superior capability currently
348-
* available for use, false if not.
358+
* Return true if the specified task has the given superior capability
359+
* currently in effect to init_user_ns, false if not. Don't write an
360+
* audit message for the check.
349361
*
350-
* This sets PF_SUPERPRIV on the task if the capability is available on the
351-
* assumption that it's about to be used.
362+
* Note that this does not set PF_SUPERPRIV on the task.
352363
*/
353-
bool capable(int cap)
364+
bool has_capability_noaudit(struct task_struct *t, int cap)
354365
{
355-
return ns_capable(&init_user_ns, cap);
366+
return has_ns_capability_noaudit(t, &init_user_ns, cap);
356367
}
357-
EXPORT_SYMBOL(capable);
358368

359369
/**
360370
* ns_capable - Determine if the current task has a superior capability in effect
@@ -374,7 +384,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
374384
BUG();
375385
}
376386

377-
if (security_capable(ns, current_cred(), cap) == 0) {
387+
if (has_ns_capability(current, ns, cap)) {
378388
current->flags |= PF_SUPERPRIV;
379389
return true;
380390
}
@@ -383,18 +393,20 @@ bool ns_capable(struct user_namespace *ns, int cap)
383393
EXPORT_SYMBOL(ns_capable);
384394

385395
/**
386-
* task_ns_capable - Determine whether current task has a superior
387-
* capability targeted at a specific task's user namespace.
388-
* @t: The task whose user namespace is targeted.
389-
* @cap: The capability in question.
396+
* capable - Determine if the current task has a superior capability in effect
397+
* @cap: The capability to be tested for
398+
*
399+
* Return true if the current task has the given superior capability currently
400+
* available for use, false if not.
390401
*
391-
* Return true if it does, false otherwise.
402+
* This sets PF_SUPERPRIV on the task if the capability is available on the
403+
* assumption that it's about to be used.
392404
*/
393-
bool task_ns_capable(struct task_struct *t, int cap)
405+
bool capable(int cap)
394406
{
395-
return ns_capable(task_cred_xxx(t, user)->user_ns, cap);
407+
return ns_capable(&init_user_ns, cap);
396408
}
397-
EXPORT_SYMBOL(task_ns_capable);
409+
EXPORT_SYMBOL(capable);
398410

399411
/**
400412
* nsown_capable - Check superior capability to one's own user_ns

0 commit comments

Comments
 (0)