@@ -215,7 +215,7 @@ static void cred_init_security(void)
215215 /* NOTE: the lsm framework zeros out the buffer on allocation */
216216
217217 tsec = selinux_cred (unrcu_pointer (current -> real_cred ));
218- tsec -> osid = tsec -> sid = tsec -> avdcache . sid = SECINITSID_KERNEL ;
218+ tsec -> osid = tsec -> sid = SECINITSID_KERNEL ;
219219}
220220
221221/*
@@ -3110,10 +3110,10 @@ static noinline int audit_inode_permission(struct inode *inode,
31103110 * Clear the task's AVD cache in @tsec and reset it to the current policy's
31113111 * and task's info.
31123112 */
3113- static inline void task_avdcache_reset (struct cred_security_struct * tsec )
3113+ static inline void task_avdcache_reset (struct task_security_struct * tsec )
31143114{
31153115 memset (& tsec -> avdcache .dir , 0 , sizeof (tsec -> avdcache .dir ));
3116- tsec -> avdcache .sid = tsec -> sid ;
3116+ tsec -> avdcache .sid = current_sid () ;
31173117 tsec -> avdcache .seqno = avc_policy_seqno ();
31183118 tsec -> avdcache .dir_spot = TSEC_AVDC_DIR_SIZE - 1 ;
31193119}
@@ -3127,7 +3127,7 @@ static inline void task_avdcache_reset(struct cred_security_struct *tsec)
31273127 * Search @tsec for a AVD cache entry that matches @isec and return it to the
31283128 * caller via @avdc. Returns 0 if a match is found, negative values otherwise.
31293129 */
3130- static inline int task_avdcache_search (struct cred_security_struct * tsec ,
3130+ static inline int task_avdcache_search (struct task_security_struct * tsec ,
31313131 struct inode_security_struct * isec ,
31323132 struct avdc_entry * * avdc )
31333133{
@@ -3137,7 +3137,7 @@ static inline int task_avdcache_search(struct cred_security_struct *tsec,
31373137 if (isec -> sclass != SECCLASS_DIR )
31383138 return - ENOENT ;
31393139
3140- if (unlikely (tsec -> sid != tsec -> avdcache .sid ||
3140+ if (unlikely (current_sid () != tsec -> avdcache .sid ||
31413141 tsec -> avdcache .seqno != avc_policy_seqno ())) {
31423142 task_avdcache_reset (tsec );
31433143 return - ENOENT ;
@@ -3167,7 +3167,7 @@ static inline int task_avdcache_search(struct cred_security_struct *tsec,
31673167 * Update the AVD cache in @tsec with the @avdc and @audited info associated
31683168 * with @isec.
31693169 */
3170- static inline void task_avdcache_update (struct cred_security_struct * tsec ,
3170+ static inline void task_avdcache_update (struct task_security_struct * tsec ,
31713171 struct inode_security_struct * isec ,
31723172 struct av_decision * avd ,
31733173 u32 audited )
@@ -3201,7 +3201,8 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32013201{
32023202 int mask ;
32033203 u32 perms ;
3204- struct cred_security_struct * tsec ;
3204+ u32 sid = current_sid ();
3205+ struct task_security_struct * tsec ;
32053206 struct inode_security_struct * isec ;
32063207 struct avdc_entry * avdc ;
32073208 int rc , rc2 ;
@@ -3213,8 +3214,8 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32133214 if (!mask )
32143215 return 0 ;
32153216
3216- tsec = selinux_cred ( current_cred () );
3217- if (task_avdcache_permnoaudit (tsec ))
3217+ tsec = selinux_task ( current );
3218+ if (task_avdcache_permnoaudit (tsec , sid ))
32183219 return 0 ;
32193220
32203221 isec = inode_security_rcu (inode , requested & MAY_NOT_BLOCK );
@@ -3234,7 +3235,7 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32343235 struct av_decision avd ;
32353236
32363237 /* Cache miss. */
3237- rc = avc_has_perm_noaudit (tsec -> sid , isec -> sid , isec -> sclass ,
3238+ rc = avc_has_perm_noaudit (sid , isec -> sid , isec -> sclass ,
32383239 perms , 0 , & avd );
32393240 audited = avc_audit_required (perms , & avd , rc ,
32403241 (requested & MAY_ACCESS ) ? FILE__AUDIT_ACCESS : 0 ,
@@ -3283,11 +3284,11 @@ static int selinux_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
32833284
32843285static int selinux_inode_getattr (const struct path * path )
32853286{
3286- struct cred_security_struct * tsec ;
3287+ struct task_security_struct * tsec ;
32873288
3288- tsec = selinux_cred ( current_cred () );
3289+ tsec = selinux_task ( current );
32893290
3290- if (task_avdcache_permnoaudit (tsec ))
3291+ if (task_avdcache_permnoaudit (tsec , current_sid () ))
32913292 return 0 ;
32923293
32933294 return path_has_perm (current_cred (), path , FILE__GETATTR );
@@ -4151,7 +4152,10 @@ static int selinux_task_alloc(struct task_struct *task,
41514152 u64 clone_flags )
41524153{
41534154 u32 sid = current_sid ();
4155+ struct task_security_struct * old_tsec = selinux_task (current );
4156+ struct task_security_struct * new_tsec = selinux_task (task );
41544157
4158+ * new_tsec = * old_tsec ;
41554159 return avc_has_perm (sid , sid , SECCLASS_PROCESS , PROCESS__FORK , NULL );
41564160}
41574161
@@ -7138,6 +7142,7 @@ static int selinux_bpf_token_create(struct bpf_token *token, union bpf_attr *att
71387142
71397143struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
71407144 .lbs_cred = sizeof (struct cred_security_struct ),
7145+ .lbs_task = sizeof (struct task_security_struct ),
71417146 .lbs_file = sizeof (struct file_security_struct ),
71427147 .lbs_inode = sizeof (struct inode_security_struct ),
71437148 .lbs_ipc = sizeof (struct ipc_security_struct ),
0 commit comments