]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selinux: rename comparison functions for clarity
authorChristian Göttsche <cgzones@googlemail.com>
Mon, 16 Dec 2024 16:40:04 +0000 (17:40 +0100)
committerPaul Moore <paul@paul-moore.com>
Wed, 8 Jan 2025 04:14:39 +0000 (23:14 -0500)
The functions context_cmp(), mls_context_cmp() and ebitmap_cmp() are not
traditional C style compare functions returning -1, 0, and 1 for less
than, equal, and greater than; they only return whether their arguments
are equal.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/context.c
security/selinux/ss/context.h
security/selinux/ss/ebitmap.c
security/selinux/ss/ebitmap.h
security/selinux/ss/mls_types.h
security/selinux/ss/services.c
security/selinux/ss/sidtab.c

index e39990f494dd54aac7accf76870af8ab380a88e3..a528b7f7628002d84cb42201a01c2274f885d66e 100644 (file)
@@ -20,7 +20,7 @@ u32 context_compute_hash(const struct context *c)
         * context struct with only the len & str set (and vice versa)
         * under a given policy. Since context structs from different
         * policies should never meet, it is safe to hash valid and
-        * invalid contexts differently. The context_cmp() function
+        * invalid contexts differently. The context_equal() function
         * already operates under the same assumption.
         */
        if (c->len)
index 7ccab2e6965f018430b1c25f425c73335f0e5fe2..dd3b9b5b588eac41f2644eef2485aeb3378ecb78 100644 (file)
@@ -132,13 +132,13 @@ out:
        return rc;
 }
 
-static inline int mls_context_cmp(const struct context *c1,
-                                 const struct context *c2)
+static inline bool mls_context_equal(const struct context *c1,
+                                    const struct context *c2)
 {
        return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
-               ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
+               ebitmap_equal(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
                (c1->range.level[1].sens == c2->range.level[1].sens) &&
-               ebitmap_cmp(&c1->range.level[1].cat, &c2->range.level[1].cat));
+               ebitmap_equal(&c1->range.level[1].cat, &c2->range.level[1].cat));
 }
 
 static inline void mls_context_destroy(struct context *c)
@@ -188,15 +188,15 @@ static inline void context_destroy(struct context *c)
        mls_context_destroy(c);
 }
 
-static inline int context_cmp(const struct context *c1,
-                             const struct context *c2)
+static inline bool context_equal(const struct context *c1,
+                                const struct context *c2)
 {
        if (c1->len && c2->len)
                return (c1->len == c2->len && !strcmp(c1->str, c2->str));
        if (c1->len || c2->len)
                return 0;
        return ((c1->user == c2->user) && (c1->role == c2->role) &&
-               (c1->type == c2->type) && mls_context_cmp(c1, c2));
+               (c1->type == c2->type) && mls_context_equal(c1, c2));
 }
 
 u32 context_compute_hash(const struct context *c);
index 99c01be15115aa024a119dc9dbcc743d6da7da84..1cc1e7e711e31e5092685fcf20e9f72a5daac681 100644 (file)
 
 static struct kmem_cache *ebitmap_node_cachep __ro_after_init;
 
-int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
+bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2)
 {
        const struct ebitmap_node *n1, *n2;
 
        if (e1->highbit != e2->highbit)
-               return 0;
+               return false;
 
        n1 = e1->node;
        n2 = e2->node;
@@ -41,9 +41,9 @@ int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
        }
 
        if (n1 || n2)
-               return 0;
+               return false;
 
-       return 1;
+       return true;
 }
 
 int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)
index ba2ac3da115396bde165517b9baa77d67624c492..49eb33de87e0a5bdb575b651489c3ba734dd9547 100644 (file)
@@ -120,7 +120,7 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, u32 bit)
             (bit) < ebitmap_length(e);               \
             (bit) = ebitmap_next_positive(e, &(n), bit))
 
-int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2);
+bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2);
 int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src);
 int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
                const struct ebitmap *e2);
index 7ef6e8cb0cf41f217941c372b30e79ff8b793aff..51df2ebd12115ebd19e261ed9fab83c26cae812a 100644 (file)
@@ -29,7 +29,7 @@ struct mls_range {
 static inline int mls_level_eq(const struct mls_level *l1,
                               const struct mls_level *l2)
 {
-       return ((l1->sens == l2->sens) && ebitmap_cmp(&l1->cat, &l2->cat));
+       return ((l1->sens == l2->sens) && ebitmap_equal(&l1->cat, &l2->cat));
 }
 
 static inline int mls_level_dom(const struct mls_level *l1,
index 9bd14256a1544da4f3f648a701bd7768654b69d9..e5c9b62e59c174d1c07eec6f44dfeff86701e2c1 100644 (file)
@@ -3331,7 +3331,7 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
                       __func__, xfrm_sid);
                goto out;
        }
-       rc = (mls_context_cmp(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
+       rc = (mls_context_equal(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
        if (rc)
                goto out;
 
index cb7125cc7f8ed8a28c1a2402f2e48a2f1962b6e9..59f8c09158ef5d910ba1f89c2997c3c49c1915a2 100644 (file)
@@ -66,7 +66,7 @@ static u32 context_to_sid(struct sidtab *s, struct context *context, u32 hash)
        hash_for_each_possible_rcu(s->context_to_sid, entry, list, hash) {
                if (entry->hash != hash)
                        continue;
-               if (context_cmp(&entry->context, context)) {
+               if (context_equal(&entry->context, context)) {
                        sid = entry->sid;
                        break;
                }