aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2008-11-13 18:39:28 -0500
committerJames Morris <jmorris@namei.org>2008-11-13 18:39:28 -0500
commit3a3b7ce9336952ea7b9564d976d068a238976c9d (patch)
tree3f0a3be33022492161f534636a20a4b1059f8236 /security
parent1bfdc75ae077d60a01572a7781ec6264d55ab1b9 (diff)
CRED: Allow kernel services to override LSM settings for task actions
Allow kernel services to override LSM settings appropriate to the actions performed by a task by duplicating a set of credentials, modifying it and then using task_struct::cred to point to it when performing operations on behalf of a task. This is used, for example, by CacheFiles which has to transparently access the cache on behalf of a process that thinks it is doing, say, NFS accesses with a potentially inappropriate (with respect to accessing the cache) set of credentials. This patch provides two LSM hooks for modifying a task security record: (*) security_kernel_act_as() which allows modification of the security datum with which a task acts on other objects (most notably files). (*) security_kernel_create_files_as() which allows modification of the security datum that is used to initialise the security data on a file that a task creates. The patch also provides four new credentials handling functions, which wrap the LSM functions: (1) prepare_kernel_cred() Prepare a set of credentials for a kernel service to use, based either on a daemon's credentials or on init_cred. All the keyrings are cleared. (2) set_security_override() Set the LSM security ID in a set of credentials to a specific security context, assuming permission from the LSM policy. (3) set_security_override_from_ctx() As (2), but takes the security context as a string. (4) set_create_files_as() Set the file creation LSM security ID in a set of credentials to be the same as that on a particular inode. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> [Smack changes] Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security')
-rw-r--r--security/capability.c12
-rw-r--r--security/security.c10
-rw-r--r--security/selinux/hooks.c46
-rw-r--r--security/smack/smack_lsm.c37
4 files changed, 105 insertions, 0 deletions
diff --git a/security/capability.c b/security/capability.c
index 185804f99ad1..b9e391425e6f 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -348,6 +348,16 @@ static void cap_cred_commit(struct cred *new, const struct cred *old)
348{ 348{
349} 349}
350 350
351static int cap_kernel_act_as(struct cred *new, u32 secid)
352{
353 return 0;
354}
355
356static int cap_kernel_create_files_as(struct cred *new, struct inode *inode)
357{
358 return 0;
359}
360
351static int cap_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags) 361static int cap_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
352{ 362{
353 return 0; 363 return 0;
@@ -889,6 +899,8 @@ void security_fixup_ops(struct security_operations *ops)
889 set_to_cap_if_null(ops, cred_free); 899 set_to_cap_if_null(ops, cred_free);
890 set_to_cap_if_null(ops, cred_prepare); 900 set_to_cap_if_null(ops, cred_prepare);
891 set_to_cap_if_null(ops, cred_commit); 901 set_to_cap_if_null(ops, cred_commit);
902 set_to_cap_if_null(ops, kernel_act_as);
903 set_to_cap_if_null(ops, kernel_create_files_as);
892 set_to_cap_if_null(ops, task_setuid); 904 set_to_cap_if_null(ops, task_setuid);
893 set_to_cap_if_null(ops, task_fix_setuid); 905 set_to_cap_if_null(ops, task_fix_setuid);
894 set_to_cap_if_null(ops, task_setgid); 906 set_to_cap_if_null(ops, task_setgid);
diff --git a/security/security.c b/security/security.c
index dc5babb2d6d8..038ef04b2c7f 100644
--- a/security/security.c
+++ b/security/security.c
@@ -616,6 +616,16 @@ void security_commit_creds(struct cred *new, const struct cred *old)
616 return security_ops->cred_commit(new, old); 616 return security_ops->cred_commit(new, old);
617} 617}
618 618
619int security_kernel_act_as(struct cred *new, u32 secid)
620{
621 return security_ops->kernel_act_as(new, secid);
622}
623
624int security_kernel_create_files_as(struct cred *new, struct inode *inode)
625{
626 return security_ops->kernel_create_files_as(new, inode);
627}
628
619int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags) 629int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
620{ 630{
621 return security_ops->task_setuid(id0, id1, id2, flags); 631 return security_ops->task_setuid(id0, id1, id2, flags);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 91b06f2aa963..520f82ab3fbf 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3277,6 +3277,50 @@ static void selinux_cred_commit(struct cred *new, const struct cred *old)
3277 secondary_ops->cred_commit(new, old); 3277 secondary_ops->cred_commit(new, old);
3278} 3278}
3279 3279
3280/*
3281 * set the security data for a kernel service
3282 * - all the creation contexts are set to unlabelled
3283 */
3284static int selinux_kernel_act_as(struct cred *new, u32 secid)
3285{
3286 struct task_security_struct *tsec = new->security;
3287 u32 sid = current_sid();
3288 int ret;
3289
3290 ret = avc_has_perm(sid, secid,
3291 SECCLASS_KERNEL_SERVICE,
3292 KERNEL_SERVICE__USE_AS_OVERRIDE,
3293 NULL);
3294 if (ret == 0) {
3295 tsec->sid = secid;
3296 tsec->create_sid = 0;
3297 tsec->keycreate_sid = 0;
3298 tsec->sockcreate_sid = 0;
3299 }
3300 return ret;
3301}
3302
3303/*
3304 * set the file creation context in a security record to the same as the
3305 * objective context of the specified inode
3306 */
3307static int selinux_kernel_create_files_as(struct cred *new, struct inode *inode)
3308{
3309 struct inode_security_struct *isec = inode->i_security;
3310 struct task_security_struct *tsec = new->security;
3311 u32 sid = current_sid();
3312 int ret;
3313
3314 ret = avc_has_perm(sid, isec->sid,
3315 SECCLASS_KERNEL_SERVICE,
3316 KERNEL_SERVICE__CREATE_FILES_AS,
3317 NULL);
3318
3319 if (ret == 0)
3320 tsec->create_sid = isec->sid;
3321 return 0;
3322}
3323
3280static int selinux_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags) 3324static int selinux_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
3281{ 3325{
3282 /* Since setuid only affects the current process, and 3326 /* Since setuid only affects the current process, and
@@ -5593,6 +5637,8 @@ static struct security_operations selinux_ops = {
5593 .cred_free = selinux_cred_free, 5637 .cred_free = selinux_cred_free,
5594 .cred_prepare = selinux_cred_prepare, 5638 .cred_prepare = selinux_cred_prepare,
5595 .cred_commit = selinux_cred_commit, 5639 .cred_commit = selinux_cred_commit,
5640 .kernel_act_as = selinux_kernel_act_as,
5641 .kernel_create_files_as = selinux_kernel_create_files_as,
5596 .task_setuid = selinux_task_setuid, 5642 .task_setuid = selinux_task_setuid,
5597 .task_fix_setuid = selinux_task_fix_setuid, 5643 .task_fix_setuid = selinux_task_fix_setuid,
5598 .task_setgid = selinux_task_setgid, 5644 .task_setgid = selinux_task_setgid,
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index de396742abf4..8ad48161cef5 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1012,6 +1012,41 @@ static void smack_cred_commit(struct cred *new, const struct cred *old)
1012} 1012}
1013 1013
1014/** 1014/**
1015 * smack_kernel_act_as - Set the subjective context in a set of credentials
1016 * @new points to the set of credentials to be modified.
1017 * @secid specifies the security ID to be set
1018 *
1019 * Set the security data for a kernel service.
1020 */
1021static int smack_kernel_act_as(struct cred *new, u32 secid)
1022{
1023 char *smack = smack_from_secid(secid);
1024
1025 if (smack == NULL)
1026 return -EINVAL;
1027
1028 new->security = smack;
1029 return 0;
1030}
1031
1032/**
1033 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1034 * @new points to the set of credentials to be modified
1035 * @inode points to the inode to use as a reference
1036 *
1037 * Set the file creation context in a set of credentials to the same
1038 * as the objective context of the specified inode
1039 */
1040static int smack_kernel_create_files_as(struct cred *new,
1041 struct inode *inode)
1042{
1043 struct inode_smack *isp = inode->i_security;
1044
1045 new->security = isp->smk_inode;
1046 return 0;
1047}
1048
1049/**
1015 * smack_task_setpgid - Smack check on setting pgid 1050 * smack_task_setpgid - Smack check on setting pgid
1016 * @p: the task object 1051 * @p: the task object
1017 * @pgid: unused 1052 * @pgid: unused
@@ -2641,6 +2676,8 @@ struct security_operations smack_ops = {
2641 .cred_free = smack_cred_free, 2676 .cred_free = smack_cred_free,
2642 .cred_prepare = smack_cred_prepare, 2677 .cred_prepare = smack_cred_prepare,
2643 .cred_commit = smack_cred_commit, 2678 .cred_commit = smack_cred_commit,
2679 .kernel_act_as = smack_kernel_act_as,
2680 .kernel_create_files_as = smack_kernel_create_files_as,
2644 .task_fix_setuid = cap_task_fix_setuid, 2681 .task_fix_setuid = cap_task_fix_setuid,
2645 .task_setpgid = smack_task_setpgid, 2682 .task_setpgid = smack_task_setpgid,
2646 .task_getpgid = smack_task_getpgid, 2683 .task_getpgid = smack_task_getpgid,