All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH] libsepol: reject invalid roles before inverting
Date: Mon, 17 Jan 2022 16:02:00 +0100	[thread overview]
Message-ID: <20220117150200.24953-1-cgzones@googlemail.com> (raw)

Since the role datums have not been validated yet, they might be invalid
and set to an enormous high value. Inverting such an ebitmap will take
excessive amount of memory and time.

Found by oss-fuzz (#43709)
---
 libsepol/src/expand.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c
index 898e6b87..3fc54af6 100644
--- a/libsepol/src/expand.c
+++ b/libsepol/src/expand.c
@@ -2481,6 +2481,10 @@ int role_set_expand(role_set_t * x, ebitmap_t * r, policydb_t * out, policydb_t
 
 	/* if role is to be complimented, invert the entire bitmap here */
 	if (x->flags & ROLE_COMP) {
+		/* inverting an ebitmap with an invalid highbit will take aeons */
+		if (ebitmap_length(r) > p->p_roles.nprim)
+			return -1;
+
 		for (i = 0; i < ebitmap_length(r); i++) {
 			if (ebitmap_get_bit(r, i)) {
 				if (ebitmap_set_bit(r, i, 0))
-- 
2.34.1


             reply	other threads:[~2022-01-17 15:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 15:02 Christian Göttsche [this message]
2022-01-19 19:17 ` [PATCH] libsepol: reject invalid roles before inverting James Carter
2022-01-20 16:15   ` Christian Göttsche
2022-01-20 17:37     ` James Carter

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=20220117150200.24953-1-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.