Linux-audit Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: selinux@vger.kernel.org, Paul Moore <paul@paul-moore.com>
Cc: linux-audit@redhat.com, Stephen Smalley <sds@tycho.nsa.gov>
Subject: [PATCH v3 2/4] selinux: replace some BUG_ON()s with a WARN_ON()
Date: Fri, 25 Jan 2019 11:06:49 +0100	[thread overview]
Message-ID: <20190125100651.21753-3-omosnace@redhat.com> (raw)
In-Reply-To: <20190125100651.21753-1-omosnace@redhat.com>

We don't need to crash the machine in these cases. Let's just detect the
buggy state early and error out with a warning.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 security/selinux/avc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 502162eeb3a0..5ebad47391c9 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -678,7 +678,6 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
 		return;
 	}
 
-	BUG_ON(!sad->tclass || sad->tclass >= ARRAY_SIZE(secclass_map));
 	perms = secclass_map[sad->tclass-1].perms;
 
 	audit_log_string(ab, " {");
@@ -731,7 +730,6 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
 		kfree(scontext);
 	}
 
-	BUG_ON(!sad->tclass || sad->tclass >= ARRAY_SIZE(secclass_map));
 	audit_log_format(ab, " tclass=%s", secclass_map[sad->tclass-1].name);
 
 	if (sad->denied)
@@ -748,6 +746,9 @@ noinline int slow_avc_audit(struct selinux_state *state,
 	struct common_audit_data stack_data;
 	struct selinux_audit_data sad;
 
+	if (WARN_ON(!tclass || tclass >= ARRAY_SIZE(secclass_map)))
+		return -EINVAL;
+
 	if (!a) {
 		a = &stack_data;
 		a->type = LSM_AUDIT_DATA_NONE;
-- 
2.20.1

  parent reply	other threads:[~2019-01-25 10:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-25 10:06 [PATCH v3 0/4] Report raw context in AVCs + refactoring Ondrej Mosnacek
2019-01-25 10:06 ` [PATCH v3 1/4] selinux: inline some AVC functions used only once Ondrej Mosnacek
2019-01-25 14:49   ` Stephen Smalley
2019-01-25 22:11   ` Paul Moore
2019-01-25 10:06 ` Ondrej Mosnacek [this message]
2019-01-25 14:52   ` [PATCH v3 2/4] selinux: replace some BUG_ON()s with a WARN_ON() Stephen Smalley
2019-01-25 22:26   ` Paul Moore
2019-01-25 10:06 ` [PATCH v3 3/4] selinux: remove some useless BUG_ONs Ondrej Mosnacek
2019-01-25 13:52   ` Stephen Smalley
2019-01-25 15:55     ` Ondrej Mosnacek
2019-01-25 22:36       ` Paul Moore
2019-01-25 10:06 ` [PATCH v3 4/4] selinux: log invalid contexts in AVCs Ondrej Mosnacek
2019-01-25 14:56   ` Stephen Smalley
2019-01-25 22:35   ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190125100651.21753-3-omosnace@redhat.com \
    --to=omosnace@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox