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>,
	Casey Schaufler <casey@schaufler-ca.com>,
	Xiu Jianfeng <xiujianfeng@huaweicloud.com>,
	"GONG, Ruiqi" <gongruiqi1@huawei.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 08/20] selinux: services: avoid implicit conversions
Date: Thu,  6 Jul 2023 15:23:23 +0200	[thread overview]
Message-ID: <20230706132337.15924-8-cgzones@googlemail.com> (raw)
In-Reply-To: <20230706132337.15924-1-cgzones@googlemail.com>

Use u32 as the output parameter type in security_get_classes() and
security_get_permissions(), based on the type of the symtab nprim
member.

Declare the read-only class string parameter of
security_get_permissions() const.

Avoid several implicit conversions by using the identical type for the
destination.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 security/selinux/include/security.h |  4 ++--
 security/selinux/selinuxfs.c        |  7 ++++---
 security/selinux/ss/services.c      | 22 +++++++++-------------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index 665c4e5bae99..0f93fd019bb4 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -312,9 +312,9 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
 				 u32 *peer_sid);
 
 int security_get_classes(struct selinux_policy *policy,
-			 char ***classes, int *nclasses);
+			 char ***classes, u32 *nclasses);
 int security_get_permissions(struct selinux_policy *policy,
-			     char *class, char ***perms, int *nperms);
+			     const char *class, char ***perms, u32 *nperms);
 int security_get_reject_unknown(void);
 int security_get_allow_unknown(void);
 
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index bad1f6b685fd..16036633ddd3 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1797,7 +1797,8 @@ static int sel_make_perm_files(struct selinux_policy *newpolicy,
 			char *objclass, int classvalue,
 			struct dentry *dir)
 {
-	int i, rc, nperms;
+	u32 i, nperms;
+	int rc;
 	char **perms;
 
 	rc = security_get_permissions(newpolicy, objclass, &perms, &nperms);
@@ -1867,8 +1868,8 @@ static int sel_make_classes(struct selinux_policy *newpolicy,
 			    struct dentry *class_dir,
 			    unsigned long *last_class_ino)
 {
-
-	int rc, nclasses, i;
+	u32 i, nclasses;
+	int rc;
 	char **classes;
 
 	rc = security_get_classes(newpolicy, &classes, &nclasses);
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 3275cfe2c8f7..2e2b17b00298 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -2822,7 +2822,6 @@ static inline int __security_genfs_sid(struct selinux_policy *policy,
 {
 	struct policydb *policydb = &policy->policydb;
 	struct sidtab *sidtab = policy->sidtab;
-	int len;
 	u16 sclass;
 	struct genfs *genfs;
 	struct ocontext *c;
@@ -2844,7 +2843,7 @@ static inline int __security_genfs_sid(struct selinux_policy *policy,
 		return -ENOENT;
 
 	for (c = genfs->head; c; c = c->next) {
-		len = strlen(c->u.name);
+		size_t len = strlen(c->u.name);
 		if ((!c->v.sclass || sclass == c->v.sclass) &&
 		    (strncmp(c->u.name, path, len) == 0))
 			break;
@@ -3332,7 +3331,7 @@ static int get_classes_callback(void *k, void *d, void *args)
 {
 	struct class_datum *datum = d;
 	char *name = k, **classes = args;
-	int value = datum->value - 1;
+	u32 value = datum->value - 1;
 
 	classes[value] = kstrdup(name, GFP_ATOMIC);
 	if (!classes[value])
@@ -3342,7 +3341,7 @@ static int get_classes_callback(void *k, void *d, void *args)
 }
 
 int security_get_classes(struct selinux_policy *policy,
-			 char ***classes, int *nclasses)
+			 char ***classes, u32 *nclasses)
 {
 	struct policydb *policydb;
 	int rc;
@@ -3358,8 +3357,7 @@ int security_get_classes(struct selinux_policy *policy,
 	rc = hashtab_map(&policydb->p_classes.table, get_classes_callback,
 			 *classes);
 	if (rc) {
-		int i;
-		for (i = 0; i < *nclasses; i++)
+		for (u32 i = 0; i < *nclasses; i++)
 			kfree((*classes)[i]);
 		kfree(*classes);
 	}
@@ -3372,7 +3370,7 @@ static int get_permissions_callback(void *k, void *d, void *args)
 {
 	struct perm_datum *datum = d;
 	char *name = k, **perms = args;
-	int value = datum->value - 1;
+	u32 value = datum->value - 1;
 
 	perms[value] = kstrdup(name, GFP_ATOMIC);
 	if (!perms[value])
@@ -3382,10 +3380,10 @@ static int get_permissions_callback(void *k, void *d, void *args)
 }
 
 int security_get_permissions(struct selinux_policy *policy,
-			     char *class, char ***perms, int *nperms)
+			     const char *class, char ***perms, u32 *nperms)
 {
 	struct policydb *policydb;
-	int rc, i;
+	int rc;
 	struct class_datum *match;
 
 	policydb = &policy->policydb;
@@ -3420,7 +3418,7 @@ int security_get_permissions(struct selinux_policy *policy,
 	return rc;
 
 err:
-	for (i = 0; i < *nperms; i++)
+	for (u32 i = 0; i < *nperms; i++)
 		kfree((*perms)[i]);
 	kfree(*perms);
 	return rc;
@@ -3600,9 +3598,7 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
 /* Check to see if the rule contains any selinux fields */
 int selinux_audit_rule_known(struct audit_krule *rule)
 {
-	int i;
-
-	for (i = 0; i < rule->field_count; i++) {
+	for (u32 i = 0; i < rule->field_count; i++) {
 		struct audit_field *f = &rule->fields[i];
 		switch (f->type) {
 		case AUDIT_SUBJ_USER:
-- 
2.40.1


  parent reply	other threads:[~2023-07-06 13:24 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
2023-07-18 22:01   ` [PATCH RFC 7/20] " Paul Moore
2023-07-19  1:45     ` Gong Ruiqi
2023-07-06 13:23 ` Christian Göttsche [this message]
2023-07-18 22:01   ` [PATCH RFC 8/20] selinux: services: avoid implicit conversions 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=20230706132337.15924-8-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=casey@schaufler-ca.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 \
    --cc=xiujianfeng@huaweicloud.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®