@@ -127,14 +127,15 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
127
127
struct aa_label * tracer , * tracee ;
128
128
const struct cred * cred ;
129
129
int error ;
130
+ bool needput ;
130
131
131
132
cred = get_task_cred (child );
132
133
tracee = cred_label (cred ); /* ref count on cred */
133
- tracer = __begin_current_label_crit_section ();
134
+ tracer = __begin_current_label_crit_section (& needput );
134
135
error = aa_may_ptrace (current_cred (), tracer , cred , tracee ,
135
136
(mode & PTRACE_MODE_READ ) ? AA_PTRACE_READ
136
137
: AA_PTRACE_TRACE );
137
- __end_current_label_crit_section (tracer );
138
+ __end_current_label_crit_section (tracer , needput );
138
139
put_cred (cred );
139
140
140
141
return error ;
@@ -145,14 +146,15 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
145
146
struct aa_label * tracer , * tracee ;
146
147
const struct cred * cred ;
147
148
int error ;
149
+ bool needput ;
148
150
149
- tracee = __begin_current_label_crit_section ();
151
+ tracee = __begin_current_label_crit_section (& needput );
150
152
cred = get_task_cred (parent );
151
153
tracer = cred_label (cred ); /* ref count on cred */
152
154
error = aa_may_ptrace (cred , tracer , current_cred (), tracee ,
153
155
AA_PTRACE_TRACE );
154
156
put_cred (cred );
155
- __end_current_label_crit_section (tracee );
157
+ __end_current_label_crit_section (tracee , needput );
156
158
157
159
return error ;
158
160
}
@@ -221,12 +223,13 @@ static int common_perm(const char *op, const struct path *path, u32 mask,
221
223
{
222
224
struct aa_label * label ;
223
225
int error = 0 ;
226
+ bool needput ;
224
227
225
- label = __begin_current_label_crit_section ();
228
+ label = __begin_current_label_crit_section (& needput );
226
229
if (!unconfined (label ))
227
230
error = aa_path_perm (op , current_cred (), label , path , 0 , mask ,
228
231
cond );
229
- __end_current_label_crit_section (label );
232
+ __end_current_label_crit_section (label , needput );
230
233
231
234
return error ;
232
235
}
@@ -524,14 +527,15 @@ static int common_file_perm(const char *op, struct file *file, u32 mask,
524
527
{
525
528
struct aa_label * label ;
526
529
int error = 0 ;
530
+ bool needput ;
527
531
528
532
/* don't reaudit files closed during inheritance */
529
- if (file -> f_path .dentry == aa_null .dentry )
533
+ if (unlikely ( file -> f_path .dentry == aa_null .dentry ) )
530
534
return - EACCES ;
531
535
532
- label = __begin_current_label_crit_section ();
536
+ label = __begin_current_label_crit_section (& needput );
533
537
error = aa_file_perm (op , current_cred (), label , file , mask , in_atomic );
534
- __end_current_label_crit_section (label );
538
+ __end_current_label_crit_section (label , needput );
535
539
536
540
return error ;
537
541
}
@@ -664,15 +668,16 @@ static int apparmor_uring_override_creds(const struct cred *new)
664
668
struct aa_profile * profile ;
665
669
struct aa_label * label ;
666
670
int error ;
671
+ bool needput ;
667
672
DEFINE_AUDIT_DATA (ad , LSM_AUDIT_DATA_NONE , AA_CLASS_IO_URING ,
668
673
OP_URING_OVERRIDE );
669
674
670
675
ad .uring .target = cred_label (new );
671
- label = __begin_current_label_crit_section ();
676
+ label = __begin_current_label_crit_section (& needput );
672
677
error = fn_for_each (label , profile ,
673
678
profile_uring (profile , AA_MAY_OVERRIDE_CRED ,
674
679
cred_label (new ), CAP_SYS_ADMIN , & ad ));
675
- __end_current_label_crit_section (label );
680
+ __end_current_label_crit_section (label , needput );
676
681
677
682
return error ;
678
683
}
@@ -688,14 +693,15 @@ static int apparmor_uring_sqpoll(void)
688
693
struct aa_profile * profile ;
689
694
struct aa_label * label ;
690
695
int error ;
696
+ bool needput ;
691
697
DEFINE_AUDIT_DATA (ad , LSM_AUDIT_DATA_NONE , AA_CLASS_IO_URING ,
692
698
OP_URING_SQPOLL );
693
699
694
- label = __begin_current_label_crit_section ();
700
+ label = __begin_current_label_crit_section (& needput );
695
701
error = fn_for_each (label , profile ,
696
702
profile_uring (profile , AA_MAY_CREATE_SQPOLL ,
697
703
NULL , CAP_SYS_ADMIN , & ad ));
698
- __end_current_label_crit_section (label );
704
+ __end_current_label_crit_section (label , needput );
699
705
700
706
return error ;
701
707
}
@@ -706,14 +712,15 @@ static int apparmor_sb_mount(const char *dev_name, const struct path *path,
706
712
{
707
713
struct aa_label * label ;
708
714
int error = 0 ;
715
+ bool needput ;
709
716
710
717
/* Discard magic */
711
718
if ((flags & MS_MGC_MSK ) == MS_MGC_VAL )
712
719
flags &= ~MS_MGC_MSK ;
713
720
714
721
flags &= ~AA_MS_IGNORE_MASK ;
715
722
716
- label = __begin_current_label_crit_section ();
723
+ label = __begin_current_label_crit_section (& needput );
717
724
if (!unconfined (label )) {
718
725
if (flags & MS_REMOUNT )
719
726
error = aa_remount (current_cred (), label , path , flags ,
@@ -732,7 +739,7 @@ static int apparmor_sb_mount(const char *dev_name, const struct path *path,
732
739
error = aa_new_mount (current_cred (), label , dev_name ,
733
740
path , type , flags , data );
734
741
}
735
- __end_current_label_crit_section (label );
742
+ __end_current_label_crit_section (label , needput );
736
743
737
744
return error ;
738
745
}
@@ -742,12 +749,13 @@ static int apparmor_move_mount(const struct path *from_path,
742
749
{
743
750
struct aa_label * label ;
744
751
int error = 0 ;
752
+ bool needput ;
745
753
746
- label = __begin_current_label_crit_section ();
754
+ label = __begin_current_label_crit_section (& needput );
747
755
if (!unconfined (label ))
748
756
error = aa_move_mount (current_cred (), label , from_path ,
749
757
to_path );
750
- __end_current_label_crit_section (label );
758
+ __end_current_label_crit_section (label , needput );
751
759
752
760
return error ;
753
761
}
@@ -756,11 +764,12 @@ static int apparmor_sb_umount(struct vfsmount *mnt, int flags)
756
764
{
757
765
struct aa_label * label ;
758
766
int error = 0 ;
767
+ bool needput ;
759
768
760
- label = __begin_current_label_crit_section ();
769
+ label = __begin_current_label_crit_section (& needput );
761
770
if (!unconfined (label ))
762
771
error = aa_umount (current_cred (), label , mnt , flags );
763
- __end_current_label_crit_section (label );
772
+ __end_current_label_crit_section (label , needput );
764
773
765
774
return error ;
766
775
}
@@ -984,10 +993,12 @@ static void apparmor_bprm_committed_creds(const struct linux_binprm *bprm)
984
993
985
994
static void apparmor_current_getlsmprop_subj (struct lsm_prop * prop )
986
995
{
987
- struct aa_label * label = __begin_current_label_crit_section ();
996
+ struct aa_label * label ;
997
+ bool needput ;
988
998
999
+ label = __begin_current_label_crit_section (& needput );
989
1000
prop -> apparmor .label = label ;
990
- __end_current_label_crit_section (label );
1001
+ __end_current_label_crit_section (label , needput );
991
1002
}
992
1003
993
1004
static void apparmor_task_getlsmprop_obj (struct task_struct * p ,
@@ -1002,13 +1013,16 @@ static void apparmor_task_getlsmprop_obj(struct task_struct *p,
1002
1013
static int apparmor_task_setrlimit (struct task_struct * task ,
1003
1014
unsigned int resource , struct rlimit * new_rlim )
1004
1015
{
1005
- struct aa_label * label = __begin_current_label_crit_section () ;
1016
+ struct aa_label * label ;
1006
1017
int error = 0 ;
1018
+ bool needput ;
1019
+
1020
+ label = __begin_current_label_crit_section (& needput );
1007
1021
1008
1022
if (!unconfined (label ))
1009
1023
error = aa_task_setrlimit (current_cred (), label , task ,
1010
1024
resource , new_rlim );
1011
- __end_current_label_crit_section (label );
1025
+ __end_current_label_crit_section (label , needput );
1012
1026
1013
1027
return error ;
1014
1028
}
@@ -1019,6 +1033,7 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
1019
1033
const struct cred * tc ;
1020
1034
struct aa_label * cl , * tl ;
1021
1035
int error ;
1036
+ bool needput ;
1022
1037
1023
1038
tc = get_task_cred (target );
1024
1039
tl = aa_get_newest_cred_label (tc );
@@ -1030,9 +1045,9 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
1030
1045
error = aa_may_signal (cred , cl , tc , tl , sig );
1031
1046
aa_put_label (cl );
1032
1047
} else {
1033
- cl = __begin_current_label_crit_section ();
1048
+ cl = __begin_current_label_crit_section (& needput );
1034
1049
error = aa_may_signal (current_cred (), cl , tc , tl , sig );
1035
- __end_current_label_crit_section (cl );
1050
+ __end_current_label_crit_section (cl , needput );
1036
1051
}
1037
1052
aa_put_label (tl );
1038
1053
put_cred (tc );
@@ -1133,10 +1148,11 @@ static int apparmor_unix_stream_connect(struct sock *sk, struct sock *peer_sk,
1133
1148
struct aa_sk_ctx * new_ctx = aa_sock (newsk );
1134
1149
struct aa_label * label ;
1135
1150
int error ;
1151
+ bool needput ;
1136
1152
1137
- label = __begin_current_label_crit_section ();
1153
+ label = __begin_current_label_crit_section (& needput );
1138
1154
error = unix_connect_perm (current_cred (), label , sk , peer_sk );
1139
- __end_current_label_crit_section (label );
1155
+ __end_current_label_crit_section (label , needput );
1140
1156
1141
1157
if (error )
1142
1158
return error ;
@@ -1163,16 +1179,17 @@ static int apparmor_unix_may_send(struct socket *sock, struct socket *peer)
1163
1179
struct aa_sk_ctx * peer_ctx = aa_sock (peer -> sk );
1164
1180
struct aa_label * label ;
1165
1181
int error ;
1182
+ bool needput ;
1166
1183
1167
- label = __begin_current_label_crit_section ();
1184
+ label = __begin_current_label_crit_section (& needput );
1168
1185
error = xcheck (aa_unix_peer_perm (current_cred (),
1169
1186
label , OP_SENDMSG , AA_MAY_SEND ,
1170
1187
sock -> sk , peer -> sk , NULL ),
1171
1188
aa_unix_peer_perm (peer -> file ? peer -> file -> f_cred : NULL ,
1172
1189
peer_ctx -> label , OP_SENDMSG ,
1173
1190
AA_MAY_RECEIVE ,
1174
1191
peer -> sk , sock -> sk , label ));
1175
- __end_current_label_crit_section (label );
1192
+ __end_current_label_crit_section (label , needput );
1176
1193
1177
1194
return error ;
1178
1195
}
0 commit comments