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

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

Pull selinux updates from Paul Moore:
"We've got twelve patches queued for v5.19, with most being fairly
minor. The highlights are below:

- The checkreqprot and runtime disable knobs have been deprecated for
some time with no active users that we can find. In an effort to
move things along we are adding a pause when the knobs are used to
help make the deprecation more noticeable in case anyone is still
using these hacks in the shadows.

- We've added the anonymous inode class name to the AVC audit records
when anonymous inodes are involved. This should make writing policy
easier when anonymous inodes are involved.

- More constification work. This is fairly straightforward and the
source of most of the diffstat.

- The usual minor cleanups: remove unnecessary assignments, assorted
style/checkpatch fixes, kdoc fixes, macro while-loop
encapsulations, #include tweaks, etc"

* tag 'selinux-pr-20220523' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux:
security: declare member holding string literal const
selinux: log anon inode class name
selinux: declare data arrays const
selinux: fix indentation level of mls_ops block
selinux: include necessary headers in headers
selinux: avoid extra semicolon
selinux: update parameter documentation
selinux: resolve checkpatch errors
selinux: don't sleep when CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is true
selinux: checkreqprot is deprecated, add some ssleep() discomfort
selinux: runtime disable is deprecated, add some ssleep() discomfort
selinux: Remove redundant assignments

+144 -115
+2
include/linux/lsm_audit.h
··· 76 76 #define LSM_AUDIT_DATA_IBENDPORT 14 77 77 #define LSM_AUDIT_DATA_LOCKDOWN 15 78 78 #define LSM_AUDIT_DATA_NOTIFICATION 16 79 + #define LSM_AUDIT_DATA_ANONINODE 17 79 80 union { 80 81 struct path path; 81 82 struct dentry *dentry; ··· 97 96 struct lsm_ibpkey_audit *ibpkey; 98 97 struct lsm_ibendport_audit *ibendport; 99 98 int reason; 99 + const char *anonclass; 100 100 } u; 101 101 /* this union contains LSM specific data */ 102 102 union {
+2 -2
include/linux/lsm_hooks.h
··· 1595 1595 struct hlist_node list; 1596 1596 struct hlist_head *head; 1597 1597 union security_list_options hook; 1598 - char *lsm; 1598 + const char *lsm; 1599 1599 } __randomize_layout; 1600 1600 1601 1601 /* ··· 1630 1630 extern char *lsm_names; 1631 1631 1632 1632 extern void security_add_hooks(struct security_hook_list *hooks, int count, 1633 - char *lsm); 1633 + const char *lsm); 1634 1634 1635 1635 #define LSM_FLAG_LEGACY_MAJOR BIT(0) 1636 1636 #define LSM_FLAG_EXCLUSIVE BIT(1)
+45 -30
scripts/selinux/genheaders/genheaders.c
··· 59 59 exit(2); 60 60 } 61 61 62 - for (i = 0; secclass_map[i].name; i++) { 63 - struct security_class_mapping *map = &secclass_map[i]; 64 - map->name = stoupperx(map->name); 65 - for (j = 0; map->perms[j]; j++) 66 - map->perms[j] = stoupperx(map->perms[j]); 67 - } 68 - 69 - isids_len = sizeof(initial_sid_to_string) / sizeof (char *); 70 - for (i = 1; i < isids_len; i++) { 71 - const char *s = initial_sid_to_string[i]; 72 - 73 - if (s) 74 - initial_sid_to_string[i] = stoupperx(s); 75 - } 76 - 77 62 fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); 78 63 fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n"); 79 64 80 65 for (i = 0; secclass_map[i].name; i++) { 81 - struct security_class_mapping *map = &secclass_map[i]; 82 - fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1); 66 + char *name = stoupperx(secclass_map[i].name); 67 + 68 + fprintf(fout, "#define SECCLASS_%-39s %2d\n", name, i+1); 69 + free(name); 83 70 } 84 71 85 72 fprintf(fout, "\n"); 86 73 74 + isids_len = sizeof(initial_sid_to_string) / sizeof(char *); 87 75 for (i = 1; i < isids_len; i++) { 88 76 const char *s = initial_sid_to_string[i]; 89 - if (s) 90 - fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i); 77 + if (s) { 78 + char *sidname = stoupperx(s); 79 + 80 + fprintf(fout, "#define SECINITSID_%-39s %2d\n", sidname, i); 81 + free(sidname); 82 + } 91 83 } 92 84 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); 93 85 fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); ··· 88 96 fprintf(fout, "\tswitch (kern_tclass) {\n"); 89 97 for (i = 0; secclass_map[i].name; i++) { 90 98 static char s[] = "SOCKET"; 91 - struct security_class_mapping *map = &secclass_map[i]; 92 - int len = strlen(map->name), l = sizeof(s) - 1; 93 - if (len >= l && memcmp(map->name + len - l, s, l) == 0) 94 - fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); 99 + int len, l; 100 + char *name = stoupperx(secclass_map[i].name); 101 + 102 + len = strlen(name); 103 + l = sizeof(s) - 1; 104 + if (len >= l && memcmp(name + len - l, s, l) == 0) 105 + fprintf(fout, "\tcase SECCLASS_%s:\n", name); 106 + free(name); 95 107 } 96 108 fprintf(fout, "\t\tsock = true;\n"); 97 109 fprintf(fout, "\t\tbreak;\n"); ··· 106 110 fprintf(fout, "}\n"); 107 111 108 112 fprintf(fout, "\n#endif\n"); 109 - fclose(fout); 113 + 114 + if (fclose(fout) != 0) { 115 + fprintf(stderr, "Could not successfully close %s: %s\n", 116 + argv[1], strerror(errno)); 117 + exit(4); 118 + } 110 119 111 120 fout = fopen(argv[2], "w"); 112 121 if (!fout) { 113 122 fprintf(stderr, "Could not open %s for writing: %s\n", 114 123 argv[2], strerror(errno)); 115 - exit(4); 124 + exit(5); 116 125 } 117 126 118 127 fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); 119 128 fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n"); 120 129 121 130 for (i = 0; secclass_map[i].name; i++) { 122 - struct security_class_mapping *map = &secclass_map[i]; 123 - int len = strlen(map->name); 131 + const struct security_class_mapping *map = &secclass_map[i]; 132 + int len; 133 + char *name = stoupperx(map->name); 134 + 135 + len = strlen(name); 124 136 for (j = 0; map->perms[j]; j++) { 137 + char *permname; 138 + 125 139 if (j >= 32) { 126 140 fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", 127 141 map->name, map->perms[j]); 128 142 exit(5); 129 143 } 130 - fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name, 131 - 39-len, map->perms[j], 1U<<j); 144 + permname = stoupperx(map->perms[j]); 145 + fprintf(fout, "#define %s__%-*s 0x%08xU\n", name, 146 + 39-len, permname, 1U<<j); 147 + free(permname); 132 148 } 149 + free(name); 133 150 } 134 151 135 152 fprintf(fout, "\n#endif\n"); 136 - fclose(fout); 153 + 154 + if (fclose(fout) != 0) { 155 + fprintf(stderr, "Could not successfully close %s: %s\n", 156 + argv[2], strerror(errno)); 157 + exit(6); 158 + } 159 + 137 160 exit(0); 138 161 }
+2 -2
scripts/selinux/mdp/mdp.c
··· 82 82 83 83 /* print out the class permissions */ 84 84 for (i = 0; secclass_map[i].name; i++) { 85 - struct security_class_mapping *map = &secclass_map[i]; 85 + const struct security_class_mapping *map = &secclass_map[i]; 86 86 fprintf(fout, "class %s\n", map->name); 87 87 fprintf(fout, "{\n"); 88 88 for (j = 0; map->perms[j]; j++) ··· 103 103 #define SYSTEMLOW "s0" 104 104 #define SYSTEMHIGH "s1:c0.c1" 105 105 for (i = 0; secclass_map[i].name; i++) { 106 - struct security_class_mapping *map = &secclass_map[i]; 106 + const struct security_class_mapping *map = &secclass_map[i]; 107 107 108 108 fprintf(fout, "mlsconstrain %s {\n", map->name); 109 109 for (j = 0; map->perms[j]; j++)
+3
security/lsm_audit.c
··· 433 433 audit_log_format(ab, " lockdown_reason=\"%s\"", 434 434 lockdown_reasons[a->u.reason]); 435 435 break; 436 + case LSM_AUDIT_DATA_ANONINODE: 437 + audit_log_format(ab, " anonclass=%s", a->u.anonclass); 438 + break; 436 439 } /* switch (a->type) */ 437 440 } 438 441
+1 -1
security/security.c
··· 479 479 * Each LSM has to register its hooks with the infrastructure. 480 480 */ 481 481 void __init security_add_hooks(struct security_hook_list *hooks, int count, 482 - char *lsm) 482 + const char *lsm) 483 483 { 484 484 int i; 485 485
+3 -3
security/selinux/avc.c
··· 668 668 struct common_audit_data *ad = a; 669 669 struct selinux_audit_data *sad = ad->selinux_audit_data; 670 670 u32 av = sad->audited; 671 - const char **perms; 671 + const char *const *perms; 672 672 int i, perm; 673 673 674 674 audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted"); ··· 1059 1059 1060 1060 node = avc_lookup(state->avc, ssid, tsid, tclass); 1061 1061 if (unlikely(!node)) { 1062 - node = avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node); 1062 + avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node); 1063 1063 } else { 1064 1064 memcpy(&avd, &node->ae.avd, sizeof(avd)); 1065 1065 xp_node = node->ae.xp_node; ··· 1151 1151 1152 1152 node = avc_lookup(state->avc, ssid, tsid, tclass); 1153 1153 if (unlikely(!node)) 1154 - node = avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node); 1154 + avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node); 1155 1155 else 1156 1156 memcpy(avd, &node->ae.avd, sizeof(*avd)); 1157 1157
+5 -4
security/selinux/hooks.c
··· 145 145 if (!kstrtoul(str, 0, &checkreqprot)) { 146 146 selinux_checkreqprot_boot = checkreqprot ? 1 : 0; 147 147 if (checkreqprot) 148 - pr_warn("SELinux: checkreqprot set to 1 via kernel parameter. This is deprecated and will be rejected in a future kernel release.\n"); 148 + pr_err("SELinux: checkreqprot set to 1 via kernel parameter. This is deprecated and will be rejected in a future kernel release.\n"); 149 149 } 150 150 return 1; 151 151 } ··· 2964 2964 * allowed to actually create this type of anonymous inode. 2965 2965 */ 2966 2966 2967 - ad.type = LSM_AUDIT_DATA_INODE; 2968 - ad.u.inode = inode; 2967 + ad.type = LSM_AUDIT_DATA_ANONINODE; 2968 + ad.u.anonclass = name ? (const char *)name->name : "?"; 2969 2969 2970 2970 return avc_has_perm(&selinux_state, 2971 2971 tsec->sid, ··· 6487 6487 goto abort_change; 6488 6488 6489 6489 /* Only allow single threaded processes to change context */ 6490 - error = -EPERM; 6491 6490 if (!current_is_single_threaded()) { 6492 6491 error = security_bounded_transition(&selinux_state, 6493 6492 tsec->sid, sid); ··· 7293 7294 7294 7295 memset(&selinux_state, 0, sizeof(selinux_state)); 7295 7296 enforcing_set(&selinux_state, selinux_enforcing_boot); 7297 + if (CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE) 7298 + pr_err("SELinux: CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is non-zero. This is deprecated and will be rejected in a future kernel release.\n"); 7296 7299 checkreqprot_set(&selinux_state, selinux_checkreqprot_boot); 7297 7300 selinux_avc_init(&selinux_state.avc); 7298 7301 mutex_init(&selinux_state.status_lock);
+4 -1
security/selinux/include/audit.h
··· 12 12 #ifndef _SELINUX_AUDIT_H 13 13 #define _SELINUX_AUDIT_H 14 14 15 + #include <linux/audit.h> 16 + #include <linux/types.h> 17 + 15 18 /** 16 19 * selinux_audit_rule_init - alloc/init an selinux audit rule structure. 17 20 * @field: the field this rule refers to ··· 54 51 * @rule: rule to be checked 55 52 * Returns 1 if there are selinux fields specified in the rule, 0 otherwise. 56 53 */ 57 - int selinux_audit_rule_known(struct audit_krule *krule); 54 + int selinux_audit_rule_known(struct audit_krule *rule); 58 55 59 56 #endif /* _SELINUX_AUDIT_H */ 60 57
+1
security/selinux/include/avc.h
··· 104 104 105 105 /** 106 106 * avc_audit - Audit the granting or denial of permissions. 107 + * @state: SELinux state 107 108 * @ssid: source security identifier 108 109 * @tsid: target security identifier 109 110 * @tclass: target security class
+2 -2
security/selinux/include/avc_ss.h
··· 7 7 #ifndef _SELINUX_AVC_SS_H_ 8 8 #define _SELINUX_AVC_SS_H_ 9 9 10 - #include "flask.h" 10 + #include <linux/types.h> 11 11 12 12 struct selinux_avc; 13 13 int avc_ss_reset(struct selinux_avc *avc, u32 seqno); ··· 18 18 const char *perms[sizeof(u32) * 8 + 1]; 19 19 }; 20 20 21 - extern struct security_class_mapping secclass_map[]; 21 + extern const struct security_class_mapping secclass_map[]; 22 22 23 23 #endif /* _SELINUX_AVC_SS_H_ */ 24 24
+1 -1
security/selinux/include/classmap.h
··· 38 38 * Note: The name for any socket class should be suffixed by "socket", 39 39 * and doesn't contain more than one substr of "socket". 40 40 */ 41 - struct security_class_mapping secclass_map[] = { 41 + const struct security_class_mapping secclass_map[] = { 42 42 { "security", 43 43 { "compute_av", "compute_create", "compute_member", 44 44 "check_context", "load_policy", "compute_relabel",
+2
security/selinux/include/ibpkey.h
··· 14 14 #ifndef _SELINUX_IB_PKEY_H 15 15 #define _SELINUX_IB_PKEY_H 16 16 17 + #include <linux/types.h> 18 + 17 19 #ifdef CONFIG_SECURITY_INFINIBAND 18 20 void sel_ib_pkey_flush(void); 19 21 int sel_ib_pkey_sid(u64 subnet_prefix, u16 pkey, u32 *sid);
+1 -2
security/selinux/include/initial_sid_to_string.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - static const char *initial_sid_to_string[] = 3 - { 2 + static const char *const initial_sid_to_string[] = { 4 3 NULL, 5 4 "kernel", 6 5 "security",
+2
security/selinux/include/netnode.h
··· 17 17 #ifndef _SELINUX_NETNODE_H 18 18 #define _SELINUX_NETNODE_H 19 19 20 + #include <linux/types.h> 21 + 20 22 void sel_netnode_flush(void); 21 23 22 24 int sel_netnode_sid(void *addr, u16 family, u32 *sid);
+2
security/selinux/include/netport.h
··· 16 16 #ifndef _SELINUX_NETPORT_H 17 17 #define _SELINUX_NETPORT_H 18 18 19 + #include <linux/types.h> 20 + 19 21 void sel_netport_flush(void); 20 22 21 23 int sel_netport_sid(u8 protocol, u16 pnum, u32 *sid);
+1 -1
security/selinux/include/policycap.h
··· 16 16 }; 17 17 #define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1) 18 18 19 - extern const char *selinux_policycap_names[__POLICYDB_CAP_MAX]; 19 + extern const char *const selinux_policycap_names[__POLICYDB_CAP_MAX]; 20 20 21 21 #endif /* _SELINUX_POLICYCAP_H_ */
+1 -1
security/selinux/include/policycap_names.h
··· 5 5 #include "policycap.h" 6 6 7 7 /* Policy capability names */ 8 - const char *selinux_policycap_names[__POLICYDB_CAP_MAX] = { 8 + const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = { 9 9 "network_peer_controls", 10 10 "open_perms", 11 11 "extended_socket_class",
+4
security/selinux/include/security.h
··· 16 16 #include <linux/rcupdate.h> 17 17 #include <linux/refcount.h> 18 18 #include <linux/workqueue.h> 19 + #include <linux/delay.h> 20 + #include <linux/printk.h> 19 21 #include "flask.h" 20 22 #include "policycap.h" 21 23 ··· 152 150 153 151 static inline void checkreqprot_set(struct selinux_state *state, bool value) 154 152 { 153 + if (value) 154 + pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-checkreqprot\n"); 155 155 WRITE_ONCE(state->checkreqprot, value); 156 156 } 157 157
+2
security/selinux/include/xfrm.h
··· 8 8 #ifndef _SELINUX_XFRM_H_ 9 9 #define _SELINUX_XFRM_H_ 10 10 11 + #include <linux/lsm_audit.h> 11 12 #include <net/flow.h> 13 + #include <net/xfrm.h> 12 14 13 15 int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, 14 16 struct xfrm_user_sec_ctx *uctx,
+4 -8
security/selinux/nlmsgtab.c
··· 25 25 u32 perm; 26 26 }; 27 27 28 - static const struct nlmsg_perm nlmsg_route_perms[] = 29 - { 28 + static const struct nlmsg_perm nlmsg_route_perms[] = { 30 29 { RTM_NEWLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, 31 30 { RTM_DELLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, 32 31 { RTM_GETLINK, NETLINK_ROUTE_SOCKET__NLMSG_READ }, ··· 96 97 { RTM_GETTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_READ }, 97 98 }; 98 99 99 - static const struct nlmsg_perm nlmsg_tcpdiag_perms[] = 100 - { 100 + static const struct nlmsg_perm nlmsg_tcpdiag_perms[] = { 101 101 { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, 102 102 { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, 103 103 { SOCK_DIAG_BY_FAMILY, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, 104 104 { SOCK_DESTROY, NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE }, 105 105 }; 106 106 107 - static const struct nlmsg_perm nlmsg_xfrm_perms[] = 108 - { 107 + static const struct nlmsg_perm nlmsg_xfrm_perms[] = { 109 108 { XFRM_MSG_NEWSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 110 109 { XFRM_MSG_DELSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, 111 110 { XFRM_MSG_GETSA, NETLINK_XFRM_SOCKET__NLMSG_READ }, ··· 131 134 { XFRM_MSG_GETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_READ }, 132 135 }; 133 136 134 - static const struct nlmsg_perm nlmsg_audit_perms[] = 135 - { 137 + static const struct nlmsg_perm nlmsg_audit_perms[] = { 136 138 { AUDIT_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ }, 137 139 { AUDIT_SET, NETLINK_AUDIT_SOCKET__NLMSG_WRITE }, 138 140 { AUDIT_LIST, NETLINK_AUDIT_SOCKET__NLMSG_READPRIV },
+6 -2
security/selinux/selinuxfs.c
··· 293 293 * kernel releases until eventually it is removed 294 294 */ 295 295 pr_err("SELinux: Runtime disable is deprecated, use selinux=0 on the kernel cmdline.\n"); 296 + pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-runtime-disable\n"); 297 + ssleep(5); 296 298 297 299 if (count >= PAGE_SIZE) 298 300 return -ENOMEM; ··· 757 755 char comm[sizeof(current->comm)]; 758 756 759 757 memcpy(comm, current->comm, sizeof(comm)); 760 - pr_warn_once("SELinux: %s (%d) set checkreqprot to 1. This is deprecated and will be rejected in a future kernel release.\n", 761 - comm, current->pid); 758 + pr_err("SELinux: %s (%d) set checkreqprot to 1. This is deprecated and will be rejected in a future kernel release.\n", 759 + comm, current->pid); 762 760 } 763 761 764 762 checkreqprot_set(fsi->state, (new_value ? 1 : 0)); 763 + if (new_value) 764 + ssleep(5); 765 765 length = count; 766 766 767 767 selinux_ima_measure_state(fsi->state);
+10 -10
security/selinux/ss/avtab.c
··· 40 40 41 41 u32 hash = 0; 42 42 43 - #define mix(input) { \ 44 - u32 v = input; \ 45 - v *= c1; \ 46 - v = (v << r1) | (v >> (32 - r1)); \ 47 - v *= c2; \ 48 - hash ^= v; \ 49 - hash = (hash << r2) | (hash >> (32 - r2)); \ 50 - hash = hash * m + n; \ 51 - } 43 + #define mix(input) do { \ 44 + u32 v = input; \ 45 + v *= c1; \ 46 + v = (v << r1) | (v >> (32 - r1)); \ 47 + v *= c2; \ 48 + hash ^= v; \ 49 + hash = (hash << r2) | (hash >> (32 - r2)); \ 50 + hash = hash * m + n; \ 51 + } while (0) 52 52 53 53 mix(keyp->target_class); 54 54 mix(keyp->target_type); ··· 385 385 chain2_len_sum); 386 386 } 387 387 388 - static uint16_t spec_order[] = { 388 + static const uint16_t spec_order[] = { 389 389 AVTAB_ALLOWED, 390 390 AVTAB_AUDITDENY, 391 391 AVTAB_AUDITALLOW,
+15 -21
security/selinux/ss/policydb.c
··· 61 61 }; 62 62 63 63 /* These need to be updated if SYM_NUM or OCON_NUM changes */ 64 - static struct policydb_compat_info policydb_compat[] = { 64 + static const struct policydb_compat_info policydb_compat[] = { 65 65 { 66 66 .version = POLICYDB_VERSION_BASE, 67 67 .sym_num = SYM_NUM - 3, ··· 159 159 }, 160 160 }; 161 161 162 - static struct policydb_compat_info *policydb_lookup_compat(int version) 162 + static const struct policydb_compat_info *policydb_lookup_compat(int version) 163 163 { 164 164 int i; 165 - struct policydb_compat_info *info = NULL; 166 165 167 166 for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) { 168 - if (policydb_compat[i].version == version) { 169 - info = &policydb_compat[i]; 170 - break; 171 - } 167 + if (policydb_compat[i].version == version) 168 + return &policydb_compat[i]; 172 169 } 173 - return info; 170 + 171 + return NULL; 174 172 } 175 173 176 174 /* ··· 312 314 return 0; 313 315 } 314 316 315 - static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) = 316 - { 317 + static int (*const destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 317 318 common_destroy, 318 319 cls_destroy, 319 320 role_destroy, ··· 667 670 return 0; 668 671 } 669 672 670 - static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) = 671 - { 673 + static int (*const index_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 672 674 common_index, 673 675 class_index, 674 676 role_index, ··· 1635 1639 return rc; 1636 1640 } 1637 1641 1638 - static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) = 1639 - { 1642 + static int (*const read_f[SYM_NUM]) (struct policydb *p, 1643 + struct symtab *s, void *fp) = { 1640 1644 common_read, 1641 1645 class_read, 1642 1646 role_read, ··· 2207 2211 return rc; 2208 2212 } 2209 2213 2210 - static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, 2214 + static int ocontext_read(struct policydb *p, const struct policydb_compat_info *info, 2211 2215 void *fp) 2212 2216 { 2213 2217 int i, j, rc; ··· 2403 2407 u32 len, nprim, nel, perm; 2404 2408 2405 2409 char *policydb_str; 2406 - struct policydb_compat_info *info; 2410 + const struct policydb_compat_info *info; 2407 2411 2408 2412 policydb_init(p); 2409 2413 ··· 3237 3241 return 0; 3238 3242 } 3239 3243 3240 - static int (*write_f[SYM_NUM]) (void *key, void *datum, 3241 - void *datap) = 3242 - { 3244 + static int (*const write_f[SYM_NUM]) (void *key, void *datum, void *datap) = { 3243 3245 common_write, 3244 3246 class_write, 3245 3247 role_write, ··· 3248 3254 cat_write, 3249 3255 }; 3250 3256 3251 - static int ocontext_write(struct policydb *p, struct policydb_compat_info *info, 3257 + static int ocontext_write(struct policydb *p, const struct policydb_compat_info *info, 3252 3258 void *fp) 3253 3259 { 3254 3260 unsigned int i, j, rc; ··· 3605 3611 __le32 buf[4]; 3606 3612 u32 config; 3607 3613 size_t len; 3608 - struct policydb_compat_info *info; 3614 + const struct policydb_compat_info *info; 3609 3615 3610 3616 /* 3611 3617 * refuse to write policy older than compressed avtab
+23 -24
security/selinux/ss/services.c
··· 99 99 struct extended_perms *xperms); 100 100 101 101 static int selinux_set_mapping(struct policydb *pol, 102 - struct security_class_mapping *map, 102 + const struct security_class_mapping *map, 103 103 struct selinux_map *out_map) 104 104 { 105 105 u16 i, j; ··· 121 121 /* Store the raw class and permission values */ 122 122 j = 0; 123 123 while (map[j].name) { 124 - struct security_class_mapping *p_in = map + (j++); 124 + const struct security_class_mapping *p_in = map + (j++); 125 125 struct selinux_mapping *p_out = out_map->mapping + j; 126 126 127 127 /* An empty class string skips ahead */ ··· 358 358 l2 = &(tcontext->range.level[1]); 359 359 goto mls_ops; 360 360 mls_ops: 361 - switch (e->op) { 362 - case CEXPR_EQ: 363 - s[++sp] = mls_level_eq(l1, l2); 364 - continue; 365 - case CEXPR_NEQ: 366 - s[++sp] = !mls_level_eq(l1, l2); 367 - continue; 368 - case CEXPR_DOM: 369 - s[++sp] = mls_level_dom(l1, l2); 370 - continue; 371 - case CEXPR_DOMBY: 372 - s[++sp] = mls_level_dom(l2, l1); 373 - continue; 374 - case CEXPR_INCOMP: 375 - s[++sp] = mls_level_incomp(l2, l1); 376 - continue; 377 - default: 378 - BUG(); 379 - return 0; 380 - } 381 - break; 361 + switch (e->op) { 362 + case CEXPR_EQ: 363 + s[++sp] = mls_level_eq(l1, l2); 364 + continue; 365 + case CEXPR_NEQ: 366 + s[++sp] = !mls_level_eq(l1, l2); 367 + continue; 368 + case CEXPR_DOM: 369 + s[++sp] = mls_level_dom(l1, l2); 370 + continue; 371 + case CEXPR_DOMBY: 372 + s[++sp] = mls_level_dom(l2, l1); 373 + continue; 374 + case CEXPR_INCOMP: 375 + s[++sp] = mls_level_incomp(l2, l1); 376 + continue; 377 + default: 378 + BUG(); 379 + return 0; 380 + } 381 + break; 382 382 default: 383 383 BUG(); 384 384 return 0; ··· 2980 2980 } 2981 2981 2982 2982 retry: 2983 - rc = 0; 2984 2983 rcu_read_lock(); 2985 2984 policy = rcu_dereference(state->policy); 2986 2985 policydb = &policy->policydb;