Skip to contentSkip to conversation

xsm/flask: code style formatting

PATCH In review Daniel P. Smith 4 participants 5 messages Apr 22, 2022 – Apr 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xsm/flask: code style formatting

This is a quick code style cleanup patch for xsm/flask. The files flask_op.c and hooks.c are Xen specific, thus full code style rules were applied. The remaining files are from Linux and therefore only trailing whitespace was remove from those files.

---
 xen/xsm/flask/avc.c            |  14 +--
 xen/xsm/flask/flask_op.c       |  27 ++---
 xen/xsm/flask/hooks.c          | 186 +++++++++++++++++----------------
 xen/xsm/flask/include/avc.h    |   2 +-
 xen/xsm/flask/ss/avtab.c       |  10 +-
 xen/xsm/flask/ss/avtab.h       |   4 +-
 xen/xsm/flask/ss/conditional.c |   4 +-
 xen/xsm/flask/ss/context.h     |   4 +-
 xen/xsm/flask/ss/mls.c         |   2 +-
 xen/xsm/flask/ss/policydb.c    |   2 +-
 xen/xsm/flask/ss/services.c    |   6 +-
 xen/xsm/flask/ss/sidtab.c      |   6 +-
 12 files changed, 136 insertions(+), 131 deletions(-)
xen/xsm/flask/avc.c +7 -7
index e20c165042..4a75ec97e2 100644
@@ -13,9 +13,9 @@
  *    it under the terms of the GNU General Public License version 2,
  *      as published by the Free Software Foundation.
  */
- 
+
 /* Ported to Xen 3.0, George Coker, <[email protected]> */
- 
+
 #include <xen/lib.h>
 #include <xen/xmalloc.h>
 #include <xen/types.h>
@@ -267,7 +267,7 @@ int avc_get_hash_stats(struct xen_flask_hash_stats *arg)
     }
 
     rcu_read_unlock(&avc_rcu_lock);
-    
+
     arg->entries = atomic_read(&avc_cache.active_nodes);
     arg->buckets_used = slots_used;
     arg->buckets_total = AVC_CACHE_SLOTS;
@@ -336,7 +336,7 @@ static inline int avc_reclaim_node(void)
         }
         rcu_read_unlock(&avc_rcu_lock);
         spin_unlock_irqrestore(lock, flags);
-    }    
+    }
  out:
     return ecx;
 }
@@ -622,7 +622,7 @@ static int avc_update_node(u32 perms, u32 ssid, u32 tsid, u16 tclass,
     struct hlist_head *head;
     struct hlist_node *next;
     spinlock_t *lock;
-    
+
     node = avc_alloc_node();
     if ( !node )
     {
@@ -630,7 +630,7 @@ static int avc_update_node(u32 perms, u32 ssid, u32 tsid, u16 tclass,
         goto out;
     }
 
-    hvalue = avc_hash(ssid, tsid, tclass);    
+    hvalue = avc_hash(ssid, tsid, tclass);
 
     head = &avc_cache.slots[hvalue];
     lock = &avc_cache.slots_lock[hvalue];
@@ -695,7 +695,7 @@ int avc_ss_reset(u32 seqno)
         rcu_read_unlock(&avc_rcu_lock);
         spin_unlock_irqrestore(lock, flag);
     }
-    
+
     avc_latest_notif_update(seqno, 0);
     return rc;
 }
xen/xsm/flask/flask_op.c +14 -13
index 707be72a3b..eb16e289c3 100644
@@ -75,15 +75,15 @@ static int __init cf_check parse_flask_param(const char *s)
 }
 custom_param("flask", parse_flask_param);
 
-static int domain_has_security(struct domain *d, u32 perms)
+static int domain_has_security(struct domain *d, uint32_t perms)
 {
     struct domain_security_struct *dsec;
-    
+
     dsec = d->ssid;
     if ( !dsec )
         return -EACCES;
-        
-    return avc_has_perm(dsec->sid, SECINITSID_SECURITY, SECCLASS_SECURITY, 
+
+    return avc_has_perm(dsec->sid, SECINITSID_SECURITY, SECCLASS_SECURITY,
                         perms, NULL);
 }
 
@@ -130,7 +130,7 @@ static int flask_security_access(struct xen_flask_access *arg)
     arg->audit_allow = avd.auditallow;
     arg->audit_deny = avd.auditdeny;
     arg->seqno = avd.seqno;
-                
+
     return rv;
 }
 
@@ -196,7 +196,7 @@ static int flask_security_sid(struct xen_flask_sid_context *arg)
 {
     int rv;
     char *context;
-    u32 len;
+    uint32_t len;
 
     rv = domain_has_security(current->domain, SECURITY__CHECK_CONTEXT);
     if ( rv )
@@ -223,7 +223,8 @@ static int flask_security_sid(struct xen_flask_sid_context *arg)
 
 #ifndef COMPAT
 
-static int flask_security_setavc_threshold(struct xen_flask_setavc_threshold *arg)
+static int flask_security_setavc_threshold(
+    struct xen_flask_setavc_threshold *arg)
 {
     int rv = 0;
 
@@ -350,7 +351,7 @@ static int flask_security_get_bool(struct xen_flask_boolean *arg)
         if ( nameout_len > arg->size )
             rv = -ERANGE;
         arg->size = nameout_len;
- 
+
         if ( !rv && _copy_to_guest(arg->name, nameout, nameout_len) )
             rv = -EFAULT;
         xfree(nameout);
@@ -386,9 +387,9 @@ static int flask_security_make_bools(void)
     int ret = 0;
     int num;
     int *values = NULL;
-    
+
     xfree(bool_pending_values);
-    
+
     ret = security_get_bools(&num, NULL, &values, NULL);
     if ( ret != 0 )
         goto out;
@@ -474,8 +475,8 @@ static int flask_devicetree_label(struct xen_flask_devicetree_label *arg)
 {
     int rv;
     char *buf;
-    u32 sid = arg->sid;
-    u32 perm = sid ? SECURITY__ADD_OCONTEXT : SECURITY__DEL_OCONTEXT;
+    uint32_t sid = arg->sid;
+    uint32_t perm = sid ? SECURITY__ADD_OCONTEXT : SECURITY__DEL_OCONTEXT;
 
     rv = domain_has_security(current->domain, perm);
     if ( rv )
@@ -670,7 +671,7 @@ ret_t cf_check do_flask_op(XEN_GUEST_HANDLE_PARAM(void) u_flask_op)
 
     case FLASK_MLS:
         rv = flask_mls_enabled;
-        break;    
+        break;
 
     case FLASK_GETAVC_THRESHOLD:
         rv = avc_cache_threshold;
xen/xsm/flask/hooks.c +95 -91

530 lines not on this page · raw message

xen/xsm/flask/include/avc.h +1 -1
index c14bd07a2b..e29949f5a8 100644
@@ -3,7 +3,7 @@
  *
  * Author : Stephen Smalley, <[email protected]>
  */
- 
+
 /* Ported to Xen 3.0, George Coker, <[email protected]> */
 
 #ifndef _FLASK_AVC_H_
xen/xsm/flask/ss/avtab.c +5 -5
index 55c2b4d8a4..017f5183de 100644
@@ -35,7 +35,7 @@ static inline int avtab_hash(struct avtab_key *keyp, u16 mask)
 }
 
 static struct avtab_node* avtab_insert_node(struct avtab *h, int hvalue,
-    struct avtab_node * prev, struct avtab_node * cur, struct avtab_key *key, 
+    struct avtab_node * prev, struct avtab_node * cur, struct avtab_key *key,
                                                     struct avtab_datum *datum)
 {
     struct avtab_node *newnode = xzalloc(struct avtab_node);
@@ -59,7 +59,7 @@ static struct avtab_node* avtab_insert_node(struct avtab *h, int hvalue,
     return newnode;
 }
 
-static int avtab_insert(struct avtab *h, struct avtab_key *key, 
+static int avtab_insert(struct avtab *h, struct avtab_key *key,
                                                     struct avtab_datum *datum)
 {
     int hvalue;
@@ -100,7 +100,7 @@ static int avtab_insert(struct avtab *h, struct avtab_key *key,
  * key/specified mask into the table, as needed by the conditional avtab.
  * It also returns a pointer to the node inserted.
  */
-struct avtab_node * avtab_insert_nonunique(struct avtab * h, 
+struct avtab_node * avtab_insert_nonunique(struct avtab * h,
                             struct avtab_key * key, struct avtab_datum * datum)
 {
     int hvalue;
@@ -110,7 +110,7 @@ struct avtab_node * avtab_insert_nonunique(struct avtab * h,
     if ( !h || !h->htable )
         return NULL;
     hvalue = avtab_hash(key, h->mask);
-    for ( prev = NULL, cur = h->htable[hvalue]; cur; 
+    for ( prev = NULL, cur = h->htable[hvalue]; cur;
                                                 prev = cur, cur = cur->next )
     {
         if ( key->source_type == cur->key.source_type &&
@@ -199,7 +199,7 @@ struct avtab_node* avtab_search_node(struct avtab *h, struct avtab_key *key)
     return NULL;
 }
 
-struct avtab_node* avtab_search_node_next(struct avtab_node *node, 
+struct avtab_node* avtab_search_node_next(struct avtab_node *node,
                                                                 int specified)
 {
     struct avtab_node *cur;
xen/xsm/flask/ss/avtab.h +2 -2
index a2b50c222a..591604f927 100644
@@ -74,12 +74,12 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
 
 int avtab_read(struct avtab *a, void *fp, struct policydb *pol);
 
-struct avtab_node *avtab_insert_nonunique(struct avtab *h, 
+struct avtab_node *avtab_insert_nonunique(struct avtab *h,
                             struct avtab_key *key, struct avtab_datum *datum);
 
 struct avtab_node *avtab_search_node(struct avtab *h, struct avtab_key *key);
 
-struct avtab_node *avtab_search_node_next(struct avtab_node *node, 
+struct avtab_node *avtab_search_node_next(struct avtab_node *node,
                                                                 int specified);
 
 #define MAX_AVTAB_HASH_BITS 13
xen/xsm/flask/ss/conditional.c +2 -2
index b4b116666c..e74fc01746 100644
@@ -452,7 +452,7 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
             goto err;
         }
 
-        if ( i == 0 ) 
+        if ( i == 0 )
             node->expr = expr;
         else
             last->next = expr;
@@ -513,7 +513,7 @@ err:
 /* Determine whether additional permissions are granted by the conditional
  * av table, and if so, add them to the result
  */
-void cond_compute_av(struct avtab *ctab, struct avtab_key *key, 
+void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
                                                         struct av_decision *avd)
 {
     struct avtab_node *node;
xen/xsm/flask/ss/context.h +2 -2
index 302b3698a7..311edf8794 100644
@@ -12,9 +12,9 @@
  *
  * Author : Stephen Smalley, <[email protected]>
  */
- 
+
 /* Ported to Xen 3.0, George Coker, <[email protected]> */
- 
+
 #ifndef _SS_CONTEXT_H_
 #define _SS_CONTEXT_H_
 
xen/xsm/flask/ss/mls.c +1 -1
index f2fa560810..a3255ae01a 100644
@@ -70,7 +70,7 @@ int mls_compute_context_len(struct context * context)
         }
         if ( l == 0 )
         {
-            if ( mls_level_eq(&context->range.level[0], 
+            if ( mls_level_eq(&context->range.level[0],
                               &context->range.level[1]) )
                 break;
             else
xen/xsm/flask/ss/policydb.c +1 -1
index ff2103c63e..162470bbbd 100644
@@ -339,7 +339,7 @@ static int cf_check sens_index(void *key, void *datum, void *datap)
 
     if ( !levdatum->isalias )
     {
-        if ( !levdatum->level->sens || levdatum->level->sens > 
+        if ( !levdatum->level->sens || levdatum->level->sens >
                                                         p->p_levels.nprim )
             return -EINVAL;
         p->p_sens_val_to_name[levdatum->level->sens - 1] = key;
xen/xsm/flask/ss/services.c +3 -3
index 2f6d3d350d..dab07b5f60 100644
@@ -99,7 +99,7 @@ static int context_struct_compute_av(struct context *scontext,
  * constraint_expr_eval should pass in NULL for xcontext.
  */
 static int constraint_expr_eval(struct context *scontext,
-                            struct context *tcontext, struct context *xcontext, 
+                            struct context *tcontext, struct context *xcontext,
                                                 struct constraint_expr *cexpr)
 {
     u32 val1, val2;
@@ -1073,7 +1073,7 @@ static int security_compute_sid(u32 ssid,
                 /* Look for a role transition rule. */
                 for ( roletr = policydb.role_tr; roletr; roletr = roletr->next )
                 {
-                    if ( roletr->role == scontext->role && 
+                    if ( roletr->role == scontext->role &&
                                             roletr->type == tcontext->type )
                     {
                         /* Use the role transition rule. */
@@ -1485,7 +1485,7 @@ int security_irq_sid(int pirq, u32 *out_sid)
     POLICY_RDLOCK;
 
     c = policydb.ocontexts[OCON_PIRQ];
-    
+
     while ( c )
     {
         if ( c->u.pirq == pirq )
xen/xsm/flask/ss/sidtab.c +3 -3
index cd1360cb4a..74babfac9c 100644
@@ -3,9 +3,9 @@
  *
  * Author : Stephen Smalley, <[email protected]>
  */
- 
+
 /* Ported to Xen 3.0, George Coker, <[email protected]> */
- 
+
 #include <xen/lib.h>
 #include <xen/xmalloc.h>
 #include <xen/errno.h>
@@ -192,7 +192,7 @@ void sidtab_map_remove_on_error(struct sidtab *s,
     return;
 }
 
-static inline u32 sidtab_search_context(struct sidtab *s, 
+static inline u32 sidtab_search_context(struct sidtab *s,
                                                         struct context *context)
 {
     int i;
Signature · 1 line
2.20.1
#1 lore raw

xen/xsm/flask/hooks.c static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) · line 125

Quoted 12 lines · Daniel P. Smith
xen/xsm/flask/hooks.c +2 -2
index 0bf63ffa84..e2ebbc7716 100644
@@ -120,8 +121,8 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad)
         struct irq_desc *desc = irq_to_desc(irq);
         if ( desc->msi_desc && desc->msi_desc->dev ) {
             struct pci_dev *dev = desc->msi_desc->dev;
-            u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
-            if (ad) {
+            uint32_t sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
+            if ( ad ) {

Brace on newline, and in the subsequent hunk.  Can be fixed on commit.

Otherwise, LGTM.  Acked-by: Andrew Cooper <[email protected]>

Reviewed-by
#2 lore raw
Quoted 17 lines · Andrew Cooper

xen/xsm/flask/hooks.c static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) · line 125

Quoted 12 lines · Daniel P. Smith
xen/xsm/flask/hooks.c +2 -2
index 0bf63ffa84..e2ebbc7716 100644
@@ -120,8 +121,8 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad)
         struct irq_desc *desc = irq_to_desc(irq);
         if ( desc->msi_desc && desc->msi_desc->dev ) {
             struct pci_dev *dev = desc->msi_desc->dev;
-            u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
-            if (ad) {
+            uint32_t sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
+            if ( ad ) {

Brace on newline, and in the subsequent hunk. Can be fixed on commit.

Quoted 1 line

Otherwise, LGTM. Acked-by: Andrew Cooper <[email protected]>

#3 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

xen/xsm/flask/hooks.c static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) · line 122

Quoted 7 lines · Daniel P. Smith
xen/xsm/flask/hooks.c +0 -0
index 0bf63ffa84..e2ebbc7716 100644
@@ -120,8 +121,8 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad)
         struct irq_desc *desc = irq_to_desc(irq);
         if ( desc->msi_desc && desc->msi_desc->dev ) {

I've elected to also fix this misplaced brace while committing.

Quoted 9 lines

xen/xsm/flask/hooks.c static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) · line 125

Quoted 5 lines
xen/xsm/flask/hooks.c +2 -2
             struct pci_dev *dev = desc->msi_desc->dev;
-            u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
-            if (ad) {
+            uint32_t sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
+            if ( ad ) {

Brace on newline, and in the subsequent hunk.  Can be fixed on commit.

Otherwise, LGTM.  Acked-by: Andrew Cooper <[email protected]>

Strictly speaking the u32 -> uint32_t conversion was getting us only half the mileage, but I've committed the change as is (in this regard) nevertheless. In many of the cases "unsigned int" or alike should be used instead.

Jan

#4 lore raw
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

xen/xsm/flask/hooks.c static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) · line 122

Quoted 7 lines · Daniel P. Smith
xen/xsm/flask/hooks.c +0 -0
index 0bf63ffa84..e2ebbc7716 100644
@@ -120,8 +121,8 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad)
          struct irq_desc *desc = irq_to_desc(irq);
          if ( desc->msi_desc && desc->msi_desc->dev ) {

I've elected to also fix this misplaced brace while committing.

Ack.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/xsm/flask/hooks.c +2 -2
              struct pci_dev *dev = desc->msi_desc->dev;
-            u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
-            if (ad) {
+            uint32_t sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn;
+            if ( ad ) {
Quoted 8 lines
Quoted 3 lines

Brace on newline, and in the subsequent hunk.  Can be fixed on commit.

Otherwise, LGTM.  Acked-by: Andrew Cooper <[email protected]>

Strictly speaking the u32 -> uint32_t conversion was getting us only half the mileage, but I've committed the change as is (in this regard) nevertheless. In many of the cases "unsigned int" or alike should be used instead.

Thank you, I can add a review of uint{X}_t usage to the list of updates for flask.

v/r,
dps