diff options
author | Paul Moore <pmoore@redhat.com> | 2013-05-29 03:36:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-05-31 20:30:07 -0400 |
commit | e4e8536f65b51ce91c30588b0925872bdfc60d03 (patch) | |
tree | 729236474c6bfdc9fcfc19db57504b5b13936825 /security | |
parent | e4c1721642bbd42d8142f4811cde0588c28db51d (diff) |
selinux: fix the labeled xfrm/IPsec reference count handling
The SELinux labeled IPsec code was improperly handling its reference
counting, dropping a reference on a delete operation instead of on a
free/release operation.
Reported-by: Ondrej Moris <omoris@redhat.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'security')
-rw-r--r-- | security/selinux/xfrm.c | 34 |
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 | */ |
327 | void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx) | 328 | void 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) | |||
335 | int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx) | 337 | int 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 | */ |
371 | void selinux_xfrm_state_free(struct xfrm_state *x) | 369 | void 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 | /* |