[PATCH 08/97] LSM: Use lsm_export in the cred_getsecid hooks
Casey Schaufler
casey at schaufler-ca.com
Thu Feb 28 22:18:04 UTC 2019
Convert the cred_getsecid hooks to use the lsm_export
structure instead of a u32 secid. There is some scaffolding
involved that will be removed when security_cred_getsecid()
is updated.
Signed-off-by: Casey Schaufler <casey at schaufler-ca.com>
---
include/linux/lsm_hooks.h | 5 +++--
security/security.c | 6 ++++--
security/selinux/hooks.c | 4 ++--
security/smack/smack_lsm.c | 4 ++--
4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index ff97f57a87bb..2e8516447bfd 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -556,7 +556,8 @@
* Transfer data from original creds to new creds
* @cred_getsecid:
* Retrieve the security identifier of the cred structure @c
- * @c contains the credentials, secid will be placed into @secid.
+ * @c contains the credentials
+ * @l contains a pointer to the location where result will be saved.
* In case of failure, @secid will be set to zero.
* @kernel_act_as:
* Set the credentials for a kernel service to act as (subjective context).
@@ -1586,7 +1587,7 @@ union security_list_options {
int (*cred_prepare)(struct cred *new, const struct cred *old,
gfp_t gfp);
void (*cred_transfer)(struct cred *new, const struct cred *old);
- void (*cred_getsecid)(const struct cred *c, u32 *secid);
+ void (*cred_getsecid)(const struct cred *c, struct lsm_export *l);
int (*kernel_act_as)(struct cred *new, u32 secid);
int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
int (*kernel_module_request)(char *kmod_name);
diff --git a/security/security.c b/security/security.c
index 5bee7e0b0bf3..9c10d9aae83f 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1624,8 +1624,10 @@ void security_transfer_creds(struct cred *new, const struct cred *old)
void security_cred_getsecid(const struct cred *c, u32 *secid)
{
- *secid = 0;
- call_void_hook(cred_getsecid, c, secid);
+ struct lsm_export data = { .flags = LSM_EXPORT_NONE };
+
+ call_void_hook(cred_getsecid, c, &data);
+ lsm_export_secid(&data, secid);
}
EXPORT_SYMBOL(security_cred_getsecid);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index cbf7bf3fa4af..d9179b75acb7 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3660,9 +3660,9 @@ static void selinux_cred_transfer(struct cred *new, const struct cred *old)
*tsec = *old_tsec;
}
-static void selinux_cred_getsecid(const struct cred *c, u32 *secid)
+static void selinux_cred_getsecid(const struct cred *c, struct lsm_export *l)
{
- *secid = cred_sid(c);
+ selinux_export_secid(l, cred_sid(c));
}
/*
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index a9277a942ca2..e3639d6f1b62 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1893,13 +1893,13 @@ static void smack_cred_transfer(struct cred *new, const struct cred *old)
*
* Sets the secid to contain a u32 version of the smack label.
*/
-static void smack_cred_getsecid(const struct cred *cred, u32 *secid)
+static void smack_cred_getsecid(const struct cred *cred, struct lsm_export *l)
{
struct smack_known *skp;
rcu_read_lock();
skp = smk_of_task(smack_cred(cred));
- *secid = skp->smk_secid;
+ smack_export_secid(l, skp->smk_secid);
rcu_read_unlock();
}
--
2.17.0
More information about the Linux-security-module-archive
mailing list