mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Cc: Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	Eric Paris <eparis@parisplace.org>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	"GONG, Ruiqi" <gongruiqi1@huawei.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 4/7] selinux: make left shifts well defined
Date: Mon,  7 Aug 2023 19:11:38 +0200	[thread overview]
Message-ID: <20230807171143.208481-3-cgzones@googlemail.com> (raw)
In-Reply-To: <20230807171143.208481-1-cgzones@googlemail.com>

The loops upper bound represent the number of permissions used (for the
current class or in general).  The limit for this is 32, thus we might
left shift of one less, 31.  Shifting a base of 1 results in undefined
behavior; use (u32)1 as base.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
v3: split from parent commit and apply cast to correct shift operand
---
 security/selinux/ss/services.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index dacec2ebdcd7..1eeffc66ea7d 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -207,22 +207,22 @@ static void map_decision(struct selinux_map *map,
 
 		for (i = 0, result = 0; i < n; i++) {
 			if (avd->allowed & mapping->perms[i])
-				result |= 1<<i;
+				result |= (u32)1<<i;
 			if (allow_unknown && !mapping->perms[i])
-				result |= 1<<i;
+				result |= (u32)1<<i;
 		}
 		avd->allowed = result;
 
 		for (i = 0, result = 0; i < n; i++)
 			if (avd->auditallow & mapping->perms[i])
-				result |= 1<<i;
+				result |= (u32)1<<i;
 		avd->auditallow = result;
 
 		for (i = 0, result = 0; i < n; i++) {
 			if (avd->auditdeny & mapping->perms[i])
-				result |= 1<<i;
+				result |= (u32)1<<i;
 			if (!allow_unknown && !mapping->perms[i])
-				result |= 1<<i;
+				result |= (u32)1<<i;
 		}
 		/*
 		 * In case the kernel has a bug and requests a permission
@@ -230,7 +230,7 @@ static void map_decision(struct selinux_map *map,
 		 * should audit that denial
 		 */
 		for (; i < (sizeof(u32)*8); i++)
-			result |= 1<<i;
+			result |= (u32)1<<i;
 		avd->auditdeny = result;
 	}
 }
-- 
2.40.1


  parent reply	other threads:[~2023-08-07 17:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 17:11 [PATCH v3 2/7] selinux: use u32 as bit type in ebitmap code Christian Göttsche
2023-08-07 17:11 ` [PATCH v3 3/7] selinux: update type for number of class permissions in services code Christian Göttsche
2023-08-09 23:07   ` Paul Moore
2023-08-07 17:11 ` Christian Göttsche [this message]
2023-08-09 23:07   ` [PATCH v3 4/7] selinux: make left shifts well defined Paul Moore
2023-08-07 17:11 ` [PATCH v3 5/7] selinux: avoid implicit conversions in selinuxfs code Christian Göttsche
2023-08-09 23:07   ` Paul Moore
2023-08-07 17:11 ` [PATCH v3 6/7] selinux: avoid implicit conversions in policydb code Christian Göttsche
2023-08-09 23:07   ` Paul Moore
2023-08-07 17:11 ` [PATCH v3 7/7] selinux: use unsigned iterator in nlmsgtab code Christian Göttsche
2023-08-09 23:07   ` Paul Moore
2023-08-07 17:11 ` [PATCH v3 1/7] selinux: avoid implicit conversions in avtab code Christian Göttsche
2023-08-09 23:07   ` Paul Moore
2023-08-09 23:07 ` [PATCH v3 2/7] selinux: use u32 as bit type in ebitmap code Paul Moore
2023-08-16 15:00   ` Christian Göttsche
2023-08-18 13:55     ` Christian Göttsche

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=20230807171143.208481-3-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=eparis@parisplace.org \
    --cc=gongruiqi1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /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

all inboxes | Powered by JetHome®