@@ -184,9 +184,7 @@ sepgsql_exec_check_perms(List *rangeTabls, bool abort)
184
184
static bool
185
185
sepgsql_needs_fmgr_hook (Oid functionId )
186
186
{
187
- char * old_label ;
188
- char * new_label ;
189
- char * function_label ;
187
+ ObjectAddress object ;
190
188
191
189
if (next_needs_fmgr_hook &&
192
190
(* next_needs_fmgr_hook ) (functionId ))
@@ -198,32 +196,24 @@ sepgsql_needs_fmgr_hook(Oid functionId)
198
196
* functions as trusted-procedure, if the security policy has a rule that
199
197
* switches security label of the client on execution.
200
198
*/
201
- old_label = sepgsql_get_client_label ();
202
- new_label = sepgsql_proc_get_domtrans (functionId );
203
- if (strcmp (old_label , new_label ) != 0 )
204
- {
205
- pfree (new_label );
199
+ if (sepgsql_avc_trusted_proc (functionId ) != NULL )
206
200
return true;
207
- }
208
- pfree (new_label );
209
201
210
202
/*
211
203
* Even if not a trusted-procedure, this function should not be inlined
212
204
* unless the client has db_procedure:{execute} permission. Please note
213
205
* that it shall be actually failed later because of same reason with
214
206
* ACL_EXECUTE.
215
207
*/
216
- function_label = sepgsql_get_label (ProcedureRelationId , functionId , 0 );
217
- if (sepgsql_check_perms (sepgsql_get_client_label (),
218
- function_label ,
219
- SEPG_CLASS_DB_PROCEDURE ,
220
- SEPG_DB_PROCEDURE__EXECUTE ,
221
- NULL , false) != true)
222
- {
223
- pfree (function_label );
208
+ object .classId = ProcedureRelationId ;
209
+ object .objectId = functionId ;
210
+ object .objectSubId = 0 ;
211
+ if (!sepgsql_avc_check_perms (& object ,
212
+ SEPG_CLASS_DB_PROCEDURE ,
213
+ SEPG_DB_PROCEDURE__EXECUTE ,
214
+ SEPGSQL_AVC_NOAUDIT , false))
224
215
return true;
225
- }
226
- pfree (function_label );
216
+
227
217
return false;
228
218
}
229
219
@@ -251,33 +241,31 @@ sepgsql_fmgr_hook(FmgrHookEventType event,
251
241
if (!stack )
252
242
{
253
243
MemoryContext oldcxt ;
254
- const char * cur_label = sepgsql_get_client_label ();
255
244
256
245
oldcxt = MemoryContextSwitchTo (flinfo -> fn_mcxt );
257
246
stack = palloc (sizeof (* stack ));
258
247
stack -> old_label = NULL ;
259
- stack -> new_label = sepgsql_proc_get_domtrans (flinfo -> fn_oid );
248
+ stack -> new_label = sepgsql_avc_trusted_proc (flinfo -> fn_oid );
260
249
stack -> next_private = 0 ;
261
250
262
251
MemoryContextSwitchTo (oldcxt );
263
252
264
- if (strcmp (cur_label , stack -> new_label ) != 0 )
265
- {
266
- /*
267
- * process:transition permission between old and new
268
- * label, when user tries to switch security label of the
269
- * client on execution of trusted procedure.
270
- */
271
- sepgsql_check_perms (cur_label , stack -> new_label ,
272
- SEPG_CLASS_PROCESS ,
273
- SEPG_PROCESS__TRANSITION ,
274
- NULL , true);
275
- }
253
+ /*
254
+ * process:transition permission between old and new label,
255
+ * when user tries to switch security label of the client
256
+ * on execution of trusted procedure.
257
+ */
258
+ if (stack -> new_label )
259
+ sepgsql_avc_check_perms_label (stack -> new_label ,
260
+ SEPG_CLASS_PROCESS ,
261
+ SEPG_PROCESS__TRANSITION ,
262
+ NULL , true);
276
263
277
264
* private = PointerGetDatum (stack );
278
265
}
279
266
Assert (!stack -> old_label );
280
- stack -> old_label = sepgsql_set_client_label (stack -> new_label );
267
+ if (stack -> new_label )
268
+ stack -> old_label = sepgsql_set_client_label (stack -> new_label );
281
269
282
270
if (next_fmgr_hook )
283
271
(* next_fmgr_hook ) (event , flinfo , & stack -> next_private );
@@ -290,7 +278,8 @@ sepgsql_fmgr_hook(FmgrHookEventType event,
290
278
if (next_fmgr_hook )
291
279
(* next_fmgr_hook ) (event , flinfo , & stack -> next_private );
292
280
293
- sepgsql_set_client_label (stack -> old_label );
281
+ if (stack -> old_label )
282
+ sepgsql_set_client_label (stack -> old_label );
294
283
stack -> old_label = NULL ;
295
284
break ;
296
285
@@ -433,6 +422,9 @@ _PG_init(void)
433
422
errmsg ("SELinux: failed to get server security label: %m" )));
434
423
sepgsql_set_client_label (context );
435
424
425
+ /* Initialize userspace access vector cache */
426
+ sepgsql_avc_init ();
427
+
436
428
/* Security label provider hook */
437
429
register_label_provider (SEPGSQL_LABEL_TAG ,
438
430
sepgsql_object_relabel );
0 commit comments