diff mbox series

[RFC,11/20] selinux: avc: avoid implicit conversions

Message ID 20230706132337.15924-11-cgzones@googlemail.com (mailing list archive)
State Accepted
Delegated to: Paul Moore
Headers show
Series [RFC,01/20] selinux: check for multiplication overflow in put_entry() | expand

Commit Message

Christian Göttsche July 6, 2023, 1:23 p.m. UTC
Use a consistent type of u32 for sequence numbers.

Use a non-negative and input parameter matching type for the hash
result.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 security/selinux/avc.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Paul Moore July 18, 2023, 10:01 p.m. UTC | #1
On Jul  6, 2023 =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com> wrote:
> 
> Use a consistent type of u32 for sequence numbers.
> 
> Use a non-negative and input parameter matching type for the hash
> result.
> 
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
>  security/selinux/avc.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)

...

> diff --git a/security/selinux/avc.c b/security/selinux/avc.c
> index 1074db66e5ff..cd55479cce25 100644
> --- a/security/selinux/avc.c
> +++ b/security/selinux/avc.c
> @@ -654,9 +654,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
>  {
>  	struct common_audit_data *ad = a;
>  	struct selinux_audit_data *sad = ad->selinux_audit_data;
> -	u32 av = sad->audited;
> +	u32 av = sad->audited, perm;
>  	const char *const *perms;
> -	int i, perm;
> +	u32 i;

Technically the perm type change doesn't fit with the description, but
it's minor enough that it shouldn't be an issue.

Merged into selinux/next.

>  	audit_log_format(ab, "avc:  %s ", sad->denied ? "denied" : "granted");
>  
> @@ -833,7 +833,8 @@ static int avc_update_node(u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
>  			   struct extended_perms_decision *xpd,
>  			   u32 flags)
>  {
> -	int hvalue, rc = 0;
> +	u32 hvalue;
> +	int rc = 0;
>  	unsigned long flag;
>  	struct avc_node *pos, *node, *orig = NULL;
>  	struct hlist_head *head;
> -- 
> 2.40.1

--
paul-moore.com
diff mbox series

Patch

diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 1074db66e5ff..cd55479cce25 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -122,7 +122,7 @@  static struct kmem_cache *avc_xperms_data_cachep __ro_after_init;
 static struct kmem_cache *avc_xperms_decision_cachep __ro_after_init;
 static struct kmem_cache *avc_xperms_cachep __ro_after_init;
 
-static inline int avc_hash(u32 ssid, u32 tsid, u16 tclass)
+static inline u32 avc_hash(u32 ssid, u32 tsid, u16 tclass)
 {
 	return (ssid ^ (tsid<<2) ^ (tclass<<4)) & (AVC_CACHE_SLOTS - 1);
 }
@@ -523,7 +523,7 @@  static void avc_node_populate(struct avc_node *node, u32 ssid, u32 tsid, u16 tcl
 static inline struct avc_node *avc_search_node(u32 ssid, u32 tsid, u16 tclass)
 {
 	struct avc_node *node, *ret = NULL;
-	int hvalue;
+	u32 hvalue;
 	struct hlist_head *head;
 
 	hvalue = avc_hash(ssid, tsid, tclass);
@@ -566,7 +566,7 @@  static struct avc_node *avc_lookup(u32 ssid, u32 tsid, u16 tclass)
 	return NULL;
 }
 
-static int avc_latest_notif_update(int seqno, int is_insert)
+static int avc_latest_notif_update(u32 seqno, int is_insert)
 {
 	int ret = 0;
 	static DEFINE_SPINLOCK(notif_lock);
@@ -609,7 +609,7 @@  static void avc_insert(u32 ssid, u32 tsid, u16 tclass,
 		       struct av_decision *avd, struct avc_xperms_node *xp_node)
 {
 	struct avc_node *pos, *node = NULL;
-	int hvalue;
+	u32 hvalue;
 	unsigned long flag;
 	spinlock_t *lock;
 	struct hlist_head *head;
@@ -654,9 +654,9 @@  static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
 {
 	struct common_audit_data *ad = a;
 	struct selinux_audit_data *sad = ad->selinux_audit_data;
-	u32 av = sad->audited;
+	u32 av = sad->audited, perm;
 	const char *const *perms;
-	int i, perm;
+	u32 i;
 
 	audit_log_format(ab, "avc:  %s ", sad->denied ? "denied" : "granted");
 
@@ -833,7 +833,8 @@  static int avc_update_node(u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
 			   struct extended_perms_decision *xpd,
 			   u32 flags)
 {
-	int hvalue, rc = 0;
+	u32 hvalue;
+	int rc = 0;
 	unsigned long flag;
 	struct avc_node *pos, *node, *orig = NULL;
 	struct hlist_head *head;