mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gong Ruiqi <gongruiqi1@huawei.com>
To: "Christian Göttsche" <cgzones@googlemail.com>, 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>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 6/9] selinux: avoid implicit conversions in services code
Date: Mon, 31 Jul 2023 10:01:59 +0800	[thread overview]
Message-ID: <f899f0af-6aea-7cd6-cd44-a2082cb267cb@huawei.com> (raw)
In-Reply-To: <20230728155501.39632-5-cgzones@googlemail.com>



On 2023/07/28 23:54, Christian Göttsche wrote:
> 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.
> 
> Use the type identical to the source for local variables.
> 
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Reviewed-by: GONG, Ruiqi <gongruiqi1@huawei.com>

> ---
> v2: avoid declarations in init-clauses of for loops
> ---
>  security/selinux/include/security.h |  4 ++--
>  security/selinux/selinuxfs.c        |  7 ++++---
>  security/selinux/ss/services.c      | 23 ++++++++++++-----------
>  3 files changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
> index 668e393a9709..074d439fe9ad 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 f79e96f0f221..b969e87fd870 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c
> @@ -1798,7 +1798,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);
> @@ -1868,8 +1869,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 cf4b87ec4a0e..3a03243f52e7 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -856,7 +856,7 @@ int security_bounded_transition(u32 old_sid, u32 new_sid)
>  	struct sidtab *sidtab;
>  	struct sidtab_entry *old_entry, *new_entry;
>  	struct type_datum *type;
> -	int index;
> +	u32 index;
>  	int rc;
>  
>  	if (!selinux_initialized())
> @@ -1511,7 +1511,7 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
>  		return -ENOMEM;
>  
>  	if (!selinux_initialized()) {
> -		int i;
> +		u32 i;
>  
>  		for (i = 1; i < SECINITSID_NUM; i++) {
>  			const char *s = initial_sid_to_string[i];
> @@ -2821,7 +2821,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;
> @@ -2843,7 +2842,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;
> @@ -3331,7 +3330,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])
> @@ -3341,7 +3340,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;
> @@ -3357,7 +3356,8 @@ int security_get_classes(struct selinux_policy *policy,
>  	rc = hashtab_map(&policydb->p_classes.table, get_classes_callback,
>  			 *classes);
>  	if (rc) {
> -		int i;
> +		u32 i;
> +
>  		for (i = 0; i < *nclasses; i++)
>  			kfree((*classes)[i]);
>  		kfree(*classes);
> @@ -3371,7 +3371,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])
> @@ -3381,10 +3381,11 @@ 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;
> +	u32 i;
> +	int rc;
>  	struct class_datum *match;
>  
>  	policydb = &policy->policydb;
> @@ -3599,7 +3600,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;
> +	u32 i;
>  
>  	for (i = 0; i < rule->field_count; i++) {
>  		struct audit_field *f = &rule->fields[i];

  reply	other threads:[~2023-07-31  2:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28 15:54 [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code Christian Göttsche
2023-07-28 15:54 ` [PATCH v2 3/9] selinux: use identical iterator type in hashtab_duplicate() Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 4/9] selinux: avoid implicit conversions in mls code Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 5/9] selinux: services: update type for number of class permissions Christian Göttsche
2023-07-31  1:46   ` Gong Ruiqi
2023-08-04  2:20   ` Paul Moore
2023-08-04 15:21     ` David Laight
2023-07-28 15:54 ` [PATCH v2 6/9] selinux: avoid implicit conversions in services code Christian Göttsche
2023-07-31  2:01   ` Gong Ruiqi [this message]
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 7/9] selinux: avoid implicit conversions in selinuxfs code Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 8/9] selinux: policydb: implicit conversions Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 9/9] selinux: avoid implicit conversion in nlmsgtab code Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-07-28 15:55 ` [PATCH v2 1/9] selinux: avoid implicit conversions in avtab code Christian Göttsche
2023-08-04  2:20   ` Paul Moore
2023-08-04  2:20 ` [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code Paul Moore
2023-08-04 15:11   ` David Laight

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=f899f0af-6aea-7cd6-cd44-a2082cb267cb@huawei.com \
    --to=gongruiqi1@huawei.com \
    --cc=casey@schaufler-ca.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 \
    --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®