Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'selinux-pr-20240312' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux

Pull selinux updates from Paul Moore:
"Really only a few notable changes:

- Continue the coding style/formatting fixup work

This is the bulk of the diffstat in this pull request, with the
focus this time around being the security/selinux/ss directory.

We've only got a couple of files left to cleanup and once we're
done with that we can start enabling some automatic style
verfication and introduce tooling to help new folks format their
code correctly.

- Don't restrict xattr copy-up when SELinux policy is not loaded

This helps systems that use overlayfs, or similar filesystems,
preserve their SELinux labels during early boot when the SELinux
policy has yet to be loaded.

- Reduce the work we do during inode initialization time

This isn't likely to show up in any benchmark results, but we
removed an unnecessary SELinux object class lookup/calculation
during inode initialization.

- Correct the return values in selinux_socket_getpeersec_dgram()

We had some inconsistencies with respect to our return values
across selinux_socket_getpeersec_dgram() and
selinux_socket_getpeersec_stream().

This provides a more uniform set of error codes across the two
functions and should help make it easier for users to identify
the source of a failure"

* tag 'selinux-pr-20240312' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: (24 commits)
selinux: fix style issues in security/selinux/ss/symtab.c
selinux: fix style issues in security/selinux/ss/symtab.h
selinux: fix style issues in security/selinux/ss/sidtab.c
selinux: fix style issues in security/selinux/ss/sidtab.h
selinux: fix style issues in security/selinux/ss/services.h
selinux: fix style issues in security/selinux/ss/policydb.c
selinux: fix style issues in security/selinux/ss/policydb.h
selinux: fix style issues in security/selinux/ss/mls_types.h
selinux: fix style issues in security/selinux/ss/mls.c
selinux: fix style issues in security/selinux/ss/mls.h
selinux: fix style issues in security/selinux/ss/hashtab.c
selinux: fix style issues in security/selinux/ss/hashtab.h
selinux: fix style issues in security/selinux/ss/ebitmap.c
selinux: fix style issues in security/selinux/ss/ebitmap.h
selinux: fix style issues in security/selinux/ss/context.h
selinux: fix style issues in security/selinux/ss/context.h
selinux: fix style issues in security/selinux/ss/constraint.h
selinux: fix style issues in security/selinux/ss/conditional.c
selinux: fix style issues in security/selinux/ss/conditional.h
selinux: fix style issues in security/selinux/ss/avtab.c
...

+721 -728
+15 -13
security/selinux/hooks.c
··· 2920 2920 struct superblock_security_struct *sbsec; 2921 2921 struct xattr *xattr = lsm_get_xattr_slot(xattrs, xattr_count); 2922 2922 u32 newsid, clen; 2923 + u16 newsclass; 2923 2924 int rc; 2924 2925 char *context; 2925 2926 2926 2927 sbsec = selinux_superblock(dir->i_sb); 2927 2928 2928 2929 newsid = tsec->create_sid; 2929 - 2930 - rc = selinux_determine_inode_label(tsec, dir, qstr, 2931 - inode_mode_to_security_class(inode->i_mode), 2932 - &newsid); 2930 + newsclass = inode_mode_to_security_class(inode->i_mode); 2931 + rc = selinux_determine_inode_label(tsec, dir, qstr, newsclass, &newsid); 2933 2932 if (rc) 2934 2933 return rc; 2935 2934 2936 2935 /* Possibly defer initialization to selinux_complete_init. */ 2937 2936 if (sbsec->flags & SE_SBINITIALIZED) { 2938 2937 struct inode_security_struct *isec = selinux_inode(inode); 2939 - isec->sclass = inode_mode_to_security_class(inode->i_mode); 2938 + isec->sclass = newsclass; 2940 2939 isec->sid = newsid; 2941 2940 isec->initialized = LABEL_INITIALIZED; 2942 2941 } ··· 3533 3534 { 3534 3535 /* The copy_up hook above sets the initial context on an inode, but we 3535 3536 * don't then want to overwrite it by blindly copying all the lower 3536 - * xattrs up. Instead, we have to filter out SELinux-related xattrs. 3537 + * xattrs up. Instead, filter out SELinux-related xattrs following 3538 + * policy load. 3537 3539 */ 3538 - if (strcmp(name, XATTR_NAME_SELINUX) == 0) 3540 + if (selinux_initialized() && strcmp(name, XATTR_NAME_SELINUX) == 0) 3539 3541 return 1; /* Discard */ 3540 3542 /* 3541 3543 * Any other attribute apart from SELINUX is not claimed, supported ··· 5194 5194 return err; 5195 5195 } 5196 5196 5197 - static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) 5197 + static int selinux_socket_getpeersec_dgram(struct socket *sock, 5198 + struct sk_buff *skb, u32 *secid) 5198 5199 { 5199 5200 u32 peer_secid = SECSID_NULL; 5200 5201 u16 family; 5201 - struct inode_security_struct *isec; 5202 5202 5203 5203 if (skb && skb->protocol == htons(ETH_P_IP)) 5204 5204 family = PF_INET; ··· 5206 5206 family = PF_INET6; 5207 5207 else if (sock) 5208 5208 family = sock->sk->sk_family; 5209 - else 5210 - goto out; 5209 + else { 5210 + *secid = SECSID_NULL; 5211 + return -EINVAL; 5212 + } 5211 5213 5212 5214 if (sock && family == PF_UNIX) { 5215 + struct inode_security_struct *isec; 5213 5216 isec = inode_security_novalidate(SOCK_INODE(sock)); 5214 5217 peer_secid = isec->sid; 5215 5218 } else if (skb) 5216 5219 selinux_skb_peerlbl_sid(skb, family, &peer_secid); 5217 5220 5218 - out: 5219 5221 *secid = peer_secid; 5220 5222 if (peer_secid == SECSID_NULL) 5221 - return -EINVAL; 5223 + return -ENOPROTOOPT; 5222 5224 return 0; 5223 5225 } 5224 5226
+51 -54
security/selinux/ss/avtab.c
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 2 3 * Implementation of the access vector table type. 3 4 * 4 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 5 6 */ 6 7 7 - /* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> 8 - * 9 - * Added conditional policy language extensions 10 - * 11 - * Copyright (C) 2003 Tresys Technology, LLC 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License as published by 14 - * the Free Software Foundation, version 2. 8 + /* Updated: Frank Mayer <mayerf@tresys.com> and 9 + * Karl MacMillan <kmacmillan@tresys.com> 10 + * Added conditional policy language extensions 11 + * Copyright (C) 2003 Tresys Technology, LLC 15 12 * 16 13 * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp> 17 - * Tuned number of hash slots for avtab to reduce memory usage 14 + * Tuned number of hash slots for avtab to reduce memory usage 18 15 */ 19 16 20 17 #include <linux/bitops.h> ··· 33 36 static const u32 c2 = 0x1b873593; 34 37 static const u32 r1 = 15; 35 38 static const u32 r2 = 13; 36 - static const u32 m = 5; 37 - static const u32 n = 0xe6546b64; 39 + static const u32 m = 5; 40 + static const u32 n = 0xe6546b64; 38 41 39 42 u32 hash = 0; 40 43 41 - #define mix(input) do { \ 42 - u32 v = input; \ 43 - v *= c1; \ 44 - v = (v << r1) | (v >> (32 - r1)); \ 45 - v *= c2; \ 46 - hash ^= v; \ 44 + #define mix(input) \ 45 + do { \ 46 + u32 v = input; \ 47 + v *= c1; \ 48 + v = (v << r1) | (v >> (32 - r1)); \ 49 + v *= c2; \ 50 + hash ^= v; \ 47 51 hash = (hash << r2) | (hash >> (32 - r2)); \ 48 - hash = hash * m + n; \ 52 + hash = hash * m + n; \ 49 53 } while (0) 50 54 51 55 mix(keyp->target_class); ··· 64 66 return hash & mask; 65 67 } 66 68 67 - static struct avtab_node* 68 - avtab_insert_node(struct avtab *h, struct avtab_node **dst, 69 - const struct avtab_key *key, const struct avtab_datum *datum) 69 + static struct avtab_node *avtab_insert_node(struct avtab *h, 70 + struct avtab_node **dst, 71 + const struct avtab_key *key, 72 + const struct avtab_datum *datum) 70 73 { 71 74 struct avtab_node *newnode; 72 75 struct avtab_extended_perms *xperms; ··· 98 99 static int avtab_node_cmp(const struct avtab_key *key1, 99 100 const struct avtab_key *key2) 100 101 { 101 - u16 specified = key1->specified & ~(AVTAB_ENABLED|AVTAB_ENABLED_OLD); 102 + u16 specified = key1->specified & ~(AVTAB_ENABLED | AVTAB_ENABLED_OLD); 102 103 103 104 if (key1->source_type == key2->source_type && 104 105 key1->target_type == key2->target_type && ··· 128 129 return -EINVAL; 129 130 130 131 hvalue = avtab_hash(key, h->mask); 131 - for (prev = NULL, cur = h->htable[hvalue]; 132 - cur; 132 + for (prev = NULL, cur = h->htable[hvalue]; cur; 133 133 prev = cur, cur = cur->next) { 134 134 cmp = avtab_node_cmp(key, &cur->key); 135 135 /* extended perms may not be unique */ ··· 161 163 if (!h || !h->nslot || h->nel == U32_MAX) 162 164 return NULL; 163 165 hvalue = avtab_hash(key, h->mask); 164 - for (prev = NULL, cur = h->htable[hvalue]; 165 - cur; 166 + for (prev = NULL, cur = h->htable[hvalue]; cur; 166 167 prev = cur, cur = cur->next) { 167 168 cmp = avtab_node_cmp(key, &cur->key); 168 169 if (cmp <= 0) ··· 185 188 return NULL; 186 189 187 190 hvalue = avtab_hash(key, h->mask); 188 - for (cur = h->htable[hvalue]; cur; 189 - cur = cur->next) { 191 + for (cur = h->htable[hvalue]; cur; cur = cur->next) { 190 192 cmp = avtab_node_cmp(key, &cur->key); 191 193 if (cmp == 0) 192 194 return cur; ··· 195 199 return NULL; 196 200 } 197 201 198 - struct avtab_node* 199 - avtab_search_node_next(struct avtab_node *node, u16 specified) 202 + struct avtab_node *avtab_search_node_next(struct avtab_node *node, 203 + u16 specified) 200 204 { 201 205 struct avtab_key tmp_key; 202 206 struct avtab_node *cur; ··· 310 314 311 315 if (chain_len > max_chain_len) 312 316 max_chain_len = chain_len; 313 - chain2_len_sum += (unsigned long long)chain_len * chain_len; 317 + chain2_len_sum += 318 + (unsigned long long)chain_len * chain_len; 314 319 } 315 320 } 316 321 317 322 pr_debug("SELinux: %s: %d entries and %d/%d buckets used, " 318 - "longest chain length %d, sum of chain length^2 %llu\n", 319 - tag, h->nel, slots_used, h->nslot, max_chain_len, 320 - chain2_len_sum); 323 + "longest chain length %d, sum of chain length^2 %llu\n", 324 + tag, h->nel, slots_used, h->nslot, max_chain_len, 325 + chain2_len_sum); 321 326 } 322 327 #endif /* CONFIG_SECURITY_SELINUX_DEBUG */ 323 328 329 + /* clang-format off */ 324 330 static const uint16_t spec_order[] = { 325 331 AVTAB_ALLOWED, 326 332 AVTAB_AUDITDENY, ··· 334 336 AVTAB_XPERMS_AUDITALLOW, 335 337 AVTAB_XPERMS_DONTAUDIT 336 338 }; 339 + /* clang-format on */ 337 340 338 341 int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol, 339 342 int (*insertf)(struct avtab *a, const struct avtab_key *k, ··· 364 365 if (items2 > ARRAY_SIZE(buf32)) { 365 366 pr_err("SELinux: avtab: entry overflow\n"); 366 367 return -EINVAL; 367 - 368 368 } 369 - rc = next_entry(buf32, fp, sizeof(u32)*items2); 369 + rc = next_entry(buf32, fp, sizeof(u32) * items2); 370 370 if (rc) { 371 371 pr_err("SELinux: avtab: truncated entry\n"); 372 372 return rc; ··· 398 400 pr_err("SELinux: avtab: null entry\n"); 399 401 return -EINVAL; 400 402 } 401 - if ((val & AVTAB_AV) && 402 - (val & AVTAB_TYPE)) { 403 + if ((val & AVTAB_AV) && (val & AVTAB_TYPE)) { 403 404 pr_err("SELinux: avtab: entry has both access vectors and types\n"); 404 405 return -EINVAL; 405 406 } ··· 425 428 return 0; 426 429 } 427 430 428 - rc = next_entry(buf16, fp, sizeof(u16)*4); 431 + rc = next_entry(buf16, fp, sizeof(u16) * 4); 429 432 if (rc) { 430 433 pr_err("SELinux: avtab: truncated entry\n"); 431 434 return rc; ··· 451 454 } 452 455 453 456 if ((vers < POLICYDB_VERSION_XPERMS_IOCTL) && 454 - (key.specified & AVTAB_XPERMS)) { 457 + (key.specified & AVTAB_XPERMS)) { 455 458 pr_err("SELinux: avtab: policy version %u does not " 456 - "support extended permissions rules and one " 457 - "was specified\n", vers); 459 + "support extended permissions rules and one " 460 + "was specified\n", 461 + vers); 458 462 return -EINVAL; 459 463 } else if (key.specified & AVTAB_XPERMS) { 460 464 memset(&xperms, 0, sizeof(struct avtab_extended_perms)); ··· 469 471 pr_err("SELinux: avtab: truncated entry\n"); 470 472 return rc; 471 473 } 472 - rc = next_entry(buf32, fp, sizeof(u32)*ARRAY_SIZE(xperms.perms.p)); 474 + rc = next_entry(buf32, fp, 475 + sizeof(u32) * ARRAY_SIZE(xperms.perms.p)); 473 476 if (rc) { 474 477 pr_err("SELinux: avtab: truncated entry\n"); 475 478 return rc; ··· 505 506 int rc; 506 507 __le32 buf[1]; 507 508 u32 nel, i; 508 - 509 509 510 510 rc = next_entry(buf, fp, sizeof(u32)); 511 511 if (rc < 0) { ··· 559 561 return rc; 560 562 561 563 if (cur->key.specified & AVTAB_XPERMS) { 562 - rc = put_entry(&cur->datum.u.xperms->specified, sizeof(u8), 1, fp); 564 + rc = put_entry(&cur->datum.u.xperms->specified, sizeof(u8), 1, 565 + fp); 563 566 if (rc) 564 567 return rc; 565 568 rc = put_entry(&cur->datum.u.xperms->driver, sizeof(u8), 1, fp); ··· 569 570 for (i = 0; i < ARRAY_SIZE(cur->datum.u.xperms->perms.p); i++) 570 571 buf32[i] = cpu_to_le32(cur->datum.u.xperms->perms.p[i]); 571 572 rc = put_entry(buf32, sizeof(u32), 572 - ARRAY_SIZE(cur->datum.u.xperms->perms.p), fp); 573 + ARRAY_SIZE(cur->datum.u.xperms->perms.p), fp); 573 574 } else { 574 575 buf32[0] = cpu_to_le32(cur->datum.u.data); 575 576 rc = put_entry(buf32, sizeof(u32), 1, fp); ··· 592 593 return rc; 593 594 594 595 for (i = 0; i < a->nslot; i++) { 595 - for (cur = a->htable[i]; cur; 596 - cur = cur->next) { 596 + for (cur = a->htable[i]; cur; cur = cur->next) { 597 597 rc = avtab_write_item(p, cur, fp); 598 598 if (rc) 599 599 return rc; ··· 604 606 605 607 void __init avtab_cache_init(void) 606 608 { 607 - avtab_node_cachep = kmem_cache_create("avtab_node", 608 - sizeof(struct avtab_node), 609 - 0, SLAB_PANIC, NULL); 610 - avtab_xperms_cachep = kmem_cache_create("avtab_extended_perms", 611 - sizeof(struct avtab_extended_perms), 612 - 0, SLAB_PANIC, NULL); 609 + avtab_node_cachep = kmem_cache_create( 610 + "avtab_node", sizeof(struct avtab_node), 0, SLAB_PANIC, NULL); 611 + avtab_xperms_cachep = kmem_cache_create( 612 + "avtab_extended_perms", sizeof(struct avtab_extended_perms), 0, 613 + SLAB_PANIC, NULL); 613 614 }
+37 -37
security/selinux/ss/avtab.h
··· 9 9 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 10 10 */ 11 11 12 - /* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> 13 - * 14 - * Added conditional policy language extensions 15 - * 16 - * Copyright (C) 2003 Tresys Technology, LLC 12 + /* Updated: Frank Mayer <mayerf@tresys.com> and 13 + * Karl MacMillan <kmacmillan@tresys.com> 14 + * Added conditional policy language extensions 15 + * Copyright (C) 2003 Tresys Technology, LLC 17 16 * 18 17 * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp> 19 - * Tuned number of hash slots for avtab to reduce memory usage 18 + * Tuned number of hash slots for avtab to reduce memory usage 20 19 */ 20 + 21 21 #ifndef _SS_AVTAB_H_ 22 22 #define _SS_AVTAB_H_ 23 23 24 24 #include "security.h" 25 25 26 26 struct avtab_key { 27 - u16 source_type; /* source type */ 28 - u16 target_type; /* target type */ 29 - u16 target_class; /* target object class */ 30 - #define AVTAB_ALLOWED 0x0001 31 - #define AVTAB_AUDITALLOW 0x0002 32 - #define AVTAB_AUDITDENY 0x0004 33 - #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY) 34 - #define AVTAB_TRANSITION 0x0010 35 - #define AVTAB_MEMBER 0x0020 36 - #define AVTAB_CHANGE 0x0040 37 - #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE) 27 + u16 source_type; /* source type */ 28 + u16 target_type; /* target type */ 29 + u16 target_class; /* target object class */ 30 + #define AVTAB_ALLOWED 0x0001 31 + #define AVTAB_AUDITALLOW 0x0002 32 + #define AVTAB_AUDITDENY 0x0004 33 + #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY) 34 + #define AVTAB_TRANSITION 0x0010 35 + #define AVTAB_MEMBER 0x0020 36 + #define AVTAB_CHANGE 0x0040 37 + #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE) 38 38 /* extended permissions */ 39 39 #define AVTAB_XPERMS_ALLOWED 0x0100 40 - #define AVTAB_XPERMS_AUDITALLOW 0x0200 40 + #define AVTAB_XPERMS_AUDITALLOW 0x0200 41 41 #define AVTAB_XPERMS_DONTAUDIT 0x0400 42 - #define AVTAB_XPERMS (AVTAB_XPERMS_ALLOWED | \ 43 - AVTAB_XPERMS_AUDITALLOW | \ 44 - AVTAB_XPERMS_DONTAUDIT) 45 - #define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */ 46 - #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */ 47 - u16 specified; /* what field is specified */ 42 + #define AVTAB_XPERMS \ 43 + (AVTAB_XPERMS_ALLOWED | AVTAB_XPERMS_AUDITALLOW | \ 44 + AVTAB_XPERMS_DONTAUDIT) 45 + #define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */ 46 + #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */ 47 + u16 specified; /* what field is specified */ 48 48 }; 49 49 50 50 /* ··· 53 53 */ 54 54 struct avtab_extended_perms { 55 55 /* These are not flags. All 256 values may be used */ 56 - #define AVTAB_XPERMS_IOCTLFUNCTION 0x01 57 - #define AVTAB_XPERMS_IOCTLDRIVER 0x02 56 + #define AVTAB_XPERMS_IOCTLFUNCTION 0x01 57 + #define AVTAB_XPERMS_IOCTLDRIVER 0x02 58 58 /* extension of the avtab_key specified */ 59 59 u8 specified; /* ioctl, netfilter, ... */ 60 60 /* ··· 82 82 83 83 struct avtab { 84 84 struct avtab_node **htable; 85 - u32 nel; /* number of elements */ 86 - u32 nslot; /* number of hash slots */ 87 - u32 mask; /* mask to compute hash func */ 85 + u32 nel; /* number of elements */ 86 + u32 nslot; /* number of hash slots */ 87 + u32 mask; /* mask to compute hash func */ 88 88 }; 89 89 90 90 void avtab_init(struct avtab *h); 91 91 int avtab_alloc(struct avtab *, u32); 92 92 int avtab_alloc_dup(struct avtab *new, const struct avtab *orig); 93 93 void avtab_destroy(struct avtab *h); 94 + 95 + #define MAX_AVTAB_HASH_BITS 16 96 + #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) 94 97 95 98 #ifdef CONFIG_SECURITY_SELINUX_DEBUG 96 99 void avtab_hash_eval(struct avtab *h, const char *tag); ··· 110 107 void *p); 111 108 112 109 int avtab_read(struct avtab *a, void *fp, struct policydb *pol); 113 - int avtab_write_item(struct policydb *p, const struct avtab_node *cur, void *fp); 110 + int avtab_write_item(struct policydb *p, const struct avtab_node *cur, 111 + void *fp); 114 112 int avtab_write(struct policydb *p, struct avtab *a, void *fp); 115 113 116 114 struct avtab_node *avtab_insert_nonunique(struct avtab *h, ··· 120 116 121 117 struct avtab_node *avtab_search_node(struct avtab *h, 122 118 const struct avtab_key *key); 119 + struct avtab_node *avtab_search_node_next(struct avtab_node *node, 120 + u16 specified); 123 121 124 - struct avtab_node *avtab_search_node_next(struct avtab_node *node, u16 specified); 125 - 126 - #define MAX_AVTAB_HASH_BITS 16 127 - #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) 128 - 129 - #endif /* _SS_AVTAB_H_ */ 130 - 122 + #endif /* _SS_AVTAB_H_ */
+33 -35
security/selinux/ss/conditional.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 /* Authors: Karl MacMillan <kmacmillan@tresys.com> 3 3 * Frank Mayer <mayerf@tresys.com> 4 - * 5 - * Copyright (C) 2003 - 2004 Tresys Technology, LLC 4 + * Copyright (C) 2003 - 2004 Tresys Technology, LLC 6 5 */ 7 6 8 7 #include <linux/kernel.h> ··· 165 166 int cond_init_bool_indexes(struct policydb *p) 166 167 { 167 168 kfree(p->bool_val_to_struct); 168 - p->bool_val_to_struct = kmalloc_array(p->p_bools.nprim, 169 - sizeof(*p->bool_val_to_struct), 170 - GFP_KERNEL); 169 + p->bool_val_to_struct = kmalloc_array( 170 + p->p_bools.nprim, sizeof(*p->bool_val_to_struct), GFP_KERNEL); 171 171 if (!p->bool_val_to_struct) 172 172 return -ENOMEM; 173 173 return 0; ··· 285 287 if (other) { 286 288 node_ptr = avtab_search_node(&p->te_cond_avtab, k); 287 289 if (node_ptr) { 288 - if (avtab_search_node_next(node_ptr, k->specified)) { 290 + if (avtab_search_node_next(node_ptr, 291 + k->specified)) { 289 292 pr_err("SELinux: too many conflicting type rules.\n"); 290 293 return -EINVAL; 291 294 } ··· 477 478 * the conditional. This means that the avtab with the conditional 478 479 * rules will not be saved but will be rebuilt on policy load. 479 480 */ 480 - static int cond_write_av_list(struct policydb *p, 481 - struct cond_av_list *list, struct policy_file *fp) 481 + static int cond_write_av_list(struct policydb *p, struct cond_av_list *list, 482 + struct policy_file *fp) 482 483 { 483 484 __le32 buf[1]; 484 485 u32 i; ··· 499 500 } 500 501 501 502 static int cond_write_node(struct policydb *p, struct cond_node *node, 502 - struct policy_file *fp) 503 + struct policy_file *fp) 503 504 { 504 505 __le32 buf[2]; 505 506 int rc; ··· 554 555 } 555 556 556 557 void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key, 557 - struct extended_perms_decision *xpermd) 558 + struct extended_perms_decision *xpermd) 558 559 { 559 560 struct avtab_node *node; 560 561 ··· 562 563 return; 563 564 564 565 for (node = avtab_search_node(ctab, key); node; 565 - node = avtab_search_node_next(node, key->specified)) { 566 + node = avtab_search_node_next(node, key->specified)) { 566 567 if (node->key.specified & AVTAB_ENABLED) 567 568 services_compute_xperms_decision(xpermd, node); 568 569 } ··· 571 572 * av table, and if so, add them to the result 572 573 */ 573 574 void cond_compute_av(struct avtab *ctab, struct avtab_key *key, 574 - struct av_decision *avd, struct extended_perms *xperms) 575 + struct av_decision *avd, struct extended_perms *xperms) 575 576 { 576 577 struct avtab_node *node; 577 578 ··· 579 580 return; 580 581 581 582 for (node = avtab_search_node(ctab, key); node; 582 - node = avtab_search_node_next(node, key->specified)) { 583 - if ((u16)(AVTAB_ALLOWED|AVTAB_ENABLED) == 584 - (node->key.specified & (AVTAB_ALLOWED|AVTAB_ENABLED))) 583 + node = avtab_search_node_next(node, key->specified)) { 584 + if ((u16)(AVTAB_ALLOWED | AVTAB_ENABLED) == 585 + (node->key.specified & (AVTAB_ALLOWED | AVTAB_ENABLED))) 585 586 avd->allowed |= node->datum.u.data; 586 - if ((u16)(AVTAB_AUDITDENY|AVTAB_ENABLED) == 587 - (node->key.specified & (AVTAB_AUDITDENY|AVTAB_ENABLED))) 587 + if ((u16)(AVTAB_AUDITDENY | AVTAB_ENABLED) == 588 + (node->key.specified & (AVTAB_AUDITDENY | AVTAB_ENABLED))) 588 589 /* Since a '0' in an auditdeny mask represents a 589 590 * permission we do NOT want to audit (dontaudit), we use 590 591 * the '&' operand to ensure that all '0's in the mask 591 592 * are retained (much unlike the allow and auditallow cases). 592 593 */ 593 594 avd->auditdeny &= node->datum.u.data; 594 - if ((u16)(AVTAB_AUDITALLOW|AVTAB_ENABLED) == 595 - (node->key.specified & (AVTAB_AUDITALLOW|AVTAB_ENABLED))) 595 + if ((u16)(AVTAB_AUDITALLOW | AVTAB_ENABLED) == 596 + (node->key.specified & (AVTAB_AUDITALLOW | AVTAB_ENABLED))) 596 597 avd->auditallow |= node->datum.u.data; 597 598 if (xperms && (node->key.specified & AVTAB_ENABLED) && 598 - (node->key.specified & AVTAB_XPERMS)) 599 + (node->key.specified & AVTAB_XPERMS)) 599 600 services_compute_xperms_drivers(xperms, node); 600 601 } 601 602 } 602 603 603 - static int cond_dup_av_list(struct cond_av_list *new, 604 - struct cond_av_list *orig, 605 - struct avtab *avtab) 604 + static int cond_dup_av_list(struct cond_av_list *new, struct cond_av_list *orig, 605 + struct avtab *avtab) 606 606 { 607 607 u32 i; 608 608 ··· 612 614 return -ENOMEM; 613 615 614 616 for (i = 0; i < orig->len; i++) { 615 - new->nodes[i] = avtab_insert_nonunique(avtab, 616 - &orig->nodes[i]->key, 617 - &orig->nodes[i]->datum); 617 + new->nodes[i] = avtab_insert_nonunique( 618 + avtab, &orig->nodes[i]->key, &orig->nodes[i]->datum); 618 619 if (!new->nodes[i]) 619 620 return -ENOMEM; 620 621 new->len++; ··· 634 637 635 638 newp->cond_list_len = 0; 636 639 newp->cond_list = kcalloc(origp->cond_list_len, 637 - sizeof(*newp->cond_list), 638 - GFP_KERNEL); 640 + sizeof(*newp->cond_list), GFP_KERNEL); 639 641 if (!newp->cond_list) 640 642 goto error; 641 643 ··· 645 649 newp->cond_list_len++; 646 650 647 651 newn->cur_state = orign->cur_state; 648 - newn->expr.nodes = kmemdup(orign->expr.nodes, 652 + newn->expr.nodes = 653 + kmemdup(orign->expr.nodes, 649 654 orign->expr.len * sizeof(*orign->expr.nodes), 650 655 GFP_KERNEL); 651 656 if (!newn->expr.nodes) ··· 655 658 newn->expr.len = orign->expr.len; 656 659 657 660 rc = cond_dup_av_list(&newn->true_list, &orign->true_list, 658 - &newp->te_cond_avtab); 661 + &newp->te_cond_avtab); 659 662 if (rc) 660 663 goto error; 661 664 662 665 rc = cond_dup_av_list(&newn->false_list, &orign->false_list, 663 - &newp->te_cond_avtab); 666 + &newp->te_cond_avtab); 664 667 if (rc) 665 668 goto error; 666 669 } ··· 680 683 return 0; 681 684 } 682 685 683 - static int cond_bools_copy(struct hashtab_node *new, struct hashtab_node *orig, void *args) 686 + static int cond_bools_copy(struct hashtab_node *new, struct hashtab_node *orig, 687 + void *args) 684 688 { 685 689 struct cond_bool_datum *datum; 686 690 ··· 707 709 } 708 710 709 711 static int duplicate_policydb_bools(struct policydb *newdb, 710 - struct policydb *orig) 712 + struct policydb *orig) 711 713 { 712 714 struct cond_bool_datum **cond_bool_array; 713 715 int rc; ··· 719 721 return -ENOMEM; 720 722 721 723 rc = hashtab_duplicate(&newdb->p_bools.table, &orig->p_bools.table, 722 - cond_bools_copy, cond_bools_destroy, NULL); 724 + cond_bools_copy, cond_bools_destroy, NULL); 723 725 if (rc) { 724 726 kfree(cond_bool_array); 725 727 return -ENOMEM;
+11 -12
security/selinux/ss/conditional.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 /* Authors: Karl MacMillan <kmacmillan@tresys.com> 3 3 * Frank Mayer <mayerf@tresys.com> 4 - * 5 - * Copyright (C) 2003 - 2004 Tresys Technology, LLC 4 + * Copyright (C) 2003 - 2004 Tresys Technology, LLC 6 5 */ 7 6 8 7 #ifndef _CONDITIONAL_H_ ··· 19 20 * in reverse polish notation. 20 21 */ 21 22 struct cond_expr_node { 22 - #define COND_BOOL 1 /* plain bool */ 23 - #define COND_NOT 2 /* !bool */ 24 - #define COND_OR 3 /* bool || bool */ 25 - #define COND_AND 4 /* bool && bool */ 26 - #define COND_XOR 5 /* bool ^ bool */ 27 - #define COND_EQ 6 /* bool == bool */ 28 - #define COND_NEQ 7 /* bool != bool */ 29 - #define COND_LAST COND_NEQ 23 + #define COND_BOOL 1 /* plain bool */ 24 + #define COND_NOT 2 /* !bool */ 25 + #define COND_OR 3 /* bool || bool */ 26 + #define COND_AND 4 /* bool && bool */ 27 + #define COND_XOR 5 /* bool ^ bool */ 28 + #define COND_EQ 6 /* bool == bool */ 29 + #define COND_NEQ 7 /* bool != bool */ 30 + #define COND_LAST COND_NEQ 30 31 u32 expr_type; 31 32 u32 boolean; 32 33 }; ··· 74 75 int cond_write_list(struct policydb *p, void *fp); 75 76 76 77 void cond_compute_av(struct avtab *ctab, struct avtab_key *key, 77 - struct av_decision *avd, struct extended_perms *xperms); 78 + struct av_decision *avd, struct extended_perms *xperms); 78 79 void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key, 79 - struct extended_perms_decision *xpermd); 80 + struct extended_perms_decision *xpermd); 80 81 void evaluate_cond_nodes(struct policydb *p); 81 82 void cond_policydb_destroy_dup(struct policydb *p); 82 83 int cond_policydb_dup(struct policydb *new, struct policydb *orig);
+31 -30
security/selinux/ss/constraint.h
··· 13 13 * 14 14 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 15 15 */ 16 + 16 17 #ifndef _SS_CONSTRAINT_H_ 17 18 #define _SS_CONSTRAINT_H_ 18 19 ··· 22 21 #define CEXPR_MAXDEPTH 5 23 22 24 23 struct constraint_expr { 25 - #define CEXPR_NOT 1 /* not expr */ 26 - #define CEXPR_AND 2 /* expr and expr */ 27 - #define CEXPR_OR 3 /* expr or expr */ 28 - #define CEXPR_ATTR 4 /* attr op attr */ 29 - #define CEXPR_NAMES 5 /* attr op names */ 30 - u32 expr_type; /* expression type */ 24 + #define CEXPR_NOT 1 /* not expr */ 25 + #define CEXPR_AND 2 /* expr and expr */ 26 + #define CEXPR_OR 3 /* expr or expr */ 27 + #define CEXPR_ATTR 4 /* attr op attr */ 28 + #define CEXPR_NAMES 5 /* attr op names */ 29 + u32 expr_type; /* expression type */ 31 30 32 - #define CEXPR_USER 1 /* user */ 33 - #define CEXPR_ROLE 2 /* role */ 34 - #define CEXPR_TYPE 4 /* type */ 35 - #define CEXPR_TARGET 8 /* target if set, source otherwise */ 36 - #define CEXPR_XTARGET 16 /* special 3rd target for validatetrans rule */ 37 - #define CEXPR_L1L2 32 /* low level 1 vs. low level 2 */ 38 - #define CEXPR_L1H2 64 /* low level 1 vs. high level 2 */ 39 - #define CEXPR_H1L2 128 /* high level 1 vs. low level 2 */ 40 - #define CEXPR_H1H2 256 /* high level 1 vs. high level 2 */ 41 - #define CEXPR_L1H1 512 /* low level 1 vs. high level 1 */ 42 - #define CEXPR_L2H2 1024 /* low level 2 vs. high level 2 */ 43 - u32 attr; /* attribute */ 31 + #define CEXPR_USER 1 /* user */ 32 + #define CEXPR_ROLE 2 /* role */ 33 + #define CEXPR_TYPE 4 /* type */ 34 + #define CEXPR_TARGET 8 /* target if set, source otherwise */ 35 + #define CEXPR_XTARGET 16 /* special 3rd target for validatetrans rule */ 36 + #define CEXPR_L1L2 32 /* low level 1 vs. low level 2 */ 37 + #define CEXPR_L1H2 64 /* low level 1 vs. high level 2 */ 38 + #define CEXPR_H1L2 128 /* high level 1 vs. low level 2 */ 39 + #define CEXPR_H1H2 256 /* high level 1 vs. high level 2 */ 40 + #define CEXPR_L1H1 512 /* low level 1 vs. high level 1 */ 41 + #define CEXPR_L2H2 1024 /* low level 2 vs. high level 2 */ 42 + u32 attr; /* attribute */ 44 43 45 - #define CEXPR_EQ 1 /* == or eq */ 46 - #define CEXPR_NEQ 2 /* != */ 47 - #define CEXPR_DOM 3 /* dom */ 48 - #define CEXPR_DOMBY 4 /* domby */ 49 - #define CEXPR_INCOMP 5 /* incomp */ 50 - u32 op; /* operator */ 44 + #define CEXPR_EQ 1 /* == or eq */ 45 + #define CEXPR_NEQ 2 /* != */ 46 + #define CEXPR_DOM 3 /* dom */ 47 + #define CEXPR_DOMBY 4 /* domby */ 48 + #define CEXPR_INCOMP 5 /* incomp */ 49 + u32 op; /* operator */ 51 50 52 - struct ebitmap names; /* names */ 51 + struct ebitmap names; /* names */ 53 52 struct type_set *type_names; 54 53 55 - struct constraint_expr *next; /* next expression */ 54 + struct constraint_expr *next; /* next expression */ 56 55 }; 57 56 58 57 struct constraint_node { 59 - u32 permissions; /* constrained permissions */ 60 - struct constraint_expr *expr; /* constraint on permissions */ 61 - struct constraint_node *next; /* next constraint */ 58 + u32 permissions; /* constrained permissions */ 59 + struct constraint_expr *expr; /* constraint on permissions */ 60 + struct constraint_node *next; /* next constraint */ 62 61 }; 63 62 64 - #endif /* _SS_CONSTRAINT_H_ */ 63 + #endif /* _SS_CONSTRAINT_H_ */
+1 -1
security/selinux/ss/context.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 3 * Implementations of the security context functions. 4 4 *
+22 -19
security/selinux/ss/context.h
··· 13 13 * 14 14 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 15 15 */ 16 + 16 17 #ifndef _SS_CONTEXT_H_ 17 18 #define _SS_CONTEXT_H_ 18 19 ··· 29 28 u32 user; 30 29 u32 role; 31 30 u32 type; 32 - u32 len; /* length of string in bytes */ 31 + u32 len; /* length of string in bytes */ 33 32 struct mls_range range; 34 - char *str; /* string representation if context cannot be mapped. */ 33 + char *str; /* string representation if context cannot be mapped. */ 35 34 }; 36 35 37 36 static inline void mls_context_init(struct context *c) ··· 39 38 memset(&c->range, 0, sizeof(c->range)); 40 39 } 41 40 42 - static inline int mls_context_cpy(struct context *dst, const struct context *src) 41 + static inline int mls_context_cpy(struct context *dst, 42 + const struct context *src) 43 43 { 44 44 int rc; 45 45 ··· 60 58 /* 61 59 * Sets both levels in the MLS range of 'dst' to the low level of 'src'. 62 60 */ 63 - static inline int mls_context_cpy_low(struct context *dst, const struct context *src) 61 + static inline int mls_context_cpy_low(struct context *dst, 62 + const struct context *src) 64 63 { 65 64 int rc; 66 65 ··· 81 78 /* 82 79 * Sets both levels in the MLS range of 'dst' to the high level of 'src'. 83 80 */ 84 - static inline int mls_context_cpy_high(struct context *dst, const struct context *src) 81 + static inline int mls_context_cpy_high(struct context *dst, 82 + const struct context *src) 85 83 { 86 84 int rc; 87 85 ··· 99 95 return rc; 100 96 } 101 97 102 - 103 98 static inline int mls_context_glblub(struct context *dst, 104 - const struct context *c1, const struct context *c2) 99 + const struct context *c1, 100 + const struct context *c2) 105 101 { 106 102 struct mls_range *dr = &dst->range; 107 103 const struct mls_range *r1 = &c1->range, *r2 = &c2->range; ··· 118 114 /* Take the least of the high */ 119 115 dr->level[1].sens = min(r1->level[1].sens, r2->level[1].sens); 120 116 121 - rc = ebitmap_and(&dr->level[0].cat, 122 - &r1->level[0].cat, &r2->level[0].cat); 117 + rc = ebitmap_and(&dr->level[0].cat, &r1->level[0].cat, 118 + &r2->level[0].cat); 123 119 if (rc) 124 120 goto out; 125 121 126 - rc = ebitmap_and(&dr->level[1].cat, 127 - &r1->level[1].cat, &r2->level[1].cat); 122 + rc = ebitmap_and(&dr->level[1].cat, &r1->level[1].cat, 123 + &r2->level[1].cat); 128 124 if (rc) 129 125 goto out; 130 126 ··· 132 128 return rc; 133 129 } 134 130 135 - static inline int mls_context_cmp(const struct context *c1, const struct context *c2) 131 + static inline int mls_context_cmp(const struct context *c1, 132 + const struct context *c2) 136 133 { 137 134 return ((c1->range.level[0].sens == c2->range.level[0].sens) && 138 135 ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) && ··· 188 183 mls_context_destroy(c); 189 184 } 190 185 191 - static inline int context_cmp(const struct context *c1, const struct context *c2) 186 + static inline int context_cmp(const struct context *c1, 187 + const struct context *c2) 192 188 { 193 189 if (c1->len && c2->len) 194 190 return (c1->len == c2->len && !strcmp(c1->str, c2->str)); 195 191 if (c1->len || c2->len) 196 192 return 0; 197 - return ((c1->user == c2->user) && 198 - (c1->role == c2->role) && 199 - (c1->type == c2->type) && 200 - mls_context_cmp(c1, c2)); 193 + return ((c1->user == c2->user) && (c1->role == c2->role) && 194 + (c1->type == c2->type) && mls_context_cmp(c1, c2)); 201 195 } 202 196 203 197 u32 context_compute_hash(const struct context *c); 204 198 205 - #endif /* _SS_CONTEXT_H_ */ 206 - 199 + #endif /* _SS_CONTEXT_H_ */
+28 -28
security/selinux/ss/ebitmap.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 3 * Implementation of the extensible bitmap type. 4 4 * ··· 6 6 */ 7 7 /* 8 8 * Updated: Hewlett-Packard <paul@paul-moore.com> 9 + * Added support to import/export the NetLabel category bitmap 10 + * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 9 11 * 10 - * Added support to import/export the NetLabel category bitmap 11 - * 12 - * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 13 - */ 14 - /* 15 12 * Updated: KaiGai Kohei <kaigai@ak.jp.nec.com> 16 - * Applied standard bit operations to improve bitmap scanning. 13 + * Applied standard bit operations to improve bitmap scanning. 17 14 */ 18 15 19 16 #include <linux/kernel.h> ··· 21 24 #include "ebitmap.h" 22 25 #include "policydb.h" 23 26 24 - #define BITS_PER_U64 (sizeof(u64) * 8) 27 + #define BITS_PER_U64 (sizeof(u64) * 8) 25 28 26 29 static struct kmem_cache *ebitmap_node_cachep __ro_after_init; 27 30 ··· 34 37 35 38 n1 = e1->node; 36 39 n2 = e2->node; 37 - while (n1 && n2 && 38 - (n1->startbit == n2->startbit) && 40 + while (n1 && n2 && (n1->startbit == n2->startbit) && 39 41 !memcmp(n1->maps, n2->maps, EBITMAP_SIZE / 8)) { 40 42 n1 = n1->next; 41 43 n2 = n2->next; ··· 75 79 return 0; 76 80 } 77 81 78 - int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, const struct ebitmap *e2) 82 + int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, 83 + const struct ebitmap *e2) 79 84 { 80 85 struct ebitmap_node *n; 81 86 int bit, rc; 82 87 83 88 ebitmap_init(dst); 84 89 85 - ebitmap_for_each_positive_bit(e1, n, bit) { 90 + ebitmap_for_each_positive_bit(e1, n, bit) 91 + { 86 92 if (ebitmap_get_bit(e2, bit)) { 87 93 rc = ebitmap_set_bit(dst, bit, 1); 88 94 if (rc < 0) ··· 93 95 } 94 96 return 0; 95 97 } 96 - 97 98 98 99 #ifdef CONFIG_NETLABEL 99 100 /** ··· 128 131 for (iter = 0; iter < EBITMAP_UNIT_NUMS; iter++) { 129 132 e_map = e_iter->maps[iter]; 130 133 if (e_map != 0) { 131 - rc = netlbl_catmap_setlong(catmap, 132 - offset, 133 - e_map, 134 - GFP_ATOMIC); 134 + rc = netlbl_catmap_setlong(catmap, offset, 135 + e_map, GFP_ATOMIC); 135 136 if (rc != 0) 136 137 goto netlbl_export_failure; 137 138 } ··· 180 185 if (e_iter == NULL || 181 186 offset >= e_iter->startbit + EBITMAP_SIZE) { 182 187 e_prev = e_iter; 183 - e_iter = kmem_cache_zalloc(ebitmap_node_cachep, GFP_ATOMIC); 188 + e_iter = kmem_cache_zalloc(ebitmap_node_cachep, 189 + GFP_ATOMIC); 184 190 if (e_iter == NULL) 185 191 goto netlbl_import_failure; 186 192 e_iter->startbit = offset - (offset % EBITMAP_SIZE); ··· 214 218 * if last_e2bit is non-zero, the highest set bit in e2 cannot exceed 215 219 * last_e2bit. 216 220 */ 217 - int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, u32 last_e2bit) 221 + int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, 222 + u32 last_e2bit) 218 223 { 219 224 const struct ebitmap_node *n1, *n2; 220 225 int i; ··· 231 234 n1 = n1->next; 232 235 continue; 233 236 } 234 - for (i = EBITMAP_UNIT_NUMS - 1; (i >= 0) && !n2->maps[i]; ) 235 - i--; /* Skip trailing NULL map entries */ 237 + for (i = EBITMAP_UNIT_NUMS - 1; (i >= 0) && !n2->maps[i];) 238 + i--; /* Skip trailing NULL map entries */ 236 239 if (last_e2bit && (i >= 0)) { 237 240 u32 lastsetbit = n2->startbit + i * EBITMAP_UNIT_SIZE + 238 241 __fls(n2->maps[i]); ··· 299 302 * within the bitmap 300 303 */ 301 304 if (prev) 302 - e->highbit = prev->startbit 303 - + EBITMAP_SIZE; 305 + e->highbit = prev->startbit + 306 + EBITMAP_SIZE; 304 307 else 305 308 e->highbit = 0; 306 309 } ··· 421 424 422 425 if (!n || startbit >= n->startbit + EBITMAP_SIZE) { 423 426 struct ebitmap_node *tmp; 424 - tmp = kmem_cache_zalloc(ebitmap_node_cachep, GFP_KERNEL); 427 + tmp = kmem_cache_zalloc(ebitmap_node_cachep, 428 + GFP_KERNEL); 425 429 if (!tmp) { 426 430 pr_err("SELinux: ebitmap: out of memory\n"); 427 431 rc = -ENOMEM; ··· 479 481 count = 0; 480 482 last_bit = 0; 481 483 last_startbit = -1; 482 - ebitmap_for_each_positive_bit(e, n, bit) { 484 + ebitmap_for_each_positive_bit(e, n, bit) 485 + { 483 486 if (rounddown(bit, (int)BITS_PER_U64) > last_startbit) { 484 487 count++; 485 488 last_startbit = rounddown(bit, BITS_PER_U64); ··· 496 497 497 498 map = 0; 498 499 last_startbit = INT_MIN; 499 - ebitmap_for_each_positive_bit(e, n, bit) { 500 + ebitmap_for_each_positive_bit(e, n, bit) 501 + { 500 502 if (rounddown(bit, (int)BITS_PER_U64) > last_startbit) { 501 503 __le64 buf64[1]; 502 504 ··· 559 559 void __init ebitmap_cache_init(void) 560 560 { 561 561 ebitmap_node_cachep = kmem_cache_create("ebitmap_node", 562 - sizeof(struct ebitmap_node), 563 - 0, SLAB_PANIC, NULL); 562 + sizeof(struct ebitmap_node), 0, 563 + SLAB_PANIC, NULL); 564 564 }
+23 -19
security/selinux/ss/ebitmap.h
··· 12 12 * 13 13 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 14 14 */ 15 + 15 16 #ifndef _SS_EBITMAP_H_ 16 17 #define _SS_EBITMAP_H_ 17 18 18 19 #include <net/netlabel.h> 19 20 20 21 #ifdef CONFIG_64BIT 21 - #define EBITMAP_NODE_SIZE 64 22 + #define EBITMAP_NODE_SIZE 64 22 23 #else 23 - #define EBITMAP_NODE_SIZE 32 24 + #define EBITMAP_NODE_SIZE 32 24 25 #endif 25 26 26 - #define EBITMAP_UNIT_NUMS ((EBITMAP_NODE_SIZE-sizeof(void *)-sizeof(u32))\ 27 - / sizeof(unsigned long)) 28 - #define EBITMAP_UNIT_SIZE BITS_PER_LONG 29 - #define EBITMAP_SIZE (EBITMAP_UNIT_NUMS * EBITMAP_UNIT_SIZE) 30 - #define EBITMAP_BIT 1ULL 31 - #define EBITMAP_SHIFT_UNIT_SIZE(x) \ 27 + #define EBITMAP_UNIT_NUMS \ 28 + ((EBITMAP_NODE_SIZE - sizeof(void *) - sizeof(u32)) / \ 29 + sizeof(unsigned long)) 30 + #define EBITMAP_UNIT_SIZE BITS_PER_LONG 31 + #define EBITMAP_SIZE (EBITMAP_UNIT_NUMS * EBITMAP_UNIT_SIZE) 32 + #define EBITMAP_BIT 1ULL 33 + #define EBITMAP_SHIFT_UNIT_SIZE(x) \ 32 34 (((x) >> EBITMAP_UNIT_SIZE / 2) >> EBITMAP_UNIT_SIZE / 2) 33 35 34 36 struct ebitmap_node { ··· 40 38 }; 41 39 42 40 struct ebitmap { 43 - struct ebitmap_node *node; /* first node in the bitmap */ 44 - u32 highbit; /* highest position in the total bitmap */ 41 + struct ebitmap_node *node; /* first node in the bitmap */ 42 + u32 highbit; /* highest position in the total bitmap */ 45 43 }; 46 44 47 45 #define ebitmap_length(e) ((e)->highbit) ··· 82 80 return ebitmap_length(e); 83 81 } 84 82 85 - #define EBITMAP_NODE_INDEX(node, bit) \ 83 + #define EBITMAP_NODE_INDEX(node, bit) \ 86 84 (((bit) - (node)->startbit) / EBITMAP_UNIT_SIZE) 87 - #define EBITMAP_NODE_OFFSET(node, bit) \ 85 + #define EBITMAP_NODE_OFFSET(node, bit) \ 88 86 (((bit) - (node)->startbit) % EBITMAP_UNIT_SIZE) 89 87 90 88 static inline int ebitmap_node_get_bit(const struct ebitmap_node *n, ··· 119 117 n->maps[index] &= ~(EBITMAP_BIT << ofs); 120 118 } 121 119 122 - #define ebitmap_for_each_positive_bit(e, n, bit) \ 123 - for ((bit) = ebitmap_start_positive(e, &(n)); \ 124 - (bit) < ebitmap_length(e); \ 125 - (bit) = ebitmap_next_positive(e, &(n), bit)) \ 120 + #define ebitmap_for_each_positive_bit(e, n, bit) \ 121 + for ((bit) = ebitmap_start_positive(e, &(n)); \ 122 + (bit) < ebitmap_length(e); \ 123 + (bit) = ebitmap_next_positive(e, &(n), bit)) 126 124 127 125 int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2); 128 126 int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src); 129 - int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, const struct ebitmap *e2); 130 - int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, u32 last_e2bit); 127 + int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, 128 + const struct ebitmap *e2); 129 + int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, 130 + u32 last_e2bit); 131 131 int ebitmap_get_bit(const struct ebitmap *e, unsigned long bit); 132 132 int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value); 133 133 void ebitmap_destroy(struct ebitmap *e); ··· 155 151 } 156 152 #endif 157 153 158 - #endif /* _SS_EBITMAP_H_ */ 154 + #endif /* _SS_EBITMAP_H_ */
+11 -12
security/selinux/ss/hashtab.c
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 #include <linux/kernel.h> 8 9 #include <linux/slab.h> 9 10 #include <linux/errno.h> ··· 48 47 return 0; 49 48 } 50 49 51 - int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst, 52 - void *key, void *datum) 50 + int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst, void *key, 51 + void *datum) 53 52 { 54 53 struct hashtab_node *newnode; 55 54 ··· 84 83 h->htable = NULL; 85 84 } 86 85 87 - int hashtab_map(struct hashtab *h, 88 - int (*apply)(void *k, void *d, void *args), 86 + int hashtab_map(struct hashtab *h, int (*apply)(void *k, void *d, void *args), 89 87 void *args) 90 88 { 91 89 u32 i; ··· 137 137 #endif /* CONFIG_SECURITY_SELINUX_DEBUG */ 138 138 139 139 int hashtab_duplicate(struct hashtab *new, struct hashtab *orig, 140 - int (*copy)(struct hashtab_node *new, 141 - struct hashtab_node *orig, void *args), 142 - int (*destroy)(void *k, void *d, void *args), 143 - void *args) 140 + int (*copy)(struct hashtab_node *new, 141 + struct hashtab_node *orig, void *args), 142 + int (*destroy)(void *k, void *d, void *args), void *args) 144 143 { 145 144 struct hashtab_node *cur, *tmp, *tail; 146 145 u32 i; ··· 177 178 178 179 return 0; 179 180 180 - error: 181 + error: 181 182 for (i = 0; i < new->size; i++) { 182 183 for (cur = new->htable[i]; cur; cur = tmp) { 183 184 tmp = cur->next; ··· 192 193 193 194 void __init hashtab_cache_init(void) 194 195 { 195 - hashtab_node_cachep = kmem_cache_create("hashtab_node", 196 - sizeof(struct hashtab_node), 197 - 0, SLAB_PANIC, NULL); 196 + hashtab_node_cachep = kmem_cache_create("hashtab_node", 197 + sizeof(struct hashtab_node), 0, 198 + SLAB_PANIC, NULL); 198 199 }
+17 -18
security/selinux/ss/hashtab.h
··· 8 8 * 9 9 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 10 10 */ 11 + 11 12 #ifndef _SS_HASHTAB_H_ 12 13 #define _SS_HASHTAB_H_ 13 14 ··· 16 15 #include <linux/errno.h> 17 16 #include <linux/sched.h> 18 17 19 - #define HASHTAB_MAX_NODES U32_MAX 18 + #define HASHTAB_MAX_NODES U32_MAX 20 19 21 20 struct hashtab_key_params { 22 - u32 (*hash)(const void *key); /* hash function */ 23 - int (*cmp)(const void *key1, const void *key2); 24 - /* key comparison function */ 21 + u32 (*hash)(const void *key); /* hash func */ 22 + int (*cmp)(const void *key1, const void *key2); /* comparison func */ 25 23 }; 26 24 27 25 struct hashtab_node { ··· 30 30 }; 31 31 32 32 struct hashtab { 33 - struct hashtab_node **htable; /* hash table */ 34 - u32 size; /* number of slots in hash table */ 35 - u32 nel; /* number of elements in hash table */ 33 + struct hashtab_node **htable; /* hash table */ 34 + u32 size; /* number of slots in hash table */ 35 + u32 nel; /* number of elements in hash table */ 36 36 }; 37 37 38 38 struct hashtab_info { ··· 48 48 */ 49 49 int hashtab_init(struct hashtab *h, u32 nel_hint); 50 50 51 - int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst, 52 - void *key, void *datum); 51 + int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst, void *key, 52 + void *datum); 53 53 54 54 /* 55 55 * Inserts the specified (key, datum) pair into the specified hash table. ··· 84 84 cur = cur->next; 85 85 } 86 86 87 - return __hashtab_insert(h, prev ? &prev->next : &h->htable[hvalue], 88 - key, datum); 87 + return __hashtab_insert(h, prev ? &prev->next : &h->htable[hvalue], key, 88 + datum); 89 89 } 90 90 91 91 /* ··· 133 133 * iterating through the hash table and will propagate the error 134 134 * return to its caller. 135 135 */ 136 - int hashtab_map(struct hashtab *h, 137 - int (*apply)(void *k, void *d, void *args), 136 + int hashtab_map(struct hashtab *h, int (*apply)(void *k, void *d, void *args), 138 137 void *args); 139 138 140 139 int hashtab_duplicate(struct hashtab *new, struct hashtab *orig, 141 - int (*copy)(struct hashtab_node *new, 142 - struct hashtab_node *orig, void *args), 143 - int (*destroy)(void *k, void *d, void *args), 144 - void *args); 140 + int (*copy)(struct hashtab_node *new, 141 + struct hashtab_node *orig, void *args), 142 + int (*destroy)(void *k, void *d, void *args), void *args); 145 143 146 144 #ifdef CONFIG_SECURITY_SELINUX_DEBUG 147 145 /* Fill info with some hash table statistics */ ··· 147 149 #else 148 150 static inline void hashtab_stat(struct hashtab *h, struct hashtab_info *info) 149 151 { 152 + return; 150 153 } 151 154 #endif 152 155 153 - #endif /* _SS_HASHTAB_H */ 156 + #endif /* _SS_HASHTAB_H */
+33 -50
security/selinux/ss/mls.c
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 /* 8 9 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 10 + * Support for enhanced MLS infrastructure. 11 + * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. 9 12 * 10 - * Support for enhanced MLS infrastructure. 11 - * 12 - * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. 13 - */ 14 - /* 15 13 * Updated: Hewlett-Packard <paul@paul-moore.com> 16 - * 17 - * Added support to import/export the MLS label from NetLabel 18 - * 19 - * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 14 + * Added support to import/export the MLS label from NetLabel 15 + * Copyright (C) Hewlett-Packard Development Company, L.P., 2006 20 16 */ 21 17 22 18 #include <linux/kernel.h> ··· 48 52 head = -2; 49 53 prev = -2; 50 54 e = &context->range.level[l].cat; 51 - ebitmap_for_each_positive_bit(e, node, i) { 55 + ebitmap_for_each_positive_bit(e, node, i) 56 + { 52 57 if (i - prev > 1) { 53 58 /* one or more negative bits are skipped */ 54 59 if (head != prev) { ··· 83 86 * the MLS fields of `context' into the string `*scontext'. 84 87 * Update `*scontext' to point to the end of the MLS fields. 85 88 */ 86 - void mls_sid_to_context(struct policydb *p, 87 - struct context *context, 89 + void mls_sid_to_context(struct policydb *p, struct context *context, 88 90 char **scontext) 89 91 { 90 92 char *scontextp, *nm; ··· 108 112 head = -2; 109 113 prev = -2; 110 114 e = &context->range.level[l].cat; 111 - ebitmap_for_each_positive_bit(e, node, i) { 115 + ebitmap_for_each_positive_bit(e, node, i) 116 + { 112 117 if (i - prev > 1) { 113 118 /* one or more negative bits are skipped */ 114 119 if (prev != head) { ··· 227 230 * Policy read-lock must be held for sidtab lookup. 228 231 * 229 232 */ 230 - int mls_context_to_sid(struct policydb *pol, 231 - char oldc, 232 - char *scontext, 233 - struct context *context, 234 - struct sidtab *s, 235 - u32 def_sid) 233 + int mls_context_to_sid(struct policydb *pol, char oldc, char *scontext, 234 + struct context *context, struct sidtab *s, u32 def_sid) 236 235 { 237 236 char *sensitivity, *cur_cat, *next_cat, *rngptr; 238 237 struct level_datum *levdatum; ··· 326 333 return -EINVAL; 327 334 328 335 for (i = catdatum->value; i < rngdatum->value; i++) { 329 - rc = ebitmap_set_bit(&context->range.level[l].cat, i, 1); 336 + rc = ebitmap_set_bit( 337 + &context->range.level[l].cat, i, 1); 330 338 if (rc) 331 339 return rc; 332 340 } ··· 365 371 if (!tmpstr) { 366 372 rc = -ENOMEM; 367 373 } else { 368 - rc = mls_context_to_sid(p, ':', tmpstr, context, 369 - NULL, SECSID_NULL); 374 + rc = mls_context_to_sid(p, ':', tmpstr, context, NULL, 375 + SECSID_NULL); 370 376 kfree(tmpstr); 371 377 } 372 378 ··· 376 382 /* 377 383 * Copies the MLS range `range' into `context'. 378 384 */ 379 - int mls_range_set(struct context *context, 380 - struct mls_range *range) 385 + int mls_range_set(struct context *context, struct mls_range *range) 381 386 { 382 387 int l, rc = 0; 383 388 ··· 392 399 return rc; 393 400 } 394 401 395 - int mls_setup_user_range(struct policydb *p, 396 - struct context *fromcon, struct user_datum *user, 397 - struct context *usercon) 402 + int mls_setup_user_range(struct policydb *p, struct context *fromcon, 403 + struct user_datum *user, struct context *usercon) 398 404 { 399 405 if (p->mls_enabled) { 400 406 struct mls_level *fromcon_sen = &(fromcon->range.level[0]); ··· 436 444 * policy `oldp' to the values specified in the policy `newp', 437 445 * storing the resulting context in `newc'. 438 446 */ 439 - int mls_convert_context(struct policydb *oldp, 440 - struct policydb *newp, 441 - struct context *oldc, 442 - struct context *newc) 447 + int mls_convert_context(struct policydb *oldp, struct policydb *newp, 448 + struct context *oldc, struct context *newc) 443 449 { 444 450 struct level_datum *levdatum; 445 451 struct cat_datum *catdatum; ··· 458 468 return -EINVAL; 459 469 newc->range.level[l].sens = levdatum->level->sens; 460 470 461 - ebitmap_for_each_positive_bit(&oldc->range.level[l].cat, 462 - node, i) { 471 + ebitmap_for_each_positive_bit(&oldc->range.level[l].cat, node, 472 + i) 473 + { 463 474 int rc; 464 475 465 476 catdatum = symtab_search(&newp->p_cats, ··· 477 486 return 0; 478 487 } 479 488 480 - int mls_compute_sid(struct policydb *p, 481 - struct context *scontext, 482 - struct context *tcontext, 483 - u16 tclass, 484 - u32 specified, 485 - struct context *newcontext, 486 - bool sock) 489 + int mls_compute_sid(struct policydb *p, struct context *scontext, 490 + struct context *tcontext, u16 tclass, u32 specified, 491 + struct context *newcontext, bool sock) 487 492 { 488 493 struct range_trans rtr; 489 494 struct mls_range *r; ··· 519 532 case DEFAULT_TARGET_LOW_HIGH: 520 533 return mls_context_cpy(newcontext, tcontext); 521 534 case DEFAULT_GLBLUB: 522 - return mls_context_glblub(newcontext, 523 - scontext, tcontext); 535 + return mls_context_glblub(newcontext, scontext, 536 + tcontext); 524 537 } 525 538 526 539 fallthrough; ··· 550 563 * NetLabel MLS sensitivity level field. 551 564 * 552 565 */ 553 - void mls_export_netlbl_lvl(struct policydb *p, 554 - struct context *context, 566 + void mls_export_netlbl_lvl(struct policydb *p, struct context *context, 555 567 struct netlbl_lsm_secattr *secattr) 556 568 { 557 569 if (!p->mls_enabled) ··· 571 585 * NetLabel MLS sensitivity level into the context. 572 586 * 573 587 */ 574 - void mls_import_netlbl_lvl(struct policydb *p, 575 - struct context *context, 588 + void mls_import_netlbl_lvl(struct policydb *p, struct context *context, 576 589 struct netlbl_lsm_secattr *secattr) 577 590 { 578 591 if (!p->mls_enabled) ··· 592 607 * MLS category field. Returns zero on success, negative values on failure. 593 608 * 594 609 */ 595 - int mls_export_netlbl_cat(struct policydb *p, 596 - struct context *context, 610 + int mls_export_netlbl_cat(struct policydb *p, struct context *context, 597 611 struct netlbl_lsm_secattr *secattr) 598 612 { 599 613 int rc; ··· 621 637 * negative values on failure. 622 638 * 623 639 */ 624 - int mls_import_netlbl_cat(struct policydb *p, 625 - struct context *context, 640 + int mls_import_netlbl_cat(struct policydb *p, struct context *context, 626 641 struct netlbl_lsm_secattr *secattr) 627 642 { 628 643 int rc;
+19 -39
security/selinux/ss/mls.h
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 /* 8 9 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 10 + * Support for enhanced MLS infrastructure. 11 + * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. 9 12 * 10 - * Support for enhanced MLS infrastructure. 11 - * 12 - * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc. 13 - */ 14 - /* 15 13 * Updated: Hewlett-Packard <paul@paul-moore.com> 16 - * 17 - * Added support to import/export the MLS label from NetLabel 18 - * 19 - * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 14 + * Added support to import/export the MLS label from NetLabel 15 + * Copyright (X) Hewlett-Packard Development Company, L.P., 2006 20 16 */ 21 17 22 18 #ifndef _SS_MLS_H_ ··· 31 35 int mls_range_isvalid(struct policydb *p, struct mls_range *r); 32 36 int mls_level_isvalid(struct policydb *p, struct mls_level *l); 33 37 34 - int mls_context_to_sid(struct policydb *p, 35 - char oldc, 36 - char *scontext, 37 - struct context *context, 38 - struct sidtab *s, 39 - u32 def_sid); 38 + int mls_context_to_sid(struct policydb *p, char oldc, char *scontext, 39 + struct context *context, struct sidtab *s, u32 def_sid); 40 40 41 41 int mls_from_string(struct policydb *p, char *str, struct context *context, 42 42 gfp_t gfp_mask); 43 43 44 44 int mls_range_set(struct context *context, struct mls_range *range); 45 45 46 - int mls_convert_context(struct policydb *oldp, 47 - struct policydb *newp, 48 - struct context *oldc, 49 - struct context *newc); 46 + int mls_convert_context(struct policydb *oldp, struct policydb *newp, 47 + struct context *oldc, struct context *newc); 50 48 51 - int mls_compute_sid(struct policydb *p, 52 - struct context *scontext, 53 - struct context *tcontext, 54 - u16 tclass, 55 - u32 specified, 56 - struct context *newcontext, 57 - bool sock); 49 + int mls_compute_sid(struct policydb *p, struct context *scontext, 50 + struct context *tcontext, u16 tclass, u32 specified, 51 + struct context *newcontext, bool sock); 58 52 59 - int mls_setup_user_range(struct policydb *p, 60 - struct context *fromcon, struct user_datum *user, 61 - struct context *usercon); 53 + int mls_setup_user_range(struct policydb *p, struct context *fromcon, 54 + struct user_datum *user, struct context *usercon); 62 55 63 56 #ifdef CONFIG_NETLABEL 64 - void mls_export_netlbl_lvl(struct policydb *p, 65 - struct context *context, 57 + void mls_export_netlbl_lvl(struct policydb *p, struct context *context, 66 58 struct netlbl_lsm_secattr *secattr); 67 - void mls_import_netlbl_lvl(struct policydb *p, 68 - struct context *context, 59 + void mls_import_netlbl_lvl(struct policydb *p, struct context *context, 69 60 struct netlbl_lsm_secattr *secattr); 70 - int mls_export_netlbl_cat(struct policydb *p, 71 - struct context *context, 61 + int mls_export_netlbl_cat(struct policydb *p, struct context *context, 72 62 struct netlbl_lsm_secattr *secattr); 73 - int mls_import_netlbl_cat(struct policydb *p, 74 - struct context *context, 63 + int mls_import_netlbl_cat(struct policydb *p, struct context *context, 75 64 struct netlbl_lsm_secattr *secattr); 76 65 #else 77 66 static inline void mls_export_netlbl_lvl(struct policydb *p, ··· 93 112 return hash; 94 113 } 95 114 96 - #endif /* _SS_MLS_H */ 97 - 115 + #endif /* _SS_MLS_H */
+16 -16
security/selinux/ss/mls_types.h
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 /* 8 9 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 9 - * 10 - * Support for enhanced MLS infrastructure. 11 - * 12 - * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 10 + * Support for enhanced MLS infrastructure. 11 + * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 13 12 */ 14 13 15 14 #ifndef _SS_MLS_TYPES_H_ ··· 18 19 #include "ebitmap.h" 19 20 20 21 struct mls_level { 21 - u32 sens; /* sensitivity */ 22 - struct ebitmap cat; /* category set */ 22 + u32 sens; /* sensitivity */ 23 + struct ebitmap cat; /* category set */ 23 24 }; 24 25 25 26 struct mls_range { 26 27 struct mls_level level[2]; /* low == level[0], high == level[1] */ 27 28 }; 28 29 29 - static inline int mls_level_eq(const struct mls_level *l1, const struct mls_level *l2) 30 + static inline int mls_level_eq(const struct mls_level *l1, 31 + const struct mls_level *l2) 30 32 { 31 - return ((l1->sens == l2->sens) && 32 - ebitmap_cmp(&l1->cat, &l2->cat)); 33 + return ((l1->sens == l2->sens) && ebitmap_cmp(&l1->cat, &l2->cat)); 33 34 } 34 35 35 - static inline int mls_level_dom(const struct mls_level *l1, const struct mls_level *l2) 36 + static inline int mls_level_dom(const struct mls_level *l1, 37 + const struct mls_level *l2) 36 38 { 37 39 return ((l1->sens >= l2->sens) && 38 40 ebitmap_contains(&l1->cat, &l2->cat, 0)); 39 41 } 40 42 41 43 #define mls_level_incomp(l1, l2) \ 42 - (!mls_level_dom((l1), (l2)) && !mls_level_dom((l2), (l1))) 44 + (!mls_level_dom((l1), (l2)) && !mls_level_dom((l2), (l1))) 43 45 44 46 #define mls_level_between(l1, l2, l3) \ 45 - (mls_level_dom((l1), (l2)) && mls_level_dom((l3), (l1))) 47 + (mls_level_dom((l1), (l2)) && mls_level_dom((l3), (l1))) 46 48 47 - #define mls_range_contains(r1, r2) \ 48 - (mls_level_dom(&(r2).level[0], &(r1).level[0]) && \ 49 - mls_level_dom(&(r1).level[1], &(r2).level[1])) 49 + #define mls_range_contains(r1, r2) \ 50 + (mls_level_dom(&(r2).level[0], &(r1).level[0]) && \ 51 + mls_level_dom(&(r1).level[1], &(r2).level[1])) 50 52 51 - #endif /* _SS_MLS_TYPES_H_ */ 53 + #endif /* _SS_MLS_TYPES_H_ */
+213 -192
security/selinux/ss/policydb.c
··· 7 7 8 8 /* 9 9 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 10 + * Support for enhanced MLS infrastructure. 11 + * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 10 12 * 11 - * Support for enhanced MLS infrastructure. 12 - * 13 - * Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> 14 - * 15 - * Added conditional policy language extensions 13 + * Updated: Frank Mayer <mayerf@tresys.com> and 14 + * Karl MacMillan <kmacmillan@tresys.com> 15 + * Added conditional policy language extensions 16 + * Copyright (C) 2003-2004 Tresys Technology, LLC 16 17 * 17 18 * Updated: Hewlett-Packard <paul@paul-moore.com> 18 - * 19 - * Added support for the policy capability bitmap 19 + * Added support for the policy capability bitmap 20 + * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. 20 21 * 21 22 * Update: Mellanox Techonologies 22 - * 23 - * Added Infiniband support 24 - * 25 - * Copyright (C) 2016 Mellanox Techonologies 26 - * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. 27 - * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 28 - * Copyright (C) 2003 - 2004 Tresys Technology, LLC 23 + * Added Infiniband support 24 + * Copyright (C) 2016 Mellanox Techonologies 29 25 */ 30 26 31 27 #include <linux/kernel.h> ··· 38 42 #include "services.h" 39 43 40 44 #ifdef CONFIG_SECURITY_SELINUX_DEBUG 45 + /* clang-format off */ 41 46 static const char *const symtab_name[SYM_NUM] = { 42 47 "common prefixes", 43 48 "classes", ··· 49 52 "levels", 50 53 "categories", 51 54 }; 55 + /* clang-format off */ 52 56 #endif 53 57 54 58 struct policydb_compat_info { ··· 61 63 /* These need to be updated if SYM_NUM or OCON_NUM changes */ 62 64 static const struct policydb_compat_info policydb_compat[] = { 63 65 { 64 - .version = POLICYDB_VERSION_BASE, 65 - .sym_num = SYM_NUM - 3, 66 - .ocon_num = OCON_NUM - 3, 66 + .version = POLICYDB_VERSION_BASE, 67 + .sym_num = SYM_NUM - 3, 68 + .ocon_num = OCON_NUM - 3, 67 69 }, 68 70 { 69 - .version = POLICYDB_VERSION_BOOL, 70 - .sym_num = SYM_NUM - 2, 71 - .ocon_num = OCON_NUM - 3, 71 + .version = POLICYDB_VERSION_BOOL, 72 + .sym_num = SYM_NUM - 2, 73 + .ocon_num = OCON_NUM - 3, 72 74 }, 73 75 { 74 - .version = POLICYDB_VERSION_IPV6, 75 - .sym_num = SYM_NUM - 2, 76 - .ocon_num = OCON_NUM - 2, 76 + .version = POLICYDB_VERSION_IPV6, 77 + .sym_num = SYM_NUM - 2, 78 + .ocon_num = OCON_NUM - 2, 77 79 }, 78 80 { 79 - .version = POLICYDB_VERSION_NLCLASS, 80 - .sym_num = SYM_NUM - 2, 81 - .ocon_num = OCON_NUM - 2, 81 + .version = POLICYDB_VERSION_NLCLASS, 82 + .sym_num = SYM_NUM - 2, 83 + .ocon_num = OCON_NUM - 2, 82 84 }, 83 85 { 84 - .version = POLICYDB_VERSION_MLS, 85 - .sym_num = SYM_NUM, 86 - .ocon_num = OCON_NUM - 2, 86 + .version = POLICYDB_VERSION_MLS, 87 + .sym_num = SYM_NUM, 88 + .ocon_num = OCON_NUM - 2, 87 89 }, 88 90 { 89 - .version = POLICYDB_VERSION_AVTAB, 90 - .sym_num = SYM_NUM, 91 - .ocon_num = OCON_NUM - 2, 91 + .version = POLICYDB_VERSION_AVTAB, 92 + .sym_num = SYM_NUM, 93 + .ocon_num = OCON_NUM - 2, 92 94 }, 93 95 { 94 - .version = POLICYDB_VERSION_RANGETRANS, 95 - .sym_num = SYM_NUM, 96 - .ocon_num = OCON_NUM - 2, 96 + .version = POLICYDB_VERSION_RANGETRANS, 97 + .sym_num = SYM_NUM, 98 + .ocon_num = OCON_NUM - 2, 97 99 }, 98 100 { 99 - .version = POLICYDB_VERSION_POLCAP, 100 - .sym_num = SYM_NUM, 101 - .ocon_num = OCON_NUM - 2, 101 + .version = POLICYDB_VERSION_POLCAP, 102 + .sym_num = SYM_NUM, 103 + .ocon_num = OCON_NUM - 2, 102 104 }, 103 105 { 104 - .version = POLICYDB_VERSION_PERMISSIVE, 105 - .sym_num = SYM_NUM, 106 - .ocon_num = OCON_NUM - 2, 106 + .version = POLICYDB_VERSION_PERMISSIVE, 107 + .sym_num = SYM_NUM, 108 + .ocon_num = OCON_NUM - 2, 107 109 }, 108 110 { 109 - .version = POLICYDB_VERSION_BOUNDARY, 110 - .sym_num = SYM_NUM, 111 - .ocon_num = OCON_NUM - 2, 111 + .version = POLICYDB_VERSION_BOUNDARY, 112 + .sym_num = SYM_NUM, 113 + .ocon_num = OCON_NUM - 2, 112 114 }, 113 115 { 114 - .version = POLICYDB_VERSION_FILENAME_TRANS, 115 - .sym_num = SYM_NUM, 116 - .ocon_num = OCON_NUM - 2, 116 + .version = POLICYDB_VERSION_FILENAME_TRANS, 117 + .sym_num = SYM_NUM, 118 + .ocon_num = OCON_NUM - 2, 117 119 }, 118 120 { 119 - .version = POLICYDB_VERSION_ROLETRANS, 120 - .sym_num = SYM_NUM, 121 - .ocon_num = OCON_NUM - 2, 121 + .version = POLICYDB_VERSION_ROLETRANS, 122 + .sym_num = SYM_NUM, 123 + .ocon_num = OCON_NUM - 2, 122 124 }, 123 125 { 124 - .version = POLICYDB_VERSION_NEW_OBJECT_DEFAULTS, 125 - .sym_num = SYM_NUM, 126 - .ocon_num = OCON_NUM - 2, 126 + .version = POLICYDB_VERSION_NEW_OBJECT_DEFAULTS, 127 + .sym_num = SYM_NUM, 128 + .ocon_num = OCON_NUM - 2, 127 129 }, 128 130 { 129 - .version = POLICYDB_VERSION_DEFAULT_TYPE, 130 - .sym_num = SYM_NUM, 131 - .ocon_num = OCON_NUM - 2, 131 + .version = POLICYDB_VERSION_DEFAULT_TYPE, 132 + .sym_num = SYM_NUM, 133 + .ocon_num = OCON_NUM - 2, 132 134 }, 133 135 { 134 - .version = POLICYDB_VERSION_CONSTRAINT_NAMES, 135 - .sym_num = SYM_NUM, 136 - .ocon_num = OCON_NUM - 2, 136 + .version = POLICYDB_VERSION_CONSTRAINT_NAMES, 137 + .sym_num = SYM_NUM, 138 + .ocon_num = OCON_NUM - 2, 137 139 }, 138 140 { 139 - .version = POLICYDB_VERSION_XPERMS_IOCTL, 140 - .sym_num = SYM_NUM, 141 - .ocon_num = OCON_NUM - 2, 141 + .version = POLICYDB_VERSION_XPERMS_IOCTL, 142 + .sym_num = SYM_NUM, 143 + .ocon_num = OCON_NUM - 2, 142 144 }, 143 145 { 144 - .version = POLICYDB_VERSION_INFINIBAND, 145 - .sym_num = SYM_NUM, 146 - .ocon_num = OCON_NUM, 146 + .version = POLICYDB_VERSION_INFINIBAND, 147 + .sym_num = SYM_NUM, 148 + .ocon_num = OCON_NUM, 147 149 }, 148 150 { 149 - .version = POLICYDB_VERSION_GLBLUB, 150 - .sym_num = SYM_NUM, 151 - .ocon_num = OCON_NUM, 151 + .version = POLICYDB_VERSION_GLBLUB, 152 + .sym_num = SYM_NUM, 153 + .ocon_num = OCON_NUM, 152 154 }, 153 155 { 154 - .version = POLICYDB_VERSION_COMP_FTRANS, 155 - .sym_num = SYM_NUM, 156 - .ocon_num = OCON_NUM, 156 + .version = POLICYDB_VERSION_COMP_FTRANS, 157 + .sym_num = SYM_NUM, 158 + .ocon_num = OCON_NUM, 157 159 }, 158 160 }; 159 161 160 - static const struct policydb_compat_info *policydb_lookup_compat(unsigned int version) 162 + static const struct policydb_compat_info * 163 + policydb_lookup_compat(unsigned int version) 161 164 { 162 165 unsigned int i; 163 166 ··· 311 312 return 0; 312 313 } 313 314 314 - static int (*const destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 315 + /* clang-format off */ 316 + static int (*const destroy_f[SYM_NUM])(void *key, void *datum, void *datap) = { 315 317 common_destroy, 316 318 cls_destroy, 317 319 role_destroy, ··· 322 322 sens_destroy, 323 323 cat_destroy, 324 324 }; 325 + /* clang-format on */ 325 326 326 327 static int filenametr_destroy(void *key, void *datum, void *p) 327 328 { ··· 367 366 368 367 context_destroy(&c->context[0]); 369 368 context_destroy(&c->context[1]); 370 - if (i == OCON_ISID || i == OCON_FS || 371 - i == OCON_NETIF || i == OCON_FSUSE) 369 + if (i == OCON_ISID || i == OCON_FS || i == OCON_NETIF || 370 + i == OCON_FSUSE) 372 371 kfree(c->u.name); 373 372 kfree(c); 374 373 } ··· 430 429 return v; 431 430 432 431 return strcmp(ft1->name, ft2->name); 433 - 434 432 } 435 433 436 434 static const struct hashtab_key_params filenametr_key_params = { ··· 437 437 .cmp = filenametr_cmp, 438 438 }; 439 439 440 - struct filename_trans_datum *policydb_filenametr_search( 441 - struct policydb *p, struct filename_trans_key *key) 440 + struct filename_trans_datum * 441 + policydb_filenametr_search(struct policydb *p, struct filename_trans_key *key) 442 442 { 443 443 return hashtab_search(&p->filename_trans, key, filenametr_key_params); 444 444 } ··· 448 448 const struct range_trans *key = k; 449 449 450 450 return key->source_type + (key->target_type << 3) + 451 - (key->target_class << 5); 451 + (key->target_class << 5); 452 452 } 453 453 454 454 static int rangetr_cmp(const void *k1, const void *k2) ··· 484 484 { 485 485 const struct role_trans_key *key = k; 486 486 487 - return jhash_3words(key->role, key->type, (u32)key->tclass << 16 | key->tclass, 0); 487 + return jhash_3words(key->role, key->type, 488 + (u32)key->tclass << 16 | key->tclass, 0); 488 489 } 489 490 490 491 static int role_trans_cmp(const void *k1, const void *k2) ··· 577 576 578 577 role = datum; 579 578 p = datap; 580 - if (!role->value 581 - || role->value > p->p_roles.nprim 582 - || role->bounds > p->p_roles.nprim) 579 + if (!role->value || role->value > p->p_roles.nprim || 580 + role->bounds > p->p_roles.nprim) 583 581 return -EINVAL; 584 582 585 583 p->sym_val_to_name[SYM_ROLES][role->value - 1] = key; ··· 595 595 p = datap; 596 596 597 597 if (typdatum->primary) { 598 - if (!typdatum->value 599 - || typdatum->value > p->p_types.nprim 600 - || typdatum->bounds > p->p_types.nprim) 598 + if (!typdatum->value || typdatum->value > p->p_types.nprim || 599 + typdatum->bounds > p->p_types.nprim) 601 600 return -EINVAL; 602 601 p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key; 603 602 p->type_val_to_struct[typdatum->value - 1] = typdatum; ··· 612 613 613 614 usrdatum = datum; 614 615 p = datap; 615 - if (!usrdatum->value 616 - || usrdatum->value > p->p_users.nprim 617 - || usrdatum->bounds > p->p_users.nprim) 616 + if (!usrdatum->value || usrdatum->value > p->p_users.nprim || 617 + usrdatum->bounds > p->p_users.nprim) 618 618 return -EINVAL; 619 619 620 620 p->sym_val_to_name[SYM_USERS][usrdatum->value - 1] = key; ··· 658 660 return 0; 659 661 } 660 662 661 - static int (*const index_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 663 + /* clang-format off */ 664 + static int (*const index_f[SYM_NUM])(void *key, void *datum, void *datap) = { 662 665 common_index, 663 666 class_index, 664 667 role_index, ··· 669 670 sens_index, 670 671 cat_index, 671 672 }; 673 + /* clang-format on */ 672 674 673 675 #ifdef CONFIG_SECURITY_SELINUX_DEBUG 674 676 static void hash_eval(struct hashtab *h, const char *hash_name) ··· 677 677 struct hashtab_info info; 678 678 679 679 hashtab_stat(h, &info); 680 - pr_debug("SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d, sum of chain length^2 %llu\n", 681 - hash_name, h->nel, info.slots_used, h->size, 682 - info.max_chain_len, info.chain2_len_sum); 680 + pr_debug( 681 + "SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d, sum of chain length^2 %llu\n", 682 + hash_name, h->nel, info.slots_used, h->size, info.max_chain_len, 683 + info.chain2_len_sum); 683 684 } 684 685 685 686 static void symtab_hash_eval(struct symtab *s) ··· 711 710 int i, rc; 712 711 713 712 if (p->mls_enabled) 714 - pr_debug("SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n", 715 - p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, 716 - p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); 713 + pr_debug( 714 + "SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n", 715 + p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, 716 + p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); 717 717 else 718 718 pr_debug("SELinux: %d users, %d roles, %d types, %d bools\n", 719 719 p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, 720 720 p->p_bools.nprim); 721 721 722 - pr_debug("SELinux: %d classes, %d rules\n", 723 - p->p_classes.nprim, p->te_avtab.nel); 722 + pr_debug("SELinux: %d classes, %d rules\n", p->p_classes.nprim, 723 + p->te_avtab.nel); 724 724 725 725 avtab_hash_eval(&p->te_avtab, "rules"); 726 726 symtab_hash_eval(p->symtab); ··· 732 730 if (!p->class_val_to_struct) 733 731 return -ENOMEM; 734 732 735 - p->role_val_to_struct = kcalloc(p->p_roles.nprim, 736 - sizeof(*p->role_val_to_struct), 737 - GFP_KERNEL); 733 + p->role_val_to_struct = kcalloc( 734 + p->p_roles.nprim, sizeof(*p->role_val_to_struct), GFP_KERNEL); 738 735 if (!p->role_val_to_struct) 739 736 return -ENOMEM; 740 737 741 - p->user_val_to_struct = kcalloc(p->p_users.nprim, 742 - sizeof(*p->user_val_to_struct), 743 - GFP_KERNEL); 738 + p->user_val_to_struct = kcalloc( 739 + p->p_users.nprim, sizeof(*p->user_val_to_struct), GFP_KERNEL); 744 740 if (!p->user_val_to_struct) 745 741 return -ENOMEM; 746 742 747 - p->type_val_to_struct = kvcalloc(p->p_types.nprim, 748 - sizeof(*p->type_val_to_struct), 749 - GFP_KERNEL); 743 + p->type_val_to_struct = kvcalloc( 744 + p->p_types.nprim, sizeof(*p->type_val_to_struct), GFP_KERNEL); 750 745 if (!p->type_val_to_struct) 751 746 return -ENOMEM; 752 747 ··· 753 754 754 755 for (i = 0; i < SYM_NUM; i++) { 755 756 p->sym_val_to_name[i] = kvcalloc(p->symtab[i].nprim, 756 - sizeof(char *), 757 - GFP_KERNEL); 757 + sizeof(char *), GFP_KERNEL); 758 758 if (!p->sym_val_to_name[i]) 759 759 return -ENOMEM; 760 760 ··· 855 857 int policydb_load_isids(struct policydb *p, struct sidtab *s) 856 858 { 857 859 struct ocontext *head, *c; 858 - bool isid_init_supported = ebitmap_get_bit(&p->policycaps, 859 - POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT); 860 + bool isid_init; 860 861 int rc; 861 862 862 863 rc = sidtab_init(s); ··· 863 866 pr_err("SELinux: out of memory on SID table init\n"); 864 867 return rc; 865 868 } 869 + 870 + isid_init = ebitmap_get_bit(&p->policycaps, 871 + POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT); 866 872 867 873 head = p->ocontexts[OCON_ISID]; 868 874 for (c = head; c; c = c->next) { ··· 886 886 * Also ignore SECINITSID_INIT if the policy doesn't declare 887 887 * support for it 888 888 */ 889 - if (sid == SECINITSID_INIT && !isid_init_supported) 889 + if (sid == SECINITSID_INIT && !isid_init) 890 890 continue; 891 891 892 892 rc = sidtab_set_initial(s, sid, &c->context[0]); ··· 905 905 * started before policy load would initially get the context 906 906 * corresponding to SECINITSID_KERNEL. 907 907 */ 908 - if (sid == SECINITSID_KERNEL && !isid_init_supported) { 909 - rc = sidtab_set_initial(s, SECINITSID_INIT, &c->context[0]); 908 + if (sid == SECINITSID_KERNEL && !isid_init) { 909 + rc = sidtab_set_initial(s, SECINITSID_INIT, 910 + &c->context[0]); 910 911 if (rc) { 911 912 pr_err("SELinux: unable to load initial SID %s.\n", 912 913 name); ··· 1048 1047 * Read and validate a security context structure 1049 1048 * from a policydb binary representation file. 1050 1049 */ 1051 - static int context_read_and_validate(struct context *c, 1052 - struct policydb *p, 1050 + static int context_read_and_validate(struct context *c, struct policydb *p, 1053 1051 void *fp) 1054 1052 { 1055 1053 __le32 buf[3]; ··· 1211 1211 return 0; 1212 1212 } 1213 1213 1214 - 1215 - static int read_cons_helper(struct policydb *p, 1216 - struct constraint_node **nodep, 1217 - u32 ncons, int allowxtarget, void *fp) 1214 + static int read_cons_helper(struct policydb *p, struct constraint_node **nodep, 1215 + u32 ncons, int allowxtarget, void *fp) 1218 1216 { 1219 1217 struct constraint_node *c, *lc; 1220 1218 struct constraint_expr *e, *le; ··· 1282 1284 return rc; 1283 1285 if (p->policyvers >= 1284 1286 POLICYDB_VERSION_CONSTRAINT_NAMES) { 1285 - e->type_names = kzalloc(sizeof 1286 - (*e->type_names), GFP_KERNEL); 1287 + e->type_names = 1288 + kzalloc(sizeof(*e->type_names), 1289 + GFP_KERNEL); 1287 1290 if (!e->type_names) 1288 1291 return -ENOMEM; 1289 1292 type_set_init(e->type_names); ··· 1318 1319 if (!cladatum) 1319 1320 return -ENOMEM; 1320 1321 1321 - rc = next_entry(buf, fp, sizeof(u32)*6); 1322 + rc = next_entry(buf, fp, sizeof(u32) * 6); 1322 1323 if (rc) 1323 1324 goto bad; 1324 1325 ··· 1344 1345 goto bad; 1345 1346 1346 1347 rc = -EINVAL; 1347 - cladatum->comdatum = symtab_search(&p->p_commons, 1348 - cladatum->comkey); 1348 + cladatum->comdatum = 1349 + symtab_search(&p->p_commons, cladatum->comkey); 1349 1350 if (!cladatum->comdatum) { 1350 1351 pr_err("SELinux: unknown common %s\n", 1351 1352 cladatum->comkey); ··· 1368 1369 if (rc) 1369 1370 goto bad; 1370 1371 ncons = le32_to_cpu(buf[0]); 1371 - rc = read_cons_helper(p, &cladatum->validatetrans, 1372 - ncons, 1, fp); 1372 + rc = read_cons_helper(p, &cladatum->validatetrans, ncons, 1, 1373 + fp); 1373 1374 if (rc) 1374 1375 goto bad; 1375 1376 } ··· 1505 1506 type_destroy(key, typdatum, NULL); 1506 1507 return rc; 1507 1508 } 1508 - 1509 1509 1510 1510 /* 1511 1511 * Read a MLS level structure from a policydb binary ··· 1657 1659 return rc; 1658 1660 } 1659 1661 1660 - static int (*const read_f[SYM_NUM]) (struct policydb *p, 1661 - struct symtab *s, void *fp) = { 1662 + /* clang-format off */ 1663 + static int (*const read_f[SYM_NUM])(struct policydb *p, struct symtab *s, 1664 + void *fp) = { 1662 1665 common_read, 1663 1666 class_read, 1664 1667 role_read, ··· 1669 1670 sens_read, 1670 1671 cat_read, 1671 1672 }; 1673 + /* clang-format on */ 1672 1674 1673 1675 static int user_bounds_sanity_check(void *key, void *datum, void *datap) 1674 1676 { ··· 1685 1685 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) { 1686 1686 pr_err("SELinux: user %s: " 1687 1687 "too deep or looped boundary\n", 1688 - (char *) key); 1688 + (char *)key); 1689 1689 return -EINVAL; 1690 1690 } 1691 1691 1692 1692 upper = p->user_val_to_struct[upper->bounds - 1]; 1693 - ebitmap_for_each_positive_bit(&user->roles, node, bit) { 1693 + ebitmap_for_each_positive_bit(&user->roles, node, bit) 1694 + { 1694 1695 if (ebitmap_get_bit(&upper->roles, bit)) 1695 1696 continue; 1696 1697 ··· 1722 1721 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) { 1723 1722 pr_err("SELinux: role %s: " 1724 1723 "too deep or looped bounds\n", 1725 - (char *) key); 1724 + (char *)key); 1726 1725 return -EINVAL; 1727 1726 } 1728 1727 1729 1728 upper = p->role_val_to_struct[upper->bounds - 1]; 1730 - ebitmap_for_each_positive_bit(&role->types, node, bit) { 1729 + ebitmap_for_each_positive_bit(&role->types, node, bit) 1730 + { 1731 1731 if (ebitmap_get_bit(&upper->types, bit)) 1732 1732 continue; 1733 1733 ··· 1756 1754 if (++depth == POLICYDB_BOUNDS_MAXDEPTH) { 1757 1755 pr_err("SELinux: type %s: " 1758 1756 "too deep or looped boundary\n", 1759 - (char *) key); 1757 + (char *)key); 1760 1758 return -EINVAL; 1761 1759 } 1762 1760 ··· 1766 1764 if (upper->attribute) { 1767 1765 pr_err("SELinux: type %s: " 1768 1766 "bounded by attribute %s\n", 1769 - (char *) key, 1767 + (char *)key, 1770 1768 sym_name(p, SYM_TYPES, upper->value - 1)); 1771 1769 return -EINVAL; 1772 1770 } ··· 1817 1815 if (!tclass || tclass > p->p_classes.nprim) 1818 1816 return 0; 1819 1817 1820 - cladatum = p->class_val_to_struct[tclass-1]; 1818 + cladatum = p->class_val_to_struct[tclass - 1]; 1821 1819 comdatum = cladatum->comdatum; 1822 1820 if (comdatum) 1823 1821 perdatum = symtab_search(&comdatum->permissions, name); ··· 1826 1824 if (!perdatum) 1827 1825 return 0; 1828 1826 1829 - return 1U << (perdatum->value-1); 1827 + return 1U << (perdatum->value - 1); 1830 1828 } 1831 1829 1832 1830 static int range_read(struct policydb *p, void *fp) ··· 2194 2192 goto out; 2195 2193 2196 2194 newc->v.sclass = le32_to_cpu(buf[0]); 2197 - rc = context_read_and_validate(&newc->context[0], p, fp); 2195 + rc = context_read_and_validate(&newc->context[0], p, 2196 + fp); 2198 2197 if (rc) 2199 2198 goto out; 2200 2199 2201 - for (l = NULL, c = genfs->head; c; 2202 - l = c, c = c->next) { 2200 + for (l = NULL, c = genfs->head; c; l = c, c = c->next) { 2203 2201 rc = -EINVAL; 2204 2202 if (!strcmp(newc->u.name, c->u.name) && 2205 2203 (!c->v.sclass || !newc->v.sclass || ··· 2233 2231 return rc; 2234 2232 } 2235 2233 2236 - static int ocontext_read(struct policydb *p, const struct policydb_compat_info *info, 2237 - void *fp) 2234 + static int ocontext_read(struct policydb *p, 2235 + const struct policydb_compat_info *info, void *fp) 2238 2236 { 2239 2237 int rc; 2240 2238 unsigned int i; ··· 2269 2267 goto out; 2270 2268 2271 2269 c->sid[0] = le32_to_cpu(buf[0]); 2272 - rc = context_read_and_validate(&c->context[0], p, fp); 2270 + rc = context_read_and_validate(&c->context[0], 2271 + p, fp); 2273 2272 if (rc) 2274 2273 goto out; 2275 2274 break; ··· 2289 2286 pr_warn("SELinux: void and deprecated fs ocon %s\n", 2290 2287 c->u.name); 2291 2288 2292 - rc = context_read_and_validate(&c->context[0], p, fp); 2289 + rc = context_read_and_validate(&c->context[0], 2290 + p, fp); 2293 2291 if (rc) 2294 2292 goto out; 2295 - rc = context_read_and_validate(&c->context[1], p, fp); 2293 + rc = context_read_and_validate(&c->context[1], 2294 + p, fp); 2296 2295 if (rc) 2297 2296 goto out; 2298 2297 break; 2299 2298 case OCON_PORT: 2300 - rc = next_entry(buf, fp, sizeof(u32)*3); 2299 + rc = next_entry(buf, fp, sizeof(u32) * 3); 2301 2300 if (rc) 2302 2301 goto out; 2303 2302 c->u.port.protocol = le32_to_cpu(buf[0]); 2304 2303 c->u.port.low_port = le32_to_cpu(buf[1]); 2305 2304 c->u.port.high_port = le32_to_cpu(buf[2]); 2306 - rc = context_read_and_validate(&c->context[0], p, fp); 2305 + rc = context_read_and_validate(&c->context[0], 2306 + p, fp); 2307 2307 if (rc) 2308 2308 goto out; 2309 2309 break; ··· 2316 2310 goto out; 2317 2311 c->u.node.addr = nodebuf[0]; /* network order */ 2318 2312 c->u.node.mask = nodebuf[1]; /* network order */ 2319 - rc = context_read_and_validate(&c->context[0], p, fp); 2313 + rc = context_read_and_validate(&c->context[0], 2314 + p, fp); 2320 2315 if (rc) 2321 2316 goto out; 2322 2317 break; 2323 2318 case OCON_FSUSE: 2324 - rc = next_entry(buf, fp, sizeof(u32)*2); 2319 + rc = next_entry(buf, fp, sizeof(u32) * 2); 2325 2320 if (rc) 2326 2321 goto out; 2327 2322 ··· 2339 2332 if (rc) 2340 2333 goto out; 2341 2334 2342 - rc = context_read_and_validate(&c->context[0], p, fp); 2335 + rc = context_read_and_validate(&c->context[0], 2336 + p, fp); 2343 2337 if (rc) 2344 2338 goto out; 2345 2339 break; ··· 2353 2345 for (k = 0; k < 4; k++) 2354 2346 c->u.node6.addr[k] = nodebuf[k]; 2355 2347 for (k = 0; k < 4; k++) 2356 - c->u.node6.mask[k] = nodebuf[k+4]; 2357 - rc = context_read_and_validate(&c->context[0], p, fp); 2348 + c->u.node6.mask[k] = nodebuf[k + 4]; 2349 + rc = context_read_and_validate(&c->context[0], 2350 + p, fp); 2358 2351 if (rc) 2359 2352 goto out; 2360 2353 break; ··· 2368 2359 goto out; 2369 2360 2370 2361 /* we need to have subnet_prefix in CPU order */ 2371 - c->u.ibpkey.subnet_prefix = be64_to_cpu(prefixbuf[0]); 2362 + c->u.ibpkey.subnet_prefix = 2363 + be64_to_cpu(prefixbuf[0]); 2372 2364 2373 2365 rc = next_entry(buf, fp, sizeof(u32) * 2); 2374 2366 if (rc) ··· 2383 2373 goto out; 2384 2374 } 2385 2375 2386 - c->u.ibpkey.low_pkey = pkey_lo; 2376 + c->u.ibpkey.low_pkey = pkey_lo; 2387 2377 c->u.ibpkey.high_pkey = pkey_hi; 2388 2378 2389 2379 rc = context_read_and_validate(&c->context[0], 2390 - p, 2391 - fp); 2380 + p, fp); 2392 2381 if (rc) 2393 2382 goto out; 2394 2383 break; ··· 2400 2391 goto out; 2401 2392 len = le32_to_cpu(buf[0]); 2402 2393 2403 - rc = str_read(&c->u.ibendport.dev_name, GFP_KERNEL, fp, len); 2394 + rc = str_read(&c->u.ibendport.dev_name, 2395 + GFP_KERNEL, fp, len); 2404 2396 if (rc) 2405 2397 goto out; 2406 2398 ··· 2414 2404 c->u.ibendport.port = port; 2415 2405 2416 2406 rc = context_read_and_validate(&c->context[0], 2417 - p, 2418 - fp); 2407 + p, fp); 2419 2408 if (rc) 2420 2409 goto out; 2421 2410 break; ··· 2471 2462 policydb_str = kmalloc(len + 1, GFP_KERNEL); 2472 2463 if (!policydb_str) { 2473 2464 pr_err("SELinux: unable to allocate memory for policydb " 2474 - "string of length %d\n", len); 2465 + "string of length %d\n", 2466 + len); 2475 2467 goto bad; 2476 2468 } 2477 2469 ··· 2487 2477 policydb_str[len] = '\0'; 2488 2478 if (strcmp(policydb_str, POLICYDB_STRING)) { 2489 2479 pr_err("SELinux: policydb string %s does not match " 2490 - "my string %s\n", policydb_str, POLICYDB_STRING); 2480 + "my string %s\n", 2481 + policydb_str, POLICYDB_STRING); 2491 2482 kfree(policydb_str); 2492 2483 goto bad; 2493 2484 } ··· 2497 2486 policydb_str = NULL; 2498 2487 2499 2488 /* Read the version and table sizes. */ 2500 - rc = next_entry(buf, fp, sizeof(u32)*4); 2489 + rc = next_entry(buf, fp, sizeof(u32) * 4); 2501 2490 if (rc) 2502 2491 goto bad; 2503 2492 ··· 2507 2496 p->policyvers > POLICYDB_VERSION_MAX) { 2508 2497 pr_err("SELinux: policydb version %d does not match " 2509 2498 "my version range %d-%d\n", 2510 - le32_to_cpu(buf[0]), POLICYDB_VERSION_MIN, POLICYDB_VERSION_MAX); 2499 + le32_to_cpu(buf[0]), POLICYDB_VERSION_MIN, 2500 + POLICYDB_VERSION_MAX); 2511 2501 goto bad; 2512 2502 } 2513 2503 ··· 2518 2506 rc = -EINVAL; 2519 2507 if (p->policyvers < POLICYDB_VERSION_MLS) { 2520 2508 pr_err("SELinux: security policydb version %d " 2521 - "(MLS) not backwards compatible\n", 2522 - p->policyvers); 2509 + "(MLS) not backwards compatible\n", 2510 + p->policyvers); 2523 2511 goto bad; 2524 2512 } 2525 2513 } ··· 2542 2530 info = policydb_lookup_compat(p->policyvers); 2543 2531 if (!info) { 2544 2532 pr_err("SELinux: unable to find policy compat info " 2545 - "for version %d\n", p->policyvers); 2533 + "for version %d\n", 2534 + p->policyvers); 2546 2535 goto bad; 2547 2536 } 2548 2537 2549 2538 rc = -EINVAL; 2550 2539 if (le32_to_cpu(buf[2]) != info->sym_num || 2551 - le32_to_cpu(buf[3]) != info->ocon_num) { 2540 + le32_to_cpu(buf[3]) != info->ocon_num) { 2552 2541 pr_err("SELinux: policydb table sizes (%d,%d) do " 2553 - "not match mine (%d,%d)\n", le32_to_cpu(buf[2]), 2554 - le32_to_cpu(buf[3]), 2555 - info->sym_num, info->ocon_num); 2542 + "not match mine (%d,%d)\n", 2543 + le32_to_cpu(buf[2]), le32_to_cpu(buf[3]), info->sym_num, 2544 + info->ocon_num); 2556 2545 goto bad; 2557 2546 } 2558 2547 2559 2548 for (i = 0; i < info->sym_num; i++) { 2560 - rc = next_entry(buf, fp, sizeof(u32)*2); 2549 + rc = next_entry(buf, fp, sizeof(u32) * 2); 2561 2550 if (rc) 2562 2551 goto bad; 2563 2552 nprim = le32_to_cpu(buf[0]); ··· 2619 2606 if (!rtd) 2620 2607 goto bad; 2621 2608 2622 - rc = next_entry(buf, fp, sizeof(u32)*3); 2609 + rc = next_entry(buf, fp, sizeof(u32) * 3); 2623 2610 if (rc) 2624 2611 goto bad; 2625 2612 ··· 2663 2650 lra->next = ra; 2664 2651 else 2665 2652 p->role_allow = ra; 2666 - rc = next_entry(buf, fp, sizeof(u32)*2); 2653 + rc = next_entry(buf, fp, sizeof(u32) * 2); 2667 2654 if (rc) 2668 2655 goto bad; 2669 2656 ··· 2711 2698 goto bad; 2712 2699 2713 2700 rc = -ENOMEM; 2714 - p->type_attr_map_array = kvcalloc(p->p_types.nprim, 2715 - sizeof(*p->type_attr_map_array), 2716 - GFP_KERNEL); 2701 + p->type_attr_map_array = kvcalloc( 2702 + p->p_types.nprim, sizeof(*p->type_attr_map_array), GFP_KERNEL); 2717 2703 if (!p->type_attr_map_array) 2718 2704 goto bad; 2719 2705 ··· 2785 2773 items = 2; 2786 2774 else 2787 2775 items = 3; 2788 - buf[0] = cpu_to_le32(items-1); 2776 + buf[0] = cpu_to_le32(items - 1); 2789 2777 buf[1] = cpu_to_le32(r->level[0].sens); 2790 2778 if (!eq) 2791 2779 buf[2] = cpu_to_le32(r->level[1].sens); ··· 2928 2916 * Write a security context structure 2929 2917 * to a policydb binary representation file. 2930 2918 */ 2931 - static int context_write(struct policydb *p, struct context *c, 2932 - void *fp) 2919 + static int context_write(struct policydb *p, struct context *c, void *fp) 2933 2920 { 2934 2921 int rc; 2935 2922 __le32 buf[3]; ··· 3056 3045 if (rc) 3057 3046 return rc; 3058 3047 if (p->policyvers >= 3059 - POLICYDB_VERSION_CONSTRAINT_NAMES) { 3048 + POLICYDB_VERSION_CONSTRAINT_NAMES) { 3060 3049 rc = type_set_write(e->type_names, fp); 3061 3050 if (rc) 3062 3051 return rc; ··· 3277 3266 return 0; 3278 3267 } 3279 3268 3280 - static int (*const write_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 3269 + /* clang-format off */ 3270 + static int (*const write_f[SYM_NUM])(void *key, void *datum, void *datap) = { 3281 3271 common_write, 3282 3272 class_write, 3283 3273 role_write, ··· 3288 3276 sens_write, 3289 3277 cat_write, 3290 3278 }; 3279 + /* clang-format on */ 3291 3280 3292 - static int ocontext_write(struct policydb *p, const struct policydb_compat_info *info, 3293 - void *fp) 3281 + static int ocontext_write(struct policydb *p, 3282 + const struct policydb_compat_info *info, void *fp) 3294 3283 { 3295 3284 unsigned int i, j; 3296 3285 int rc; ··· 3373 3360 break; 3374 3361 case OCON_NODE6: 3375 3362 for (j = 0; j < 4; j++) 3376 - nodebuf[j] = c->u.node6.addr[j]; /* network order */ 3363 + nodebuf[j] = 3364 + c->u.node6.addr 3365 + [j]; /* network order */ 3377 3366 for (j = 0; j < 4; j++) 3378 - nodebuf[j + 4] = c->u.node6.mask[j]; /* network order */ 3367 + nodebuf[j + 4] = 3368 + c->u.node6.mask 3369 + [j]; /* network order */ 3379 3370 rc = put_entry(nodebuf, sizeof(u32), 8, fp); 3380 3371 if (rc) 3381 3372 return rc; ··· 3389 3372 break; 3390 3373 case OCON_IBPKEY: 3391 3374 /* subnet_prefix is in CPU order */ 3392 - prefixbuf[0] = cpu_to_be64(c->u.ibpkey.subnet_prefix); 3375 + prefixbuf[0] = 3376 + cpu_to_be64(c->u.ibpkey.subnet_prefix); 3393 3377 3394 3378 rc = put_entry(prefixbuf, sizeof(u64), 1, fp); 3395 3379 if (rc) ··· 3413 3395 rc = put_entry(buf, sizeof(u32), 2, fp); 3414 3396 if (rc) 3415 3397 return rc; 3416 - rc = put_entry(c->u.ibendport.dev_name, 1, len, fp); 3398 + rc = put_entry(c->u.ibendport.dev_name, 1, len, 3399 + fp); 3417 3400 if (rc) 3418 3401 return rc; 3419 3402 rc = context_write(p, &c->context[0], fp); ··· 3540 3521 u32 bit, len = strlen(ft->name); 3541 3522 3542 3523 do { 3543 - ebitmap_for_each_positive_bit(&datum->stypes, node, bit) { 3524 + ebitmap_for_each_positive_bit(&datum->stypes, node, bit) 3525 + { 3544 3526 buf[0] = cpu_to_le32(len); 3545 3527 rc = put_entry(buf, sizeof(u32), 1, fp); 3546 3528 if (rc) ··· 3665 3645 */ 3666 3646 if (p->policyvers < POLICYDB_VERSION_AVTAB) { 3667 3647 pr_err("SELinux: refusing to write policy version %d." 3668 - " Because it is less than version %d\n", p->policyvers, 3669 - POLICYDB_VERSION_AVTAB); 3648 + " Because it is less than version %d\n", 3649 + p->policyvers, POLICYDB_VERSION_AVTAB); 3670 3650 return -EINVAL; 3671 3651 } 3672 3652 ··· 3694 3674 info = policydb_lookup_compat(p->policyvers); 3695 3675 if (!info) { 3696 3676 pr_err("SELinux: compatibility lookup failed for policy " 3697 - "version %d\n", p->policyvers); 3677 + "version %d\n", 3678 + p->policyvers); 3698 3679 return -EINVAL; 3699 3680 } 3700 3681
+95 -97
security/selinux/ss/policydb.h
··· 8 8 9 9 /* 10 10 * Updated: Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> 11 + * Support for enhanced MLS infrastructure. 12 + * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 11 13 * 12 - * Support for enhanced MLS infrastructure. 13 - * 14 - * Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com> 15 - * 16 - * Added conditional policy language extensions 17 - * 18 - * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 19 - * Copyright (C) 2003 - 2004 Tresys Technology, LLC 14 + * Updated: Frank Mayer <mayerf@tresys.com> and 15 + * Karl MacMillan <kmacmillan@tresys.com> 16 + * Added conditional policy language extensions 17 + * Copyright (C) 2003-2004 Tresys Technology, LLC 20 18 */ 21 19 22 20 #ifndef _SS_POLICYDB_H_ ··· 37 39 38 40 /* Permission attributes */ 39 41 struct perm_datum { 40 - u32 value; /* permission bit + 1 */ 42 + u32 value; /* permission bit + 1 */ 41 43 }; 42 44 43 45 /* Attributes of a common prefix for access vectors */ 44 46 struct common_datum { 45 - u32 value; /* internal common value */ 46 - struct symtab permissions; /* common permissions */ 47 + u32 value; /* internal common value */ 48 + struct symtab permissions; /* common permissions */ 47 49 }; 48 50 49 51 /* Class attributes */ 50 52 struct class_datum { 51 - u32 value; /* class value */ 52 - char *comkey; /* common name */ 53 - struct common_datum *comdatum; /* common datum */ 54 - struct symtab permissions; /* class-specific permission symbol table */ 55 - struct constraint_node *constraints; /* constraints on class permissions */ 56 - struct constraint_node *validatetrans; /* special transition rules */ 53 + u32 value; /* class value */ 54 + char *comkey; /* common name */ 55 + struct common_datum *comdatum; /* common datum */ 56 + struct symtab permissions; /* class-specific permission symbol table */ 57 + struct constraint_node *constraints; /* constraints on class perms */ 58 + struct constraint_node *validatetrans; /* special transition rules */ 57 59 /* Options how a new object user, role, and type should be decided */ 58 - #define DEFAULT_SOURCE 1 59 - #define DEFAULT_TARGET 2 60 + #define DEFAULT_SOURCE 1 61 + #define DEFAULT_TARGET 2 60 62 char default_user; 61 63 char default_role; 62 64 char default_type; 63 65 /* Options how a new object range should be decided */ 64 - #define DEFAULT_SOURCE_LOW 1 65 - #define DEFAULT_SOURCE_HIGH 2 66 - #define DEFAULT_SOURCE_LOW_HIGH 3 67 - #define DEFAULT_TARGET_LOW 4 68 - #define DEFAULT_TARGET_HIGH 5 69 - #define DEFAULT_TARGET_LOW_HIGH 6 66 + #define DEFAULT_SOURCE_LOW 1 67 + #define DEFAULT_SOURCE_HIGH 2 68 + #define DEFAULT_SOURCE_LOW_HIGH 3 69 + #define DEFAULT_TARGET_LOW 4 70 + #define DEFAULT_TARGET_HIGH 5 71 + #define DEFAULT_TARGET_LOW_HIGH 6 70 72 #define DEFAULT_GLBLUB 7 71 73 char default_range; 72 74 }; 73 75 74 76 /* Role attributes */ 75 77 struct role_datum { 76 - u32 value; /* internal role value */ 77 - u32 bounds; /* boundary of role */ 78 - struct ebitmap dominates; /* set of roles dominated by this role */ 79 - struct ebitmap types; /* set of authorized types for role */ 78 + u32 value; /* internal role value */ 79 + u32 bounds; /* boundary of role */ 80 + struct ebitmap dominates; /* set of roles dominated by this role */ 81 + struct ebitmap types; /* set of authorized types for role */ 80 82 }; 81 83 82 84 struct role_trans_key { 83 - u32 role; /* current role */ 84 - u32 type; /* program executable type, or new object type */ 85 - u32 tclass; /* process class, or new object class */ 85 + u32 role; /* current role */ 86 + u32 type; /* program executable type, or new object type */ 87 + u32 tclass; /* process class, or new object class */ 86 88 }; 87 89 88 90 struct role_trans_datum { 89 - u32 new_role; /* new role */ 91 + u32 new_role; /* new role */ 90 92 }; 91 93 92 94 struct filename_trans_key { 93 - u32 ttype; /* parent dir context */ 94 - u16 tclass; /* class of new object */ 95 - const char *name; /* last path component */ 95 + u32 ttype; /* parent dir context */ 96 + u16 tclass; /* class of new object */ 97 + const char *name; /* last path component */ 96 98 }; 97 99 98 100 struct filename_trans_datum { 99 - struct ebitmap stypes; /* bitmap of source types for this otype */ 100 - u32 otype; /* resulting type of new object */ 101 - struct filename_trans_datum *next; /* record for next otype*/ 101 + struct ebitmap stypes; /* bitmap of source types for this otype */ 102 + u32 otype; /* resulting type of new object */ 103 + struct filename_trans_datum *next; /* record for next otype*/ 102 104 }; 103 105 104 106 struct role_allow { 105 - u32 role; /* current role */ 106 - u32 new_role; /* new role */ 107 + u32 role; /* current role */ 108 + u32 new_role; /* new role */ 107 109 struct role_allow *next; 108 110 }; 109 111 110 112 /* Type attributes */ 111 113 struct type_datum { 112 - u32 value; /* internal type value */ 113 - u32 bounds; /* boundary of type */ 114 - unsigned char primary; /* primary name? */ 115 - unsigned char attribute;/* attribute ?*/ 114 + u32 value; /* internal type value */ 115 + u32 bounds; /* boundary of type */ 116 + unsigned char primary; /* primary name? */ 117 + unsigned char attribute; /* attribute ?*/ 116 118 }; 117 119 118 120 /* User attributes */ 119 121 struct user_datum { 120 - u32 value; /* internal user value */ 121 - u32 bounds; /* bounds of user */ 122 - struct ebitmap roles; /* set of authorized roles for user */ 123 - struct mls_range range; /* MLS range (min - max) for user */ 124 - struct mls_level dfltlevel; /* default login MLS level for user */ 122 + u32 value; /* internal user value */ 123 + u32 bounds; /* bounds of user */ 124 + struct ebitmap roles; /* set of authorized roles for user */ 125 + struct mls_range range; /* MLS range (min - max) for user */ 126 + struct mls_level dfltlevel; /* default login MLS level for user */ 125 127 }; 126 - 127 128 128 129 /* Sensitivity attributes */ 129 130 struct level_datum { 130 - struct mls_level *level; /* sensitivity and associated categories */ 131 - unsigned char isalias; /* is this sensitivity an alias for another? */ 131 + struct mls_level *level; /* sensitivity and associated categories */ 132 + unsigned char isalias; /* is this sensitivity an alias for another? */ 132 133 }; 133 134 134 135 /* Category attributes */ 135 136 struct cat_datum { 136 - u32 value; /* internal category bit + 1 */ 137 - unsigned char isalias; /* is this category an alias for another? */ 137 + u32 value; /* internal category bit + 1 */ 138 + unsigned char isalias; /* is this category an alias for another? */ 138 139 }; 139 140 140 141 struct range_trans { ··· 144 147 145 148 /* Boolean data type */ 146 149 struct cond_bool_datum { 147 - __u32 value; /* internal type value */ 150 + __u32 value; /* internal type value */ 148 151 int state; 149 152 }; 150 153 ··· 170 173 */ 171 174 struct ocontext { 172 175 union { 173 - char *name; /* name of initial SID, fs, netif, fstype, path */ 176 + char *name; /* name of initial SID, fs, netif, fstype, path */ 174 177 struct { 175 178 u8 protocol; 176 179 u16 low_port; 177 180 u16 high_port; 178 - } port; /* TCP or UDP port information */ 181 + } port; /* TCP or UDP port information */ 179 182 struct { 180 183 u32 addr; 181 184 u32 mask; 182 - } node; /* node information */ 185 + } node; /* node information */ 183 186 struct { 184 187 u32 addr[4]; 185 188 u32 mask[4]; 186 - } node6; /* IPv6 node information */ 189 + } node6; /* IPv6 node information */ 187 190 struct { 188 191 u64 subnet_prefix; 189 192 u16 low_pkey; ··· 195 198 } ibendport; 196 199 } u; 197 200 union { 198 - u32 sclass; /* security class for genfs */ 199 - u32 behavior; /* labeling behavior for fs_use */ 201 + u32 sclass; /* security class for genfs */ 202 + u32 behavior; /* labeling behavior for fs_use */ 200 203 } v; 201 - struct context context[2]; /* security context(s) */ 202 - u32 sid[2]; /* SID(s) */ 204 + struct context context[2]; /* security context(s) */ 205 + u32 sid[2]; /* SID(s) */ 203 206 struct ocontext *next; 204 207 }; 205 208 ··· 218 221 #define SYM_BOOLS 5 219 222 #define SYM_LEVELS 6 220 223 #define SYM_CATS 7 221 - #define SYM_NUM 8 224 + #define SYM_NUM 8 222 225 223 226 /* object context array indices */ 224 - #define OCON_ISID 0 /* initial SIDs */ 225 - #define OCON_FS 1 /* unlabeled file systems (deprecated) */ 226 - #define OCON_PORT 2 /* TCP and UDP port numbers */ 227 - #define OCON_NETIF 3 /* network interfaces */ 228 - #define OCON_NODE 4 /* nodes */ 229 - #define OCON_FSUSE 5 /* fs_use */ 230 - #define OCON_NODE6 6 /* IPv6 nodes */ 231 - #define OCON_IBPKEY 7 /* Infiniband PKeys */ 232 - #define OCON_IBENDPORT 8 /* Infiniband end ports */ 233 - #define OCON_NUM 9 227 + #define OCON_ISID 0 /* initial SIDs */ 228 + #define OCON_FS 1 /* unlabeled file systems (deprecated) */ 229 + #define OCON_PORT 2 /* TCP and UDP port numbers */ 230 + #define OCON_NETIF 3 /* network interfaces */ 231 + #define OCON_NODE 4 /* nodes */ 232 + #define OCON_FSUSE 5 /* fs_use */ 233 + #define OCON_NODE6 6 /* IPv6 nodes */ 234 + #define OCON_IBPKEY 7 /* Infiniband PKeys */ 235 + #define OCON_IBENDPORT 8 /* Infiniband end ports */ 236 + #define OCON_NUM 9 234 237 235 238 /* The policy database */ 236 239 struct policydb { ··· 240 243 struct symtab symtab[SYM_NUM]; 241 244 #define p_commons symtab[SYM_COMMONS] 242 245 #define p_classes symtab[SYM_CLASSES] 243 - #define p_roles symtab[SYM_ROLES] 244 - #define p_types symtab[SYM_TYPES] 245 - #define p_users symtab[SYM_USERS] 246 - #define p_bools symtab[SYM_BOOLS] 247 - #define p_levels symtab[SYM_LEVELS] 248 - #define p_cats symtab[SYM_CATS] 246 + #define p_roles symtab[SYM_ROLES] 247 + #define p_types symtab[SYM_TYPES] 248 + #define p_users symtab[SYM_USERS] 249 + #define p_bools symtab[SYM_BOOLS] 250 + #define p_levels symtab[SYM_LEVELS] 251 + #define p_cats symtab[SYM_CATS] 249 252 250 253 /* symbol names indexed by (value - 1) */ 251 - char **sym_val_to_name[SYM_NUM]; 254 + char **sym_val_to_name[SYM_NUM]; 252 255 253 256 /* class, role, and user attributes indexed by (value - 1) */ 254 257 struct class_datum **class_val_to_struct; ··· 321 324 extern int policydb_read(struct policydb *p, void *fp); 322 325 extern int policydb_write(struct policydb *p, void *fp); 323 326 324 - extern struct filename_trans_datum *policydb_filenametr_search( 325 - struct policydb *p, struct filename_trans_key *key); 327 + extern struct filename_trans_datum * 328 + policydb_filenametr_search(struct policydb *p, struct filename_trans_key *key); 326 329 327 - extern struct mls_range *policydb_rangetr_search( 328 - struct policydb *p, struct range_trans *key); 330 + extern struct mls_range *policydb_rangetr_search(struct policydb *p, 331 + struct range_trans *key); 329 332 330 - extern struct role_trans_datum *policydb_roletr_search( 331 - struct policydb *p, struct role_trans_key *key); 333 + extern struct role_trans_datum * 334 + policydb_roletr_search(struct policydb *p, struct role_trans_key *key); 332 335 333 - #define POLICYDB_CONFIG_MLS 1 336 + #define POLICYDB_CONFIG_MLS 1 334 337 335 338 /* the config flags related to unknown classes/perms are bits 2 and 3 */ 336 - #define REJECT_UNKNOWN 0x00000002 337 - #define ALLOW_UNKNOWN 0x00000004 339 + #define REJECT_UNKNOWN 0x00000002 340 + #define ALLOW_UNKNOWN 0x00000004 338 341 339 - #define OBJECT_R "object_r" 342 + #define OBJECT_R "object_r" 340 343 #define OBJECT_R_VAL 1 341 344 342 - #define POLICYDB_MAGIC SELINUX_MAGIC 345 + #define POLICYDB_MAGIC SELINUX_MAGIC 343 346 #define POLICYDB_STRING "SE Linux" 344 347 345 348 struct policy_file { ··· 363 366 return 0; 364 367 } 365 368 366 - static inline int put_entry(const void *buf, size_t bytes, size_t num, struct policy_file *fp) 369 + static inline int put_entry(const void *buf, size_t bytes, size_t num, 370 + struct policy_file *fp) 367 371 { 368 372 size_t len; 369 373 ··· 380 382 return 0; 381 383 } 382 384 383 - static inline char *sym_name(struct policydb *p, unsigned int sym_num, unsigned int element_nr) 385 + static inline char *sym_name(struct policydb *p, unsigned int sym_num, 386 + unsigned int element_nr) 384 387 { 385 388 return p->sym_val_to_name[sym_num][element_nr]; 386 389 } ··· 389 390 extern u16 string_to_security_class(struct policydb *p, const char *name); 390 391 extern u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name); 391 392 392 - #endif /* _SS_POLICYDB_H_ */ 393 - 393 + #endif /* _SS_POLICYDB_H_ */
+2 -1
security/selinux/ss/services.h
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 #ifndef _SS_SERVICES_H_ 8 9 #define _SS_SERVICES_H_ 9 10 ··· 44 43 struct context *oldc, struct context *newc, 45 44 gfp_t gfp_flags); 46 45 47 - #endif /* _SS_SERVICES_H_ */ 46 + #endif /* _SS_SERVICES_H_ */
+37 -32
security/selinux/ss/sidtab.c
··· 7 7 * 8 8 * Copyright (C) 2018 Red Hat, Inc. 9 9 */ 10 + 10 11 #include <linux/errno.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/list.h> ··· 30 29 }; 31 30 32 31 #define index_to_sid(index) ((index) + SECINITSID_NUM + 1) 33 - #define sid_to_index(sid) ((sid) - (SECINITSID_NUM + 1)) 32 + #define sid_to_index(sid) ((sid) - (SECINITSID_NUM + 1)) 34 33 35 34 int sidtab_init(struct sidtab *s) 36 35 { ··· 141 140 if (chain_len > max_chain_len) 142 141 max_chain_len = chain_len; 143 142 144 - return scnprintf(page, PAGE_SIZE, "entries: %d\nbuckets used: %d/%d\n" 145 - "longest chain: %d\n", entries, 146 - slots_used, SIDTAB_HASH_BUCKETS, max_chain_len); 143 + return scnprintf(page, PAGE_SIZE, 144 + "entries: %d\nbuckets used: %d/%d\n" 145 + "longest chain: %d\n", 146 + entries, slots_used, SIDTAB_HASH_BUCKETS, 147 + max_chain_len); 147 148 } 148 149 149 150 static u32 sidtab_level_from_count(u32 count) ··· 165 162 u32 l; 166 163 167 164 if (!s->roots[0].ptr_leaf) { 168 - s->roots[0].ptr_leaf = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 169 - GFP_ATOMIC); 165 + s->roots[0].ptr_leaf = 166 + kzalloc(SIDTAB_NODE_ALLOC_SIZE, GFP_ATOMIC); 170 167 if (!s->roots[0].ptr_leaf) 171 168 return -ENOMEM; 172 169 } 173 170 for (l = 1; l <= level; ++l) 174 171 if (!s->roots[l].ptr_inner) { 175 - s->roots[l].ptr_inner = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 176 - GFP_ATOMIC); 172 + s->roots[l].ptr_inner = 173 + kzalloc(SIDTAB_NODE_ALLOC_SIZE, GFP_ATOMIC); 177 174 if (!s->roots[l].ptr_inner) 178 175 return -ENOMEM; 179 176 s->roots[l].ptr_inner->entries[0] = s->roots[l - 1]; ··· 206 203 207 204 if (!entry->ptr_inner) { 208 205 if (alloc) 209 - entry->ptr_inner = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 210 - GFP_ATOMIC); 206 + entry->ptr_inner = kzalloc( 207 + SIDTAB_NODE_ALLOC_SIZE, GFP_ATOMIC); 211 208 if (!entry->ptr_inner) 212 209 return NULL; 213 210 } 214 211 } 215 212 if (!entry->ptr_leaf) { 216 213 if (alloc) 217 - entry->ptr_leaf = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 218 - GFP_ATOMIC); 214 + entry->ptr_leaf = 215 + kzalloc(SIDTAB_NODE_ALLOC_SIZE, GFP_ATOMIC); 219 216 if (!entry->ptr_leaf) 220 217 return NULL; 221 218 } ··· 265 262 return sidtab_search_core(s, sid, 1); 266 263 } 267 264 268 - int sidtab_context_to_sid(struct sidtab *s, struct context *context, 269 - u32 *sid) 265 + int sidtab_context_to_sid(struct sidtab *s, struct context *context, u32 *sid) 270 266 { 271 267 unsigned long flags; 272 268 u32 count, hash = context_compute_hash(context); ··· 329 327 goto out_unlock; 330 328 } 331 329 332 - rc = services_convert_context(convert->args, 333 - context, &dst_convert->context, 330 + rc = services_convert_context(convert->args, context, 331 + &dst_convert->context, 334 332 GFP_ATOMIC); 335 333 if (rc) { 336 334 context_destroy(&dst->context); ··· 340 338 dst_convert->hash = context_compute_hash(&dst_convert->context); 341 339 target->count = count + 1; 342 340 343 - hash_add_rcu(target->context_to_sid, 344 - &dst_convert->list, dst_convert->hash); 341 + hash_add_rcu(target->context_to_sid, &dst_convert->list, 342 + dst_convert->hash); 345 343 } 346 344 347 345 if (context->len) ··· 375 373 } 376 374 377 375 static int sidtab_convert_tree(union sidtab_entry_inner *edst, 378 - union sidtab_entry_inner *esrc, 379 - u32 *pos, u32 count, u32 level, 376 + union sidtab_entry_inner *esrc, u32 *pos, 377 + u32 count, u32 level, 380 378 struct sidtab_convert_params *convert) 381 379 { 382 380 int rc; ··· 384 382 385 383 if (level != 0) { 386 384 if (!edst->ptr_inner) { 387 - edst->ptr_inner = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 388 - GFP_KERNEL); 385 + edst->ptr_inner = 386 + kzalloc(SIDTAB_NODE_ALLOC_SIZE, GFP_KERNEL); 389 387 if (!edst->ptr_inner) 390 388 return -ENOMEM; 391 389 } ··· 401 399 } 402 400 } else { 403 401 if (!edst->ptr_leaf) { 404 - edst->ptr_leaf = kzalloc(SIDTAB_NODE_ALLOC_SIZE, 405 - GFP_KERNEL); 402 + edst->ptr_leaf = 403 + kzalloc(SIDTAB_NODE_ALLOC_SIZE, GFP_KERNEL); 406 404 if (!edst->ptr_leaf) 407 405 return -ENOMEM; 408 406 } 409 407 i = 0; 410 408 while (i < SIDTAB_LEAF_ENTRIES && *pos < count) { 411 - rc = services_convert_context(convert->args, 412 - &esrc->ptr_leaf->entries[i].context, 413 - &edst->ptr_leaf->entries[i].context, 414 - GFP_KERNEL); 409 + rc = services_convert_context( 410 + convert->args, 411 + &esrc->ptr_leaf->entries[i].context, 412 + &edst->ptr_leaf->entries[i].context, 413 + GFP_KERNEL); 415 414 if (rc) 416 415 return rc; 417 416 (*pos)++; ··· 492 489 spin_unlock_irqrestore(&s->lock, flags); 493 490 } 494 491 495 - void sidtab_freeze_begin(struct sidtab *s, unsigned long *flags) __acquires(&s->lock) 492 + void sidtab_freeze_begin(struct sidtab *s, unsigned long *flags) 493 + __acquires(&s->lock) 496 494 { 497 495 spin_lock_irqsave(&s->lock, *flags); 498 496 s->frozen = true; 499 497 s->convert = NULL; 500 498 } 501 - void sidtab_freeze_end(struct sidtab *s, unsigned long *flags) __releases(&s->lock) 499 + void sidtab_freeze_end(struct sidtab *s, unsigned long *flags) 500 + __releases(&s->lock) 502 501 { 503 502 spin_unlock_irqrestore(&s->lock, *flags); 504 503 } ··· 605 600 kfree_rcu(victim, rcu_member); 606 601 } 607 602 608 - int sidtab_sid2str_get(struct sidtab *s, struct sidtab_entry *entry, 609 - char **out, u32 *out_len) 603 + int sidtab_sid2str_get(struct sidtab *s, struct sidtab_entry *entry, char **out, 604 + u32 *out_len) 610 605 { 611 606 struct sidtab_str_cache *cache; 612 607 int rc = 0;
+19 -17
security/selinux/ss/sidtab.h
··· 8 8 * 9 9 * Copyright (C) 2018 Red Hat, Inc. 10 10 */ 11 + 11 12 #ifndef _SS_SIDTAB_H_ 12 13 #define _SS_SIDTAB_H_ 13 14 ··· 30 29 31 30 union sidtab_entry_inner { 32 31 struct sidtab_node_inner *ptr_inner; 33 - struct sidtab_node_leaf *ptr_leaf; 32 + struct sidtab_node_leaf *ptr_leaf; 34 33 }; 35 34 36 35 /* align node size to page boundary */ 37 36 #define SIDTAB_NODE_ALLOC_SHIFT PAGE_SHIFT 38 - #define SIDTAB_NODE_ALLOC_SIZE PAGE_SIZE 37 + #define SIDTAB_NODE_ALLOC_SIZE PAGE_SIZE 39 38 40 - #define size_to_shift(size) ((size) == 1 ? 1 : (const_ilog2((size) - 1) + 1)) 39 + #define size_to_shift(size) ((size) == 1 ? 1 : (const_ilog2((size)-1) + 1)) 41 40 42 - #define SIDTAB_INNER_SHIFT \ 43 - (SIDTAB_NODE_ALLOC_SHIFT - size_to_shift(sizeof(union sidtab_entry_inner))) 41 + #define SIDTAB_INNER_SHIFT \ 42 + (SIDTAB_NODE_ALLOC_SHIFT - \ 43 + size_to_shift(sizeof(union sidtab_entry_inner))) 44 44 #define SIDTAB_INNER_ENTRIES ((size_t)1 << SIDTAB_INNER_SHIFT) 45 45 #define SIDTAB_LEAF_ENTRIES \ 46 46 (SIDTAB_NODE_ALLOC_SIZE / sizeof(struct sidtab_entry)) 47 47 48 48 #define SIDTAB_MAX_BITS 32 49 - #define SIDTAB_MAX U32_MAX 49 + #define SIDTAB_MAX U32_MAX 50 50 /* ensure enough tree levels for SIDTAB_MAX entries */ 51 - #define SIDTAB_MAX_LEVEL \ 51 + #define SIDTAB_MAX_LEVEL \ 52 52 DIV_ROUND_UP(SIDTAB_MAX_BITS - size_to_shift(SIDTAB_LEAF_ENTRIES), \ 53 53 SIDTAB_INNER_SHIFT) 54 54 ··· 71 69 struct sidtab *target; 72 70 }; 73 71 74 - #define SIDTAB_HASH_BITS CONFIG_SECURITY_SELINUX_SIDTAB_HASH_BITS 72 + #define SIDTAB_HASH_BITS CONFIG_SECURITY_SELINUX_SIDTAB_HASH_BITS 75 73 #define SIDTAB_HASH_BUCKETS (1 << SIDTAB_HASH_BITS) 76 74 77 75 struct sidtab { ··· 127 125 128 126 void sidtab_cancel_convert(struct sidtab *s); 129 127 130 - void sidtab_freeze_begin(struct sidtab *s, unsigned long *flags) __acquires(&s->lock); 131 - void sidtab_freeze_end(struct sidtab *s, unsigned long *flags) __releases(&s->lock); 128 + void sidtab_freeze_begin(struct sidtab *s, unsigned long *flags) 129 + __acquires(&s->lock); 130 + void sidtab_freeze_end(struct sidtab *s, unsigned long *flags) 131 + __releases(&s->lock); 132 132 133 133 int sidtab_context_to_sid(struct sidtab *s, struct context *context, u32 *sid); 134 134 ··· 141 137 #if CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0 142 138 void sidtab_sid2str_put(struct sidtab *s, struct sidtab_entry *entry, 143 139 const char *str, u32 str_len); 144 - int sidtab_sid2str_get(struct sidtab *s, struct sidtab_entry *entry, 145 - char **out, u32 *out_len); 140 + int sidtab_sid2str_get(struct sidtab *s, struct sidtab_entry *entry, char **out, 141 + u32 *out_len); 146 142 #else 147 143 static inline void sidtab_sid2str_put(struct sidtab *s, 148 144 struct sidtab_entry *entry, ··· 150 146 { 151 147 } 152 148 static inline int sidtab_sid2str_get(struct sidtab *s, 153 - struct sidtab_entry *entry, 154 - char **out, u32 *out_len) 149 + struct sidtab_entry *entry, char **out, 150 + u32 *out_len) 155 151 { 156 152 return -ENOENT; 157 153 } 158 154 #endif /* CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE > 0 */ 159 155 160 - #endif /* _SS_SIDTAB_H_ */ 161 - 162 - 156 + #endif /* _SS_SIDTAB_H_ */
+3 -1
security/selinux/ss/symtab.c
··· 4 4 * 5 5 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 6 6 */ 7 + 7 8 #include <linux/kernel.h> 8 9 #include <linux/string.h> 9 10 #include <linux/errno.h> ··· 20 19 keyp = key; 21 20 size = strlen(keyp); 22 21 for (p = keyp; (p - keyp) < size; p++) 23 - val = (val << 4 | (val >> (8*sizeof(unsigned int)-4))) ^ (*p); 22 + val = (val << 4 | (val >> (8 * sizeof(unsigned int) - 4))) ^ 23 + (*p); 24 24 return val; 25 25 } 26 26
+4 -5
security/selinux/ss/symtab.h
··· 7 7 * 8 8 * Author : Stephen Smalley, <stephen.smalley.work@gmail.com> 9 9 */ 10 + 10 11 #ifndef _SS_SYMTAB_H_ 11 12 #define _SS_SYMTAB_H_ 12 13 13 14 #include "hashtab.h" 14 15 15 16 struct symtab { 16 - struct hashtab table; /* hash table (keyed on a string) */ 17 - u32 nprim; /* number of primary names in table */ 17 + struct hashtab table; /* hash table (keyed on a string) */ 18 + u32 nprim; /* number of primary names in table */ 18 19 }; 19 20 20 21 int symtab_init(struct symtab *s, u32 size); ··· 23 22 int symtab_insert(struct symtab *s, char *name, void *datum); 24 23 void *symtab_search(struct symtab *s, const char *name); 25 24 26 - #endif /* _SS_SYMTAB_H_ */ 27 - 28 - 25 + #endif /* _SS_SYMTAB_H_ */