aboutsummaryrefslogtreecommitdiffstats
path: root/security/smack
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2008-11-13 18:39:19 -0500
committerJames Morris <jmorris@namei.org>2008-11-13 18:39:19 -0500
commitc69e8d9c01db2adc503464993c358901c9af9de4 (patch)
treebed94aaa9aeb7a7834d1c880f72b62a11a752c78 /security/smack
parent86a264abe542cfececb4df129bc45a0338d8cdb9 (diff)
CRED: Use RCU to access another task's creds and to release a task's own creds
Use RCU to access another task's creds and to release a task's own creds. This means that it will be possible for the credentials of a task to be replaced without another task (a) requiring a full lock to read them, and (b) seeing deallocated memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: James Morris <jmorris@namei.org> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/smack')
-rw-r--r--security/smack/smack_lsm.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index e8a4fcb1ad04..11167fd567b9 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -30,6 +30,8 @@
30 30
31#include "smack.h" 31#include "smack.h"
32 32
33#define task_security(task) (task_cred_xxx((task), security))
34
33/* 35/*
34 * I hope these are the hokeyist lines of code in the module. Casey. 36 * I hope these are the hokeyist lines of code in the module. Casey.
35 */ 37 */
@@ -1012,7 +1014,7 @@ static void smack_cred_free(struct cred *cred)
1012 */ 1014 */
1013static int smack_task_setpgid(struct task_struct *p, pid_t pgid) 1015static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1014{ 1016{
1015 return smk_curacc(p->cred->security, MAY_WRITE); 1017 return smk_curacc(task_security(p), MAY_WRITE);
1016} 1018}
1017 1019
1018/** 1020/**
@@ -1023,7 +1025,7 @@ static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1023 */ 1025 */
1024static int smack_task_getpgid(struct task_struct *p) 1026static int smack_task_getpgid(struct task_struct *p)
1025{ 1027{
1026 return smk_curacc(p->cred->security, MAY_READ); 1028 return smk_curacc(task_security(p), MAY_READ);
1027} 1029}
1028 1030
1029/** 1031/**
@@ -1034,7 +1036,7 @@ static int smack_task_getpgid(struct task_struct *p)
1034 */ 1036 */
1035static int smack_task_getsid(struct task_struct *p) 1037static int smack_task_getsid(struct task_struct *p)
1036{ 1038{
1037 return smk_curacc(p->cred->security, MAY_READ); 1039 return smk_curacc(task_security(p), MAY_READ);
1038} 1040}
1039 1041
1040/** 1042/**
@@ -1046,7 +1048,7 @@ static int smack_task_getsid(struct task_struct *p)
1046 */ 1048 */
1047static void smack_task_getsecid(struct task_struct *p, u32 *secid) 1049static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1048{ 1050{
1049 *secid = smack_to_secid(p->cred->security); 1051 *secid = smack_to_secid(task_security(p));
1050} 1052}
1051 1053
1052/** 1054/**
@@ -1062,7 +1064,7 @@ static int smack_task_setnice(struct task_struct *p, int nice)
1062 1064
1063 rc = cap_task_setnice(p, nice); 1065 rc = cap_task_setnice(p, nice);
1064 if (rc == 0) 1066 if (rc == 0)
1065 rc = smk_curacc(p->cred->security, MAY_WRITE); 1067 rc = smk_curacc(task_security(p), MAY_WRITE);
1066 return rc; 1068 return rc;
1067} 1069}
1068 1070
@@ -1079,7 +1081,7 @@ static int smack_task_setioprio(struct task_struct *p, int ioprio)
1079 1081
1080 rc = cap_task_setioprio(p, ioprio); 1082 rc = cap_task_setioprio(p, ioprio);
1081 if (rc == 0) 1083 if (rc == 0)
1082 rc = smk_curacc(p->cred->security, MAY_WRITE); 1084 rc = smk_curacc(task_security(p), MAY_WRITE);
1083 return rc; 1085 return rc;
1084} 1086}
1085 1087
@@ -1091,7 +1093,7 @@ static int smack_task_setioprio(struct task_struct *p, int ioprio)
1091 */ 1093 */
1092static int smack_task_getioprio(struct task_struct *p) 1094static int smack_task_getioprio(struct task_struct *p)
1093{ 1095{
1094 return smk_curacc(p->cred->security, MAY_READ); 1096 return smk_curacc(task_security(p), MAY_READ);
1095} 1097}
1096 1098
1097/** 1099/**
@@ -1109,7 +1111,7 @@ static int smack_task_setscheduler(struct task_struct *p, int policy,
1109 1111
1110 rc = cap_task_setscheduler(p, policy, lp); 1112 rc = cap_task_setscheduler(p, policy, lp);
1111 if (rc == 0) 1113 if (rc == 0)
1112 rc = smk_curacc(p->cred->security, MAY_WRITE); 1114 rc = smk_curacc(task_security(p), MAY_WRITE);
1113 return rc; 1115 return rc;
1114} 1116}
1115 1117
@@ -1121,7 +1123,7 @@ static int smack_task_setscheduler(struct task_struct *p, int policy,
1121 */ 1123 */
1122static int smack_task_getscheduler(struct task_struct *p) 1124static int smack_task_getscheduler(struct task_struct *p)
1123{ 1125{
1124 return smk_curacc(p->cred->security, MAY_READ); 1126 return smk_curacc(task_security(p), MAY_READ);
1125} 1127}
1126 1128
1127/** 1129/**
@@ -1132,7 +1134,7 @@ static int smack_task_getscheduler(struct task_struct *p)
1132 */ 1134 */
1133static int smack_task_movememory(struct task_struct *p) 1135static int smack_task_movememory(struct task_struct *p)
1134{ 1136{
1135 return smk_curacc(p->cred->security, MAY_WRITE); 1137 return smk_curacc(task_security(p), MAY_WRITE);
1136} 1138}
1137 1139
1138/** 1140/**
@@ -1155,13 +1157,13 @@ static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1155 * can write the receiver. 1157 * can write the receiver.
1156 */ 1158 */
1157 if (secid == 0) 1159 if (secid == 0)
1158 return smk_curacc(p->cred->security, MAY_WRITE); 1160 return smk_curacc(task_security(p), MAY_WRITE);
1159 /* 1161 /*
1160 * If the secid isn't 0 we're dealing with some USB IO 1162 * If the secid isn't 0 we're dealing with some USB IO
1161 * specific behavior. This is not clean. For one thing 1163 * specific behavior. This is not clean. For one thing
1162 * we can't take privilege into account. 1164 * we can't take privilege into account.
1163 */ 1165 */
1164 return smk_access(smack_from_secid(secid), p->cred->security, MAY_WRITE); 1166 return smk_access(smack_from_secid(secid), task_security(p), MAY_WRITE);
1165} 1167}
1166 1168
1167/** 1169/**
@@ -1174,7 +1176,7 @@ static int smack_task_wait(struct task_struct *p)
1174{ 1176{
1175 int rc; 1177 int rc;
1176 1178
1177 rc = smk_access(current->cred->security, p->cred->security, MAY_WRITE); 1179 rc = smk_access(current_security(), task_security(p), MAY_WRITE);
1178 if (rc == 0) 1180 if (rc == 0)
1179 return 0; 1181 return 0;
1180 1182
@@ -1205,7 +1207,7 @@ static int smack_task_wait(struct task_struct *p)
1205static void smack_task_to_inode(struct task_struct *p, struct inode *inode) 1207static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1206{ 1208{
1207 struct inode_smack *isp = inode->i_security; 1209 struct inode_smack *isp = inode->i_security;
1208 isp->smk_inode = p->cred->security; 1210 isp->smk_inode = task_security(p);
1209} 1211}
1210 1212
1211/* 1213/*
@@ -2010,7 +2012,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2010 if (strcmp(name, "current") != 0) 2012 if (strcmp(name, "current") != 0)
2011 return -EINVAL; 2013 return -EINVAL;
2012 2014
2013 cp = kstrdup(p->cred->security, GFP_KERNEL); 2015 cp = kstrdup(task_security(p), GFP_KERNEL);
2014 if (cp == NULL) 2016 if (cp == NULL)
2015 return -ENOMEM; 2017 return -ENOMEM;
2016 2018