Skip to content

Commit 1fb057d

Browse files
committed
smack: differentiate between subjective and objective task credentials
With the split of the security_task_getsecid() into subjective and objective variants it's time to update Smack to ensure it is using the correct task creds. Acked-by: Casey Schaufler <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Reviewed-by: John Johansen <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent eb1231f commit 1fb057d

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

security/smack/smack.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,23 @@ static inline struct smack_known *smk_of_task(const struct task_smack *tsp)
383383
return tsp->smk_task;
384384
}
385385

386-
static inline struct smack_known *smk_of_task_struct(
386+
static inline struct smack_known *smk_of_task_struct_subj(
387+
const struct task_struct *t)
388+
{
389+
struct smack_known *skp;
390+
const struct cred *cred;
391+
392+
rcu_read_lock();
393+
394+
cred = rcu_dereference(t->cred);
395+
skp = smk_of_task(smack_cred(cred));
396+
397+
rcu_read_unlock();
398+
399+
return skp;
400+
}
401+
402+
static inline struct smack_known *smk_of_task_struct_obj(
387403
const struct task_struct *t)
388404
{
389405
struct smack_known *skp;

security/smack/smack_lsm.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int smk_bu_current(char *note, struct smack_known *oskp,
159159
static int smk_bu_task(struct task_struct *otp, int mode, int rc)
160160
{
161161
struct task_smack *tsp = smack_cred(current_cred());
162-
struct smack_known *smk_task = smk_of_task_struct(otp);
162+
struct smack_known *smk_task = smk_of_task_struct_obj(otp);
163163
char acc[SMK_NUM_ACCESS_TYPE + 1];
164164

165165
if (rc <= 0)
@@ -479,7 +479,7 @@ static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode)
479479
{
480480
struct smack_known *skp;
481481

482-
skp = smk_of_task_struct(ctp);
482+
skp = smk_of_task_struct_obj(ctp);
483483

484484
return smk_ptrace_rule_check(current, skp, mode, __func__);
485485
}
@@ -2033,7 +2033,7 @@ static int smk_curacc_on_task(struct task_struct *p, int access,
20332033
const char *caller)
20342034
{
20352035
struct smk_audit_info ad;
2036-
struct smack_known *skp = smk_of_task_struct(p);
2036+
struct smack_known *skp = smk_of_task_struct_subj(p);
20372037
int rc;
20382038

20392039
smk_ad_init(&ad, caller, LSM_AUDIT_DATA_TASK);
@@ -2078,15 +2078,29 @@ static int smack_task_getsid(struct task_struct *p)
20782078
}
20792079

20802080
/**
2081-
* smack_task_getsecid - get the secid of the task
2082-
* @p: the object task
2081+
* smack_task_getsecid_subj - get the subjective secid of the task
2082+
* @p: the task
20832083
* @secid: where to put the result
20842084
*
2085-
* Sets the secid to contain a u32 version of the smack label.
2085+
* Sets the secid to contain a u32 version of the task's subjective smack label.
2086+
*/
2087+
static void smack_task_getsecid_subj(struct task_struct *p, u32 *secid)
2088+
{
2089+
struct smack_known *skp = smk_of_task_struct_subj(p);
2090+
2091+
*secid = skp->smk_secid;
2092+
}
2093+
2094+
/**
2095+
* smack_task_getsecid_obj - get the objective secid of the task
2096+
* @p: the task
2097+
* @secid: where to put the result
2098+
*
2099+
* Sets the secid to contain a u32 version of the task's objective smack label.
20862100
*/
2087-
static void smack_task_getsecid(struct task_struct *p, u32 *secid)
2101+
static void smack_task_getsecid_obj(struct task_struct *p, u32 *secid)
20882102
{
2089-
struct smack_known *skp = smk_of_task_struct(p);
2103+
struct smack_known *skp = smk_of_task_struct_obj(p);
20902104

20912105
*secid = skp->smk_secid;
20922106
}
@@ -2174,7 +2188,7 @@ static int smack_task_kill(struct task_struct *p, struct kernel_siginfo *info,
21742188
{
21752189
struct smk_audit_info ad;
21762190
struct smack_known *skp;
2177-
struct smack_known *tkp = smk_of_task_struct(p);
2191+
struct smack_known *tkp = smk_of_task_struct_obj(p);
21782192
int rc;
21792193

21802194
if (!sig)
@@ -2212,7 +2226,7 @@ static int smack_task_kill(struct task_struct *p, struct kernel_siginfo *info,
22122226
static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
22132227
{
22142228
struct inode_smack *isp = smack_inode(inode);
2215-
struct smack_known *skp = smk_of_task_struct(p);
2229+
struct smack_known *skp = smk_of_task_struct_obj(p);
22162230

22172231
isp->smk_inode = skp;
22182232
isp->smk_flags |= SMK_INODE_INSTANT;
@@ -3483,7 +3497,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
34833497
*/
34843498
static int smack_getprocattr(struct task_struct *p, char *name, char **value)
34853499
{
3486-
struct smack_known *skp = smk_of_task_struct(p);
3500+
struct smack_known *skp = smk_of_task_struct_subj(p);
34873501
char *cp;
34883502
int slen;
34893503

@@ -4759,8 +4773,8 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {
47594773
LSM_HOOK_INIT(task_setpgid, smack_task_setpgid),
47604774
LSM_HOOK_INIT(task_getpgid, smack_task_getpgid),
47614775
LSM_HOOK_INIT(task_getsid, smack_task_getsid),
4762-
LSM_HOOK_INIT(task_getsecid_subj, smack_task_getsecid),
4763-
LSM_HOOK_INIT(task_getsecid_obj, smack_task_getsecid),
4776+
LSM_HOOK_INIT(task_getsecid_subj, smack_task_getsecid_subj),
4777+
LSM_HOOK_INIT(task_getsecid_obj, smack_task_getsecid_obj),
47644778
LSM_HOOK_INIT(task_setnice, smack_task_setnice),
47654779
LSM_HOOK_INIT(task_setioprio, smack_task_setioprio),
47664780
LSM_HOOK_INIT(task_getioprio, smack_task_getioprio),

0 commit comments

Comments
 (0)