Skip to content

Commit 6326948

Browse files
committed
lsm: security_task_getsecid_subj() -> security_current_getsecid_subj()
The security_task_getsecid_subj() LSM hook invites misuse by allowing callers to specify a task even though the hook is only safe when the current task is referenced. Fix this by removing the task_struct argument to the hook, requiring LSM implementations to use the current task. While we are changing the hook declaration we also rename the function to security_current_getsecid_subj() in an effort to reinforce that the hook captures the subjective credentials of the current task and not an arbitrary task on the system. Reviewed-by: Serge Hallyn <[email protected]> Reviewed-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent fa55b7d commit 6326948

File tree

15 files changed

+49
-67
lines changed

15 files changed

+49
-67
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ LSM_HOOK(int, 0, task_fix_setgid, struct cred *new, const struct cred * old,
206206
LSM_HOOK(int, 0, task_setpgid, struct task_struct *p, pid_t pgid)
207207
LSM_HOOK(int, 0, task_getpgid, struct task_struct *p)
208208
LSM_HOOK(int, 0, task_getsid, struct task_struct *p)
209-
LSM_HOOK(void, LSM_RET_VOID, task_getsecid_subj,
210-
struct task_struct *p, u32 *secid)
209+
LSM_HOOK(void, LSM_RET_VOID, current_getsecid_subj, u32 *secid)
211210
LSM_HOOK(void, LSM_RET_VOID, task_getsecid_obj,
212211
struct task_struct *p, u32 *secid)
213212
LSM_HOOK(int, 0, task_setnice, struct task_struct *p, int nice)

include/linux/lsm_hooks.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,9 @@
719719
* @p.
720720
* @p contains the task_struct for the process.
721721
* Return 0 if permission is granted.
722-
* @task_getsecid_subj:
723-
* Retrieve the subjective security identifier of the task_struct in @p
724-
* and return it in @secid. Special care must be taken to ensure that @p
725-
* is the either the "current" task, or the caller has exclusive access
726-
* to @p.
722+
* @current_getsecid_subj:
723+
* Retrieve the subjective security identifier of the current task and
724+
* return it in @secid.
727725
* In case of failure, @secid will be set to zero.
728726
* @task_getsecid_obj:
729727
* Retrieve the objective security identifier of the task_struct in @p

include/linux/security.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ int security_task_fix_setgid(struct cred *new, const struct cred *old,
418418
int security_task_setpgid(struct task_struct *p, pid_t pgid);
419419
int security_task_getpgid(struct task_struct *p);
420420
int security_task_getsid(struct task_struct *p);
421-
void security_task_getsecid_subj(struct task_struct *p, u32 *secid);
421+
void security_current_getsecid_subj(u32 *secid);
422422
void security_task_getsecid_obj(struct task_struct *p, u32 *secid);
423423
int security_task_setnice(struct task_struct *p, int nice);
424424
int security_task_setioprio(struct task_struct *p, int ioprio);
@@ -1119,7 +1119,7 @@ static inline int security_task_getsid(struct task_struct *p)
11191119
return 0;
11201120
}
11211121

1122-
static inline void security_task_getsecid_subj(struct task_struct *p, u32 *secid)
1122+
static inline void security_current_getsecid_subj(u32 *secid)
11231123
{
11241124
*secid = 0;
11251125
}

kernel/audit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ int audit_log_task_context(struct audit_buffer *ab)
21322132
int error;
21332133
u32 sid;
21342134

2135-
security_task_getsecid_subj(current, &sid);
2135+
security_current_getsecid_subj(&sid);
21362136
if (!sid)
21372137
return 0;
21382138

@@ -2353,7 +2353,7 @@ int audit_signal_info(int sig, struct task_struct *t)
23532353
audit_sig_uid = auid;
23542354
else
23552355
audit_sig_uid = uid;
2356-
security_task_getsecid_subj(current, &audit_sig_sid);
2356+
security_current_getsecid_subj(&audit_sig_sid);
23572357
}
23582358

23592359
return audit_signal_info_syscall(t);

kernel/auditfilter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,8 +1368,7 @@ int audit_filter(int msgtype, unsigned int listtype)
13681368
case AUDIT_SUBJ_SEN:
13691369
case AUDIT_SUBJ_CLR:
13701370
if (f->lsm_rule) {
1371-
security_task_getsecid_subj(current,
1372-
&sid);
1371+
security_current_getsecid_subj(&sid);
13731372
result = security_audit_rule_match(sid,
13741373
f->type, f->op, f->lsm_rule);
13751374
}

kernel/auditsc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,16 @@ static int audit_filter_rules(struct task_struct *tsk,
666666
logged upon error */
667667
if (f->lsm_rule) {
668668
if (need_sid) {
669-
security_task_getsecid_subj(tsk, &sid);
669+
/* @tsk should always be equal to
670+
* @current with the exception of
671+
* fork()/copy_process() in which case
672+
* the new @tsk creds are still a dup
673+
* of @current's creds so we can still
674+
* use security_current_getsecid_subj()
675+
* here even though it always refs
676+
* @current's creds
677+
*/
678+
security_current_getsecid_subj(&sid);
670679
need_sid = 0;
671680
}
672681
result = security_audit_rule_match(sid, f->type,

net/netlabel/netlabel_unlabeled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ int __init netlbl_unlabel_defconf(void)
15371537
/* Only the kernel is allowed to call this function and the only time
15381538
* it is called is at bootup before the audit subsystem is reporting
15391539
* messages so don't worry to much about these values. */
1540-
security_task_getsecid_subj(current, &audit_info.secid);
1540+
security_current_getsecid_subj(&audit_info.secid);
15411541
audit_info.loginuid = GLOBAL_ROOT_UID;
15421542
audit_info.sessionid = 0;
15431543

net/netlabel/netlabel_user.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
static inline void netlbl_netlink_auditinfo(struct netlbl_audit *audit_info)
3434
{
35-
security_task_getsecid_subj(current, &audit_info->secid);
35+
security_current_getsecid_subj(&audit_info->secid);
3636
audit_info->loginuid = audit_get_loginuid(current);
3737
audit_info->sessionid = audit_get_sessionid(current);
3838
}

security/apparmor/lsm.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,14 @@ static void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
728728
return;
729729
}
730730

731-
static void apparmor_task_getsecid(struct task_struct *p, u32 *secid)
731+
static void apparmor_current_getsecid_subj(u32 *secid)
732+
{
733+
struct aa_label *label = aa_get_current_label();
734+
*secid = label->secid;
735+
aa_put_label(label);
736+
}
737+
738+
static void apparmor_task_getsecid_obj(struct task_struct *p, u32 *secid)
732739
{
733740
struct aa_label *label = aa_get_task_label(p);
734741
*secid = label->secid;
@@ -1252,8 +1259,8 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {
12521259

12531260
LSM_HOOK_INIT(task_free, apparmor_task_free),
12541261
LSM_HOOK_INIT(task_alloc, apparmor_task_alloc),
1255-
LSM_HOOK_INIT(task_getsecid_subj, apparmor_task_getsecid),
1256-
LSM_HOOK_INIT(task_getsecid_obj, apparmor_task_getsecid),
1262+
LSM_HOOK_INIT(current_getsecid_subj, apparmor_current_getsecid_subj),
1263+
LSM_HOOK_INIT(task_getsecid_obj, apparmor_task_getsecid_obj),
12571264
LSM_HOOK_INIT(task_setrlimit, apparmor_task_setrlimit),
12581265
LSM_HOOK_INIT(task_kill, apparmor_task_kill),
12591266

security/integrity/ima/ima_appraise.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int ima_must_appraise(struct user_namespace *mnt_userns, struct inode *inode,
7676
if (!ima_appraise)
7777
return 0;
7878

79-
security_task_getsecid_subj(current, &secid);
79+
security_current_getsecid_subj(&secid);
8080
return ima_match_policy(mnt_userns, inode, current_cred(), secid,
8181
func, mask, IMA_APPRAISE | IMA_HASH, NULL,
8282
NULL, NULL, NULL);

0 commit comments

Comments
 (0)