From: Gong Ruiqi <gongruiqi1@huawei.com>
To: "Christian Göttsche" <cgzones@googlemail.com>
Cc: Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Eric Paris <eparis@parisplace.org>,
Ondrej Mosnacek <omosnace@redhat.com>,
<linux-kernel@vger.kernel.org>, <selinux@vger.kernel.org>
Subject: Re: [RFC PATCH 07/20] selinux: services: update type for umber of class permissions
Date: Fri, 7 Jul 2023 10:27:44 +0800 [thread overview]
Message-ID: <b5628a5d-e496-822b-b3ac-4a15b228e7b5@huawei.com> (raw)
In-Reply-To: <20230706132337.15924-7-cgzones@googlemail.com>
Hi Christian,
First of all, there's a typo in the subject: umber -> number ;)
On 2023/07/06 21:23, Christian Göttsche wrote:
> Security classes have only up to 32 permissions, hence using an u16 is
> sufficient (while improving padding).
>
> Also use a fixed sized cast in a bit shift to work correctly on
> architectures where sizeof(unsigned int) != sizeof(u32).
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> security/selinux/ss/services.c | 6 +++---
> security/selinux/ss/services.h | 2 +-
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index 78946b71c1c1..3275cfe2c8f7 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -97,7 +97,6 @@ static int selinux_set_mapping(struct policydb *pol,
> struct selinux_map *out_map)
> {
> u16 i, j;
> - unsigned k;
> bool print_unknown_handle = false;
>
> /* Find number of classes in the input mapping */
> @@ -117,6 +116,7 @@ static int selinux_set_mapping(struct policydb *pol,
> while (map[j].name) {
> const struct security_class_mapping *p_in = map + (j++);
> struct selinux_mapping *p_out = out_map->mapping + j;
> + u16 k;
>
> /* An empty class string skips ahead */
> if (!strcmp(p_in->name, "")) {
> @@ -202,7 +202,7 @@ static void map_decision(struct selinux_map *map,
> {
> if (tclass < map->size) {
> struct selinux_mapping *mapping = &map->mapping[tclass];
> - unsigned int i, n = mapping->num_perms;
> + u16 i, n = mapping->num_perms;
> u32 result;
>
> for (i = 0, result = 0; i < n; i++) {
> @@ -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 |= 1<<((u32)i);
Is it really necessary to do explicit conversion here? Its value is
known to be small, and IIUC, u16 will be implicitly promoted to int as
an operand of <<, as described here:
https://en.cppreference.com/w/c/language/conversion#Integer_promotions
> avd->auditdeny = result;
> }
> }
> diff --git a/security/selinux/ss/services.h b/security/selinux/ss/services.h
> index 8a9b85f44b66..b6f99353301e 100644
> --- a/security/selinux/ss/services.h
> +++ b/security/selinux/ss/services.h
> @@ -12,7 +12,7 @@
> /* Mapping for a single class */
> struct selinux_mapping {
> u16 value; /* policy value for class */
> - unsigned int num_perms; /* number of permissions in class */
> + u16 num_perms; /* number of permissions in class */
> u32 perms[sizeof(u32) * 8]; /* policy values for permissions */
> };
>
next prev parent reply other threads:[~2023-07-07 2:28 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-06 13:23 [RFC PATCH 01/20] selinux: check for multiplication overflow in put_entry() Christian Göttsche
2023-07-06 13:23 ` [RFC PATCH 02/20] selinux: avtab: avoid implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 2/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 03/20] selinux: avoid avtab overflows Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 3/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 04/20] selinux: ebitmap: use u32 as bit type Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 4/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 05/20] selinux: hashtab: use identical iterator type Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 5/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 06/20] selinux: mls: avoid implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 6/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 07/20] selinux: services: update type for umber of class permissions Christian Göttsche
2023-07-07 2:27 ` Gong Ruiqi [this message]
2023-07-18 22:01 ` [PATCH RFC 7/20] " Paul Moore
2023-07-19 1:45 ` Gong Ruiqi
2023-07-06 13:23 ` [RFC PATCH 08/20] selinux: services: avoid implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 8/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 09/20] selinux: status: consistently use u32 as sequence number type Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC 9/20] " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 10/20] selinux: netif: avoid implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 11/20] selinux: avc: " Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 12/20] selinux: hooks: " Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 13/20] selinux: selinuxfs: " Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 14/20] selinux: use consistent type for AV rule specifier Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 15/20] selinux: policydb: implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 16/20] selinux: symtab: implicit conversion Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 17/20] selinux: services: implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 18/20] selinux: nlmsgtab: implicit conversion Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 19/20] selinux: status: avoid implicit conversions regarding enforcing status Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-06 13:23 ` [RFC PATCH 20/20] selinux: selinuxfs: avoid implicit conversions Christian Göttsche
2023-07-18 22:01 ` [PATCH RFC " Paul Moore
2023-07-18 22:01 ` [PATCH RFC 1/20] selinux: check for multiplication overflow in put_entry() 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=b5628a5d-e496-822b-b3ac-4a15b228e7b5@huawei.com \
--to=gongruiqi1@huawei.com \
--cc=cgzones@googlemail.com \
--cc=eparis@parisplace.org \
--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®