Skip to content

Commit b0654ca

Browse files
cschauflerpcmoore
authored andcommitted
lsm: create new security_cred_getlsmprop LSM hook
Create a new LSM hook security_cred_getlsmprop() which, like security_cred_getsecid(), fetches LSM specific attributes from the cred structure. The associated data elements in the audit sub-system are changed from a secid to a lsm_prop to accommodate multiple possible LSM audit users. Cc: linux-integrity@vger.kernel.org Cc: audit@vger.kernel.org Cc: selinux@vger.kernel.org Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> [PM: subj line tweak] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent e0a8dcb commit b0654ca

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ LSM_HOOK(int, 0, cred_prepare, struct cred *new, const struct cred *old,
218218
LSM_HOOK(void, LSM_RET_VOID, cred_transfer, struct cred *new,
219219
const struct cred *old)
220220
LSM_HOOK(void, LSM_RET_VOID, cred_getsecid, const struct cred *c, u32 *secid)
221+
LSM_HOOK(void, LSM_RET_VOID, cred_getlsmprop, const struct cred *c,
222+
struct lsm_prop *prop)
221223
LSM_HOOK(int, 0, kernel_act_as, struct cred *new, u32 secid)
222224
LSM_HOOK(int, 0, kernel_create_files_as, struct cred *new, struct inode *inode)
223225
LSM_HOOK(int, 0, kernel_module_request, char *kmod_name)

include/linux/security.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ void security_cred_free(struct cred *cred);
488488
int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
489489
void security_transfer_creds(struct cred *new, const struct cred *old);
490490
void security_cred_getsecid(const struct cred *c, u32 *secid);
491+
void security_cred_getlsmprop(const struct cred *c, struct lsm_prop *prop);
491492
int security_kernel_act_as(struct cred *new, u32 secid);
492493
int security_kernel_create_files_as(struct cred *new, struct inode *inode);
493494
int security_kernel_module_request(char *kmod_name);
@@ -1229,6 +1230,10 @@ static inline void security_cred_getsecid(const struct cred *c, u32 *secid)
12291230
*secid = 0;
12301231
}
12311232

1233+
static inline void security_cred_getlsmprop(const struct cred *c,
1234+
struct lsm_prop *prop)
1235+
{ }
1236+
12321237
static inline int security_kernel_act_as(struct cred *cred, u32 secid)
12331238
{
12341239
return 0;

security/integrity/ima/ima_main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,15 @@ static int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
541541
static int ima_bprm_check(struct linux_binprm *bprm)
542542
{
543543
int ret;
544-
u32 secid;
545-
struct lsm_prop prop = { };
544+
struct lsm_prop prop;
546545

547546
security_current_getlsmprop_subj(&prop);
548547
ret = process_measurement(bprm->file, current_cred(),
549548
&prop, NULL, 0, MAY_EXEC, BPRM_CHECK);
550549
if (ret)
551550
return ret;
552551

553-
security_cred_getsecid(bprm->cred, &secid);
554-
/* scaffolding */
555-
prop.scaffold.secid = secid;
552+
security_cred_getlsmprop(bprm->cred, &prop);
556553
return process_measurement(bprm->file, bprm->cred, &prop, NULL, 0,
557554
MAY_EXEC, CREDS_CHECK);
558555
}

security/security.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,6 +3272,21 @@ void security_cred_getsecid(const struct cred *c, u32 *secid)
32723272
}
32733273
EXPORT_SYMBOL(security_cred_getsecid);
32743274

3275+
/**
3276+
* security_cred_getlsmprop() - Get the LSM data from a set of credentials
3277+
* @c: credentials
3278+
* @prop: destination for the LSM data
3279+
*
3280+
* Retrieve the security data of the cred structure @c. In case of
3281+
* failure, @prop will be cleared.
3282+
*/
3283+
void security_cred_getlsmprop(const struct cred *c, struct lsm_prop *prop)
3284+
{
3285+
lsmprop_init(prop);
3286+
call_void_hook(cred_getlsmprop, c, prop);
3287+
}
3288+
EXPORT_SYMBOL(security_cred_getlsmprop);
3289+
32753290
/**
32763291
* security_kernel_act_as() - Set the kernel credentials to act as secid
32773292
* @new: credentials

security/selinux/hooks.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,13 @@ static void selinux_cred_getsecid(const struct cred *c, u32 *secid)
40374037
*secid = cred_sid(c);
40384038
}
40394039

4040+
static void selinux_cred_getlsmprop(const struct cred *c, struct lsm_prop *prop)
4041+
{
4042+
prop->selinux.secid = cred_sid(c);
4043+
/* scaffolding */
4044+
prop->scaffold.secid = prop->selinux.secid;
4045+
}
4046+
40404047
/*
40414048
* set the security data for a kernel service
40424049
* - all the creation contexts are set to unlabelled
@@ -7203,6 +7210,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
72037210
LSM_HOOK_INIT(cred_prepare, selinux_cred_prepare),
72047211
LSM_HOOK_INIT(cred_transfer, selinux_cred_transfer),
72057212
LSM_HOOK_INIT(cred_getsecid, selinux_cred_getsecid),
7213+
LSM_HOOK_INIT(cred_getlsmprop, selinux_cred_getlsmprop),
72067214
LSM_HOOK_INIT(kernel_act_as, selinux_kernel_act_as),
72077215
LSM_HOOK_INIT(kernel_create_files_as, selinux_kernel_create_files_as),
72087216
LSM_HOOK_INIT(kernel_module_request, selinux_kernel_module_request),

security/smack/smack_lsm.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,23 @@ static void smack_cred_getsecid(const struct cred *cred, u32 *secid)
21502150
rcu_read_unlock();
21512151
}
21522152

2153+
/**
2154+
* smack_cred_getlsmprop - get the Smack label for a creds structure
2155+
* @cred: the object creds
2156+
* @prop: where to put the data
2157+
*
2158+
* Sets the Smack part of the ref
2159+
*/
2160+
static void smack_cred_getlsmprop(const struct cred *cred,
2161+
struct lsm_prop *prop)
2162+
{
2163+
rcu_read_lock();
2164+
prop->smack.skp = smk_of_task(smack_cred(cred));
2165+
/* scaffolding */
2166+
prop->scaffold.secid = prop->smack.skp->smk_secid;
2167+
rcu_read_unlock();
2168+
}
2169+
21532170
/**
21542171
* smack_kernel_act_as - Set the subjective context in a set of credentials
21552172
* @new: points to the set of credentials to be modified.
@@ -5132,6 +5149,7 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
51325149
LSM_HOOK_INIT(cred_prepare, smack_cred_prepare),
51335150
LSM_HOOK_INIT(cred_transfer, smack_cred_transfer),
51345151
LSM_HOOK_INIT(cred_getsecid, smack_cred_getsecid),
5152+
LSM_HOOK_INIT(cred_getlsmprop, smack_cred_getlsmprop),
51355153
LSM_HOOK_INIT(kernel_act_as, smack_kernel_act_as),
51365154
LSM_HOOK_INIT(kernel_create_files_as, smack_kernel_create_files_as),
51375155
LSM_HOOK_INIT(task_setpgid, smack_task_setpgid),

0 commit comments

Comments
 (0)