@@ -229,10 +229,23 @@ static inline u32 cred_sid(const struct cred *cred)
229
229
return tsec -> sid ;
230
230
}
231
231
232
+ /*
233
+ * get the subjective security ID of a task
234
+ */
235
+ static inline u32 task_sid_subj (const struct task_struct * task )
236
+ {
237
+ u32 sid ;
238
+
239
+ rcu_read_lock ();
240
+ sid = cred_sid (rcu_dereference (task -> cred ));
241
+ rcu_read_unlock ();
242
+ return sid ;
243
+ }
244
+
232
245
/*
233
246
* get the objective security ID of a task
234
247
*/
235
- static inline u32 task_sid (const struct task_struct * task )
248
+ static inline u32 task_sid_obj (const struct task_struct * task )
236
249
{
237
250
u32 sid ;
238
251
@@ -242,6 +255,29 @@ static inline u32 task_sid(const struct task_struct *task)
242
255
return sid ;
243
256
}
244
257
258
+ /*
259
+ * get the security ID of a task for use with binder
260
+ */
261
+ static inline u32 task_sid_binder (const struct task_struct * task )
262
+ {
263
+ /*
264
+ * In many case where this function is used we should be using the
265
+ * task's subjective SID, but we can't reliably access the subjective
266
+ * creds of a task other than our own so we must use the objective
267
+ * creds/SID, which are safe to access. The downside is that if a task
268
+ * is temporarily overriding it's creds it will not be reflected here;
269
+ * however, it isn't clear that binder would handle that case well
270
+ * anyway.
271
+ *
272
+ * If this ever changes and we can safely reference the subjective
273
+ * creds/SID of another task, this function will make it easier to
274
+ * identify the various places where we make use of the task SIDs in
275
+ * the binder code. It is also likely that we will need to adjust
276
+ * the main drivers/android binder code as well.
277
+ */
278
+ return task_sid_obj (task );
279
+ }
280
+
245
281
static int inode_doinit_with_dentry (struct inode * inode , struct dentry * opt_dentry );
246
282
247
283
/*
@@ -2035,20 +2071,16 @@ static inline u32 open_file_to_av(struct file *file)
2035
2071
2036
2072
static int selinux_binder_set_context_mgr (struct task_struct * mgr )
2037
2073
{
2038
- u32 mysid = current_sid ();
2039
- u32 mgrsid = task_sid (mgr );
2040
-
2041
2074
return avc_has_perm (& selinux_state ,
2042
- mysid , mgrsid , SECCLASS_BINDER ,
2075
+ current_sid (), task_sid_binder ( mgr ) , SECCLASS_BINDER ,
2043
2076
BINDER__SET_CONTEXT_MGR , NULL );
2044
2077
}
2045
2078
2046
2079
static int selinux_binder_transaction (struct task_struct * from ,
2047
2080
struct task_struct * to )
2048
2081
{
2049
2082
u32 mysid = current_sid ();
2050
- u32 fromsid = task_sid (from );
2051
- u32 tosid = task_sid (to );
2083
+ u32 fromsid = task_sid_binder (from );
2052
2084
int rc ;
2053
2085
2054
2086
if (mysid != fromsid ) {
@@ -2059,27 +2091,24 @@ static int selinux_binder_transaction(struct task_struct *from,
2059
2091
return rc ;
2060
2092
}
2061
2093
2062
- return avc_has_perm (& selinux_state ,
2063
- fromsid , tosid , SECCLASS_BINDER , BINDER__CALL ,
2064
- NULL );
2094
+ return avc_has_perm (& selinux_state , fromsid , task_sid_binder (to ),
2095
+ SECCLASS_BINDER , BINDER__CALL , NULL );
2065
2096
}
2066
2097
2067
2098
static int selinux_binder_transfer_binder (struct task_struct * from ,
2068
2099
struct task_struct * to )
2069
2100
{
2070
- u32 fromsid = task_sid (from );
2071
- u32 tosid = task_sid (to );
2072
-
2073
2101
return avc_has_perm (& selinux_state ,
2074
- fromsid , tosid , SECCLASS_BINDER , BINDER__TRANSFER ,
2102
+ task_sid_binder (from ), task_sid_binder (to ),
2103
+ SECCLASS_BINDER , BINDER__TRANSFER ,
2075
2104
NULL );
2076
2105
}
2077
2106
2078
2107
static int selinux_binder_transfer_file (struct task_struct * from ,
2079
2108
struct task_struct * to ,
2080
2109
struct file * file )
2081
2110
{
2082
- u32 sid = task_sid (to );
2111
+ u32 sid = task_sid_binder (to );
2083
2112
struct file_security_struct * fsec = selinux_file (file );
2084
2113
struct dentry * dentry = file -> f_path .dentry ;
2085
2114
struct inode_security_struct * isec ;
@@ -2115,10 +2144,10 @@ static int selinux_binder_transfer_file(struct task_struct *from,
2115
2144
}
2116
2145
2117
2146
static int selinux_ptrace_access_check (struct task_struct * child ,
2118
- unsigned int mode )
2147
+ unsigned int mode )
2119
2148
{
2120
2149
u32 sid = current_sid ();
2121
- u32 csid = task_sid (child );
2150
+ u32 csid = task_sid_obj (child );
2122
2151
2123
2152
if (mode & PTRACE_MODE_READ )
2124
2153
return avc_has_perm (& selinux_state ,
@@ -2131,15 +2160,15 @@ static int selinux_ptrace_access_check(struct task_struct *child,
2131
2160
static int selinux_ptrace_traceme (struct task_struct * parent )
2132
2161
{
2133
2162
return avc_has_perm (& selinux_state ,
2134
- task_sid (parent ), current_sid (), SECCLASS_PROCESS ,
2135
- PROCESS__PTRACE , NULL );
2163
+ task_sid_subj (parent ), task_sid_obj ( current ) ,
2164
+ SECCLASS_PROCESS , PROCESS__PTRACE , NULL );
2136
2165
}
2137
2166
2138
2167
static int selinux_capget (struct task_struct * target , kernel_cap_t * effective ,
2139
2168
kernel_cap_t * inheritable , kernel_cap_t * permitted )
2140
2169
{
2141
2170
return avc_has_perm (& selinux_state ,
2142
- current_sid (), task_sid (target ), SECCLASS_PROCESS ,
2171
+ current_sid (), task_sid_obj (target ), SECCLASS_PROCESS ,
2143
2172
PROCESS__GETCAP , NULL );
2144
2173
}
2145
2174
@@ -2264,7 +2293,7 @@ static u32 ptrace_parent_sid(void)
2264
2293
rcu_read_lock ();
2265
2294
tracer = ptrace_parent (current );
2266
2295
if (tracer )
2267
- sid = task_sid (tracer );
2296
+ sid = task_sid_obj (tracer );
2268
2297
rcu_read_unlock ();
2269
2298
2270
2299
return sid ;
@@ -3976,7 +4005,7 @@ static int selinux_file_send_sigiotask(struct task_struct *tsk,
3976
4005
struct fown_struct * fown , int signum )
3977
4006
{
3978
4007
struct file * file ;
3979
- u32 sid = task_sid (tsk );
4008
+ u32 sid = task_sid_obj (tsk );
3980
4009
u32 perm ;
3981
4010
struct file_security_struct * fsec ;
3982
4011
@@ -4195,47 +4224,52 @@ static int selinux_kernel_load_data(enum kernel_load_data_id id, bool contents)
4195
4224
static int selinux_task_setpgid (struct task_struct * p , pid_t pgid )
4196
4225
{
4197
4226
return avc_has_perm (& selinux_state ,
4198
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4227
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4199
4228
PROCESS__SETPGID , NULL );
4200
4229
}
4201
4230
4202
4231
static int selinux_task_getpgid (struct task_struct * p )
4203
4232
{
4204
4233
return avc_has_perm (& selinux_state ,
4205
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4234
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4206
4235
PROCESS__GETPGID , NULL );
4207
4236
}
4208
4237
4209
4238
static int selinux_task_getsid (struct task_struct * p )
4210
4239
{
4211
4240
return avc_has_perm (& selinux_state ,
4212
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4241
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4213
4242
PROCESS__GETSESSION , NULL );
4214
4243
}
4215
4244
4216
- static void selinux_task_getsecid (struct task_struct * p , u32 * secid )
4245
+ static void selinux_task_getsecid_subj (struct task_struct * p , u32 * secid )
4246
+ {
4247
+ * secid = task_sid_subj (p );
4248
+ }
4249
+
4250
+ static void selinux_task_getsecid_obj (struct task_struct * p , u32 * secid )
4217
4251
{
4218
- * secid = task_sid (p );
4252
+ * secid = task_sid_obj (p );
4219
4253
}
4220
4254
4221
4255
static int selinux_task_setnice (struct task_struct * p , int nice )
4222
4256
{
4223
4257
return avc_has_perm (& selinux_state ,
4224
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4258
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4225
4259
PROCESS__SETSCHED , NULL );
4226
4260
}
4227
4261
4228
4262
static int selinux_task_setioprio (struct task_struct * p , int ioprio )
4229
4263
{
4230
4264
return avc_has_perm (& selinux_state ,
4231
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4265
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4232
4266
PROCESS__SETSCHED , NULL );
4233
4267
}
4234
4268
4235
4269
static int selinux_task_getioprio (struct task_struct * p )
4236
4270
{
4237
4271
return avc_has_perm (& selinux_state ,
4238
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4272
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4239
4273
PROCESS__GETSCHED , NULL );
4240
4274
}
4241
4275
@@ -4266,7 +4300,7 @@ static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource,
4266
4300
upon context transitions. See selinux_bprm_committing_creds. */
4267
4301
if (old_rlim -> rlim_max != new_rlim -> rlim_max )
4268
4302
return avc_has_perm (& selinux_state ,
4269
- current_sid (), task_sid (p ),
4303
+ current_sid (), task_sid_obj (p ),
4270
4304
SECCLASS_PROCESS , PROCESS__SETRLIMIT , NULL );
4271
4305
4272
4306
return 0 ;
@@ -4275,21 +4309,21 @@ static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource,
4275
4309
static int selinux_task_setscheduler (struct task_struct * p )
4276
4310
{
4277
4311
return avc_has_perm (& selinux_state ,
4278
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4312
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4279
4313
PROCESS__SETSCHED , NULL );
4280
4314
}
4281
4315
4282
4316
static int selinux_task_getscheduler (struct task_struct * p )
4283
4317
{
4284
4318
return avc_has_perm (& selinux_state ,
4285
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4319
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4286
4320
PROCESS__GETSCHED , NULL );
4287
4321
}
4288
4322
4289
4323
static int selinux_task_movememory (struct task_struct * p )
4290
4324
{
4291
4325
return avc_has_perm (& selinux_state ,
4292
- current_sid (), task_sid (p ), SECCLASS_PROCESS ,
4326
+ current_sid (), task_sid_obj (p ), SECCLASS_PROCESS ,
4293
4327
PROCESS__SETSCHED , NULL );
4294
4328
}
4295
4329
@@ -4308,14 +4342,14 @@ static int selinux_task_kill(struct task_struct *p, struct kernel_siginfo *info,
4308
4342
else
4309
4343
secid = cred_sid (cred );
4310
4344
return avc_has_perm (& selinux_state ,
4311
- secid , task_sid (p ), SECCLASS_PROCESS , perm , NULL );
4345
+ secid , task_sid_obj (p ), SECCLASS_PROCESS , perm , NULL );
4312
4346
}
4313
4347
4314
4348
static void selinux_task_to_inode (struct task_struct * p ,
4315
4349
struct inode * inode )
4316
4350
{
4317
4351
struct inode_security_struct * isec = selinux_inode (inode );
4318
- u32 sid = task_sid (p );
4352
+ u32 sid = task_sid_obj (p );
4319
4353
4320
4354
spin_lock (& isec -> lock );
4321
4355
isec -> sclass = inode_mode_to_security_class (inode -> i_mode );
@@ -6208,7 +6242,7 @@ static int selinux_msg_queue_msgrcv(struct kern_ipc_perm *msq, struct msg_msg *m
6208
6242
struct ipc_security_struct * isec ;
6209
6243
struct msg_security_struct * msec ;
6210
6244
struct common_audit_data ad ;
6211
- u32 sid = task_sid (target );
6245
+ u32 sid = task_sid_subj (target );
6212
6246
int rc ;
6213
6247
6214
6248
isec = selinux_ipc (msq );
@@ -7205,8 +7239,8 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
7205
7239
LSM_HOOK_INIT (task_setpgid , selinux_task_setpgid ),
7206
7240
LSM_HOOK_INIT (task_getpgid , selinux_task_getpgid ),
7207
7241
LSM_HOOK_INIT (task_getsid , selinux_task_getsid ),
7208
- LSM_HOOK_INIT (task_getsecid_subj , selinux_task_getsecid ),
7209
- LSM_HOOK_INIT (task_getsecid_obj , selinux_task_getsecid ),
7242
+ LSM_HOOK_INIT (task_getsecid_subj , selinux_task_getsecid_subj ),
7243
+ LSM_HOOK_INIT (task_getsecid_obj , selinux_task_getsecid_obj ),
7210
7244
LSM_HOOK_INIT (task_setnice , selinux_task_setnice ),
7211
7245
LSM_HOOK_INIT (task_setioprio , selinux_task_setioprio ),
7212
7246
LSM_HOOK_INIT (task_getioprio , selinux_task_getioprio ),
0 commit comments