aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/xfrm.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux/xfrm.c')
-rw-r--r--security/selinux/xfrm.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c
index 8ab295154517..d03081886214 100644
--- a/security/selinux/xfrm.c
+++ b/security/selinux/xfrm.c
@@ -316,6 +316,7 @@ int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
316 316
317 memcpy(new_ctx, old_ctx, sizeof(*new_ctx)); 317 memcpy(new_ctx, old_ctx, sizeof(*new_ctx));
318 memcpy(new_ctx->ctx_str, old_ctx->ctx_str, new_ctx->ctx_len); 318 memcpy(new_ctx->ctx_str, old_ctx->ctx_str, new_ctx->ctx_len);
319 atomic_inc(&selinux_xfrm_refcount);
319 *new_ctxp = new_ctx; 320 *new_ctxp = new_ctx;
320 } 321 }
321 return 0; 322 return 0;
@@ -326,6 +327,7 @@ int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
326 */ 327 */
327void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx) 328void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
328{ 329{
330 atomic_dec(&selinux_xfrm_refcount);
329 kfree(ctx); 331 kfree(ctx);
330} 332}
331 333
@@ -335,17 +337,13 @@ void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
335int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) 337int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
336{ 338{
337 const struct task_security_struct *tsec = current_security(); 339 const struct task_security_struct *tsec = current_security();
338 int rc = 0;
339 340
340 if (ctx) { 341 if (!ctx)
341 rc = avc_has_perm(tsec->sid, ctx->ctx_sid, 342 return 0;
342 SECCLASS_ASSOCIATION,
343 ASSOCIATION__SETCONTEXT, NULL);
344 if (rc == 0)
345 atomic_dec(&selinux_xfrm_refcount);
346 }
347 343
348 return rc; 344 return avc_has_perm(tsec->sid, ctx->ctx_sid,
345 SECCLASS_ASSOCIATION, ASSOCIATION__SETCONTEXT,
346 NULL);
349} 347}
350 348
351/* 349/*
@@ -370,8 +368,8 @@ int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uct
370 */ 368 */
371void selinux_xfrm_state_free(struct xfrm_state *x) 369void selinux_xfrm_state_free(struct xfrm_state *x)
372{ 370{
373 struct xfrm_sec_ctx *ctx = x->security; 371 atomic_dec(&selinux_xfrm_refcount);
374 kfree(ctx); 372 kfree(x->security);
375} 373}
376 374
377 /* 375 /*
@@ -381,17 +379,13 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)
381{ 379{
382 const struct task_security_struct *tsec = current_security(); 380 const struct task_security_struct *tsec = current_security();
383 struct xfrm_sec_ctx *ctx = x->security; 381 struct xfrm_sec_ctx *ctx = x->security;
384 int rc = 0;
385 382
386 if (ctx) { 383 if (!ctx)
387 rc = avc_has_perm(tsec->sid, ctx->ctx_sid, 384 return 0;
388 SECCLASS_ASSOCIATION,
389 ASSOCIATION__SETCONTEXT, NULL);
390 if (rc == 0)
391 atomic_dec(&selinux_xfrm_refcount);
392 }
393 385
394 return rc; 386 return avc_has_perm(tsec->sid, ctx->ctx_sid,
387 SECCLASS_ASSOCIATION, ASSOCIATION__SETCONTEXT,
388 NULL);
395} 389}
396 390
397/* 391/*