@@ -48,32 +48,30 @@ static DEFINE_PER_CPU(struct audit_cache, audit_cache);
4848static void audit_cb (struct audit_buffer * ab , void * va )
4949{
5050 struct common_audit_data * sa = va ;
51+
5152 audit_log_format (ab , " capname=" );
5253 audit_log_untrustedstring (ab , capability_names [sa -> u .cap ]);
5354}
5455
5556/**
5657 * audit_caps - audit a capability
58+ * @sa: audit data
5759 * @profile: profile being tested for confinement (NOT NULL)
5860 * @cap: capability tested
59- @audit: whether an audit record should be generated
6061 * @error: error code returned by test
6162 *
6263 * Do auditing of capability and handle, audit/complain/kill modes switching
6364 * and duplicate message elimination.
6465 *
6566 * Returns: 0 or sa->error on success, error code on failure
6667 */
67- static int audit_caps (struct aa_profile * profile , int cap , int audit ,
68- int error )
68+ static int audit_caps (struct common_audit_data * sa , struct aa_profile * profile ,
69+ int cap , int error )
6970{
7071 struct audit_cache * ent ;
7172 int type = AUDIT_APPARMOR_AUTO ;
72- DEFINE_AUDIT_DATA (sa , LSM_AUDIT_DATA_CAP , OP_CAPABLE );
73- sa .u .cap = cap ;
74- aad (& sa )-> error = error ;
75- if (audit == SECURITY_CAP_NOAUDIT )
76- aad (& sa )-> info = "optional: no audit" ;
73+
74+ aad (sa )-> error = error ;
7775
7876 if (likely (!error )) {
7977 /* test if auditing is being forced */
@@ -105,39 +103,60 @@ static int audit_caps(struct aa_profile *profile, int cap, int audit,
105103 }
106104 put_cpu_var (audit_cache );
107105
108- return aa_audit (type , profile , & sa , audit_cb );
106+ return aa_audit (type , profile , sa , audit_cb );
109107}
110108
111109/**
112110 * profile_capable - test if profile allows use of capability @cap
113111 * @profile: profile being enforced (NOT NULL, NOT unconfined)
114112 * @cap: capability to test if allowed
113+ * @audit: whether an audit record should be generated
114+ * @sa: audit data (MAY BE NULL indicating no auditing)
115115 *
116116 * Returns: 0 if allowed else -EPERM
117117 */
118- static int profile_capable (struct aa_profile * profile , int cap )
118+ static int profile_capable (struct aa_profile * profile , int cap , int audit ,
119+ struct common_audit_data * sa )
119120{
120- return cap_raised (profile -> caps .allow , cap ) ? 0 : - EPERM ;
121+ int error ;
122+
123+ if (cap_raised (profile -> caps .allow , cap ) &&
124+ !cap_raised (profile -> caps .denied , cap ))
125+ error = 0 ;
126+ else
127+ error = - EPERM ;
128+
129+ if (audit == SECURITY_CAP_NOAUDIT ) {
130+ if (!COMPLAIN_MODE (profile ))
131+ return error ;
132+ /* audit the cap request in complain mode but note that it
133+ * should be optional.
134+ */
135+ aad (sa )-> info = "optional: no audit" ;
136+ }
137+
138+ return audit_caps (sa , profile , cap , error );
121139}
122140
123141/**
124142 * aa_capable - test permission to use capability
125- * @profile: profile being tested against (NOT NULL)
143+ * @label: label being tested for capability (NOT NULL)
126144 * @cap: capability to be tested
127145 * @audit: whether an audit record should be generated
128146 *
129147 * Look up capability in profile capability set.
130148 *
131149 * Returns: 0 on success, or else an error code.
132150 */
133- int aa_capable (struct aa_profile * profile , int cap , int audit )
151+ int aa_capable (struct aa_label * label , int cap , int audit )
134152{
135- int error = profile_capable (profile , cap );
153+ struct aa_profile * profile ;
154+ int error = 0 ;
155+ DEFINE_AUDIT_DATA (sa , LSM_AUDIT_DATA_CAP , OP_CAPABLE );
136156
137- if (audit == SECURITY_CAP_NOAUDIT ) {
138- if (!COMPLAIN_MODE (profile ))
139- return error ;
140- }
157+ sa .u .cap = cap ;
158+ error = fn_for_each_confined (label , profile ,
159+ profile_capable (profile , cap , audit , & sa ));
141160
142- return audit_caps ( profile , cap , audit , error ) ;
161+ return error ;
143162}
0 commit comments