selinux: enclose macro arguments in parenthesis
authorChristian Göttsche <cgzones@googlemail.com>
Tue, 25 Jan 2022 14:14:14 +0000 (15:14 +0100)
committerPaul Moore <paul@paul-moore.com>
Wed, 26 Jan 2022 20:13:58 +0000 (15:13 -0500)
Enclose the macro arguments in parenthesis to avoid potential evaluation
order issues.

Note the xperm and ebitmap macros are still not side-effect safe due to
double evaluation.

Reported by clang-tidy [bugprone-macro-parentheses]

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/include/security.h
security/selinux/ss/ebitmap.h
security/selinux/ss/sidtab.c

index 6482e0efb3689c68401021a392ad7686a29cc510..d91a5672de99114ee05d57fcd6d0c07fe80864a4 100644 (file)
@@ -254,8 +254,8 @@ struct av_decision {
 #define XPERMS_AUDITALLOW 2
 #define XPERMS_DONTAUDIT 4
 
-#define security_xperm_set(perms, x) (perms[x >> 5] |= 1 << (x & 0x1f))
-#define security_xperm_test(perms, x) (1 & (perms[x >> 5] >> (x & 0x1f)))
+#define security_xperm_set(perms, x) ((perms)[(x) >> 5] |= 1 << ((x) & 0x1f))
+#define security_xperm_test(perms, x) (1 & ((perms)[(x) >> 5] >> ((x) & 0x1f)))
 struct extended_perms_data {
        u32 p[8];
 };
index 9eb2d0af2805e2054bfa94f2646a192e5f54aacf..58eb822f11eefa6ac00cb8d0558d9aa8a772dce0 100644 (file)
@@ -118,9 +118,9 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n,
 }
 
 #define ebitmap_for_each_positive_bit(e, n, bit)       \
-       for (bit = ebitmap_start_positive(e, &n);       \
-            bit < ebitmap_length(e);                   \
-            bit = ebitmap_next_positive(e, &n, bit))   \
+       for ((bit) = ebitmap_start_positive(e, &(n));   \
+            (bit) < ebitmap_length(e);                 \
+            (bit) = ebitmap_next_positive(e, &(n), bit))       \
 
 int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2);
 int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src);
index 293ec048af08c60f55c1a78f7e22faec2acd1290..a54b8652bfb50d4ae2f0fc1f40eb871c1f945c04 100644 (file)
@@ -27,8 +27,8 @@ struct sidtab_str_cache {
        char str[];
 };
 
-#define index_to_sid(index) (index + SECINITSID_NUM + 1)
-#define sid_to_index(sid) (sid - (SECINITSID_NUM + 1))
+#define index_to_sid(index) ((index) + SECINITSID_NUM + 1)
+#define sid_to_index(sid) ((sid) - (SECINITSID_NUM + 1))
 
 int sidtab_init(struct sidtab *s)
 {