Commit efd1df19 authored by Linus Torvalds's avatar Linus Torvalds

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
parents a6b45057 1af0e4a0
...@@ -76,6 +76,7 @@ struct common_audit_data { ...@@ -76,6 +76,7 @@ struct common_audit_data {
#define LSM_AUDIT_DATA_IBENDPORT 14 #define LSM_AUDIT_DATA_IBENDPORT 14
#define LSM_AUDIT_DATA_LOCKDOWN 15 #define LSM_AUDIT_DATA_LOCKDOWN 15
#define LSM_AUDIT_DATA_NOTIFICATION 16 #define LSM_AUDIT_DATA_NOTIFICATION 16
#define LSM_AUDIT_DATA_ANONINODE 17
union { union {
struct path path; struct path path;
struct dentry *dentry; struct dentry *dentry;
...@@ -96,6 +97,7 @@ struct common_audit_data { ...@@ -96,6 +97,7 @@ struct common_audit_data {
struct lsm_ibpkey_audit *ibpkey; struct lsm_ibpkey_audit *ibpkey;
struct lsm_ibendport_audit *ibendport; struct lsm_ibendport_audit *ibendport;
int reason; int reason;
const char *anonclass;
} u; } u;
/* this union contains LSM specific data */ /* this union contains LSM specific data */
union { union {
......
...@@ -1595,7 +1595,7 @@ struct security_hook_list { ...@@ -1595,7 +1595,7 @@ struct security_hook_list {
struct hlist_node list; struct hlist_node list;
struct hlist_head *head; struct hlist_head *head;
union security_list_options hook; union security_list_options hook;
char *lsm; const char *lsm;
} __randomize_layout; } __randomize_layout;
/* /*
...@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads; ...@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
extern char *lsm_names; extern char *lsm_names;
extern void security_add_hooks(struct security_hook_list *hooks, int count, extern void security_add_hooks(struct security_hook_list *hooks, int count,
char *lsm); const char *lsm);
#define LSM_FLAG_LEGACY_MAJOR BIT(0) #define LSM_FLAG_LEGACY_MAJOR BIT(0)
#define LSM_FLAG_EXCLUSIVE BIT(1) #define LSM_FLAG_EXCLUSIVE BIT(1)
......
...@@ -59,35 +59,27 @@ int main(int argc, char *argv[]) ...@@ -59,35 +59,27 @@ int main(int argc, char *argv[])
exit(2); exit(2);
} }
for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i];
map->name = stoupperx(map->name);
for (j = 0; map->perms[j]; j++)
map->perms[j] = stoupperx(map->perms[j]);
}
isids_len = sizeof(initial_sid_to_string) / sizeof (char *);
for (i = 1; i < isids_len; i++) {
const char *s = initial_sid_to_string[i];
if (s)
initial_sid_to_string[i] = stoupperx(s);
}
fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n"); fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n");
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; char *name = stoupperx(secclass_map[i].name);
fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1);
fprintf(fout, "#define SECCLASS_%-39s %2d\n", name, i+1);
free(name);
} }
fprintf(fout, "\n"); fprintf(fout, "\n");
isids_len = sizeof(initial_sid_to_string) / sizeof(char *);
for (i = 1; i < isids_len; i++) { for (i = 1; i < isids_len; i++) {
const char *s = initial_sid_to_string[i]; const char *s = initial_sid_to_string[i];
if (s) if (s) {
fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i); char *sidname = stoupperx(s);
fprintf(fout, "#define SECINITSID_%-39s %2d\n", sidname, i);
free(sidname);
}
} }
fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
...@@ -96,10 +88,14 @@ int main(int argc, char *argv[]) ...@@ -96,10 +88,14 @@ int main(int argc, char *argv[])
fprintf(fout, "\tswitch (kern_tclass) {\n"); fprintf(fout, "\tswitch (kern_tclass) {\n");
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
static char s[] = "SOCKET"; static char s[] = "SOCKET";
struct security_class_mapping *map = &secclass_map[i]; int len, l;
int len = strlen(map->name), l = sizeof(s) - 1; char *name = stoupperx(secclass_map[i].name);
if (len >= l && memcmp(map->name + len - l, s, l) == 0)
fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); len = strlen(name);
l = sizeof(s) - 1;
if (len >= l && memcmp(name + len - l, s, l) == 0)
fprintf(fout, "\tcase SECCLASS_%s:\n", name);
free(name);
} }
fprintf(fout, "\t\tsock = true;\n"); fprintf(fout, "\t\tsock = true;\n");
fprintf(fout, "\t\tbreak;\n"); fprintf(fout, "\t\tbreak;\n");
...@@ -110,33 +106,52 @@ int main(int argc, char *argv[]) ...@@ -110,33 +106,52 @@ int main(int argc, char *argv[])
fprintf(fout, "}\n"); fprintf(fout, "}\n");
fprintf(fout, "\n#endif\n"); fprintf(fout, "\n#endif\n");
fclose(fout);
if (fclose(fout) != 0) {
fprintf(stderr, "Could not successfully close %s: %s\n",
argv[1], strerror(errno));
exit(4);
}
fout = fopen(argv[2], "w"); fout = fopen(argv[2], "w");
if (!fout) { if (!fout) {
fprintf(stderr, "Could not open %s for writing: %s\n", fprintf(stderr, "Could not open %s for writing: %s\n",
argv[2], strerror(errno)); argv[2], strerror(errno));
exit(4); exit(5);
} }
fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n"); fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n");
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; const struct security_class_mapping *map = &secclass_map[i];
int len = strlen(map->name); int len;
char *name = stoupperx(map->name);
len = strlen(name);
for (j = 0; map->perms[j]; j++) { for (j = 0; map->perms[j]; j++) {
char *permname;
if (j >= 32) { if (j >= 32) {
fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n",
map->name, map->perms[j]); map->name, map->perms[j]);
exit(5); exit(5);
} }
fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name, permname = stoupperx(map->perms[j]);
39-len, map->perms[j], 1U<<j); fprintf(fout, "#define %s__%-*s 0x%08xU\n", name,
39-len, permname, 1U<<j);
free(permname);
} }
free(name);
} }
fprintf(fout, "\n#endif\n"); fprintf(fout, "\n#endif\n");
fclose(fout);
if (fclose(fout) != 0) {
fprintf(stderr, "Could not successfully close %s: %s\n",
argv[2], strerror(errno));
exit(6);
}
exit(0); exit(0);
} }
...@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) ...@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
/* print out the class permissions */ /* print out the class permissions */
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; const struct security_class_mapping *map = &secclass_map[i];
fprintf(fout, "class %s\n", map->name); fprintf(fout, "class %s\n", map->name);
fprintf(fout, "{\n"); fprintf(fout, "{\n");
for (j = 0; map->perms[j]; j++) for (j = 0; map->perms[j]; j++)
...@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) ...@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
#define SYSTEMLOW "s0" #define SYSTEMLOW "s0"
#define SYSTEMHIGH "s1:c0.c1" #define SYSTEMHIGH "s1:c0.c1"
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; const struct security_class_mapping *map = &secclass_map[i];
fprintf(fout, "mlsconstrain %s {\n", map->name); fprintf(fout, "mlsconstrain %s {\n", map->name);
for (j = 0; map->perms[j]; j++) for (j = 0; map->perms[j]; j++)
......
...@@ -433,6 +433,9 @@ static void dump_common_audit_data(struct audit_buffer *ab, ...@@ -433,6 +433,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
audit_log_format(ab, " lockdown_reason=\"%s\"", audit_log_format(ab, " lockdown_reason=\"%s\"",
lockdown_reasons[a->u.reason]); lockdown_reasons[a->u.reason]);
break; break;
case LSM_AUDIT_DATA_ANONINODE:
audit_log_format(ab, " anonclass=%s", a->u.anonclass);
break;
} /* switch (a->type) */ } /* switch (a->type) */
} }
......
...@@ -479,7 +479,7 @@ static int lsm_append(const char *new, char **result) ...@@ -479,7 +479,7 @@ static int lsm_append(const char *new, char **result)
* Each LSM has to register its hooks with the infrastructure. * Each LSM has to register its hooks with the infrastructure.
*/ */
void __init security_add_hooks(struct security_hook_list *hooks, int count, void __init security_add_hooks(struct security_hook_list *hooks, int count,
char *lsm) const char *lsm)
{ {
int i; int i;
......
...@@ -668,7 +668,7 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a) ...@@ -668,7 +668,7 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
struct common_audit_data *ad = a; struct common_audit_data *ad = a;
struct selinux_audit_data *sad = ad->selinux_audit_data; struct selinux_audit_data *sad = ad->selinux_audit_data;
u32 av = sad->audited; u32 av = sad->audited;
const char **perms; const char *const *perms;
int i, perm; int i, perm;
audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted"); audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted");
...@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state, ...@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
node = avc_lookup(state->avc, ssid, tsid, tclass); node = avc_lookup(state->avc, ssid, tsid, tclass);
if (unlikely(!node)) { if (unlikely(!node)) {
node = avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node); avc_compute_av(state, ssid, tsid, tclass, &avd, xp_node);
} else { } else {
memcpy(&avd, &node->ae.avd, sizeof(avd)); memcpy(&avd, &node->ae.avd, sizeof(avd));
xp_node = node->ae.xp_node; xp_node = node->ae.xp_node;
...@@ -1151,7 +1151,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state, ...@@ -1151,7 +1151,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
node = avc_lookup(state->avc, ssid, tsid, tclass); node = avc_lookup(state->avc, ssid, tsid, tclass);
if (unlikely(!node)) if (unlikely(!node))
node = avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node); avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node);
else else
memcpy(avd, &node->ae.avd, sizeof(*avd)); memcpy(avd, &node->ae.avd, sizeof(*avd));
......
...@@ -145,7 +145,7 @@ static int __init checkreqprot_setup(char *str) ...@@ -145,7 +145,7 @@ static int __init checkreqprot_setup(char *str)
if (!kstrtoul(str, 0, &checkreqprot)) { if (!kstrtoul(str, 0, &checkreqprot)) {
selinux_checkreqprot_boot = checkreqprot ? 1 : 0; selinux_checkreqprot_boot = checkreqprot ? 1 : 0;
if (checkreqprot) if (checkreqprot)
pr_warn("SELinux: checkreqprot set to 1 via kernel parameter. This is deprecated and will be rejected in a future kernel release.\n"); pr_err("SELinux: checkreqprot set to 1 via kernel parameter. This is deprecated and will be rejected in a future kernel release.\n");
} }
return 1; return 1;
} }
...@@ -2964,8 +2964,8 @@ static int selinux_inode_init_security_anon(struct inode *inode, ...@@ -2964,8 +2964,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,
* allowed to actually create this type of anonymous inode. * allowed to actually create this type of anonymous inode.
*/ */
ad.type = LSM_AUDIT_DATA_INODE; ad.type = LSM_AUDIT_DATA_ANONINODE;
ad.u.inode = inode; ad.u.anonclass = name ? (const char *)name->name : "?";
return avc_has_perm(&selinux_state, return avc_has_perm(&selinux_state,
tsec->sid, tsec->sid,
...@@ -6487,7 +6487,6 @@ static int selinux_setprocattr(const char *name, void *value, size_t size) ...@@ -6487,7 +6487,6 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
goto abort_change; goto abort_change;
/* Only allow single threaded processes to change context */ /* Only allow single threaded processes to change context */
error = -EPERM;
if (!current_is_single_threaded()) { if (!current_is_single_threaded()) {
error = security_bounded_transition(&selinux_state, error = security_bounded_transition(&selinux_state,
tsec->sid, sid); tsec->sid, sid);
...@@ -7294,6 +7293,8 @@ static __init int selinux_init(void) ...@@ -7294,6 +7293,8 @@ static __init int selinux_init(void)
memset(&selinux_state, 0, sizeof(selinux_state)); memset(&selinux_state, 0, sizeof(selinux_state));
enforcing_set(&selinux_state, selinux_enforcing_boot); enforcing_set(&selinux_state, selinux_enforcing_boot);
if (CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE)
pr_err("SELinux: CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is non-zero. This is deprecated and will be rejected in a future kernel release.\n");
checkreqprot_set(&selinux_state, selinux_checkreqprot_boot); checkreqprot_set(&selinux_state, selinux_checkreqprot_boot);
selinux_avc_init(&selinux_state.avc); selinux_avc_init(&selinux_state.avc);
mutex_init(&selinux_state.status_lock); mutex_init(&selinux_state.status_lock);
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#ifndef _SELINUX_AUDIT_H #ifndef _SELINUX_AUDIT_H
#define _SELINUX_AUDIT_H #define _SELINUX_AUDIT_H
#include <linux/audit.h>
#include <linux/types.h>
/** /**
* selinux_audit_rule_init - alloc/init an selinux audit rule structure. * selinux_audit_rule_init - alloc/init an selinux audit rule structure.
* @field: the field this rule refers to * @field: the field this rule refers to
...@@ -51,7 +54,7 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule); ...@@ -51,7 +54,7 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule);
* @rule: rule to be checked * @rule: rule to be checked
* Returns 1 if there are selinux fields specified in the rule, 0 otherwise. * Returns 1 if there are selinux fields specified in the rule, 0 otherwise.
*/ */
int selinux_audit_rule_known(struct audit_krule *krule); int selinux_audit_rule_known(struct audit_krule *rule);
#endif /* _SELINUX_AUDIT_H */ #endif /* _SELINUX_AUDIT_H */
...@@ -104,6 +104,7 @@ int slow_avc_audit(struct selinux_state *state, ...@@ -104,6 +104,7 @@ int slow_avc_audit(struct selinux_state *state,
/** /**
* avc_audit - Audit the granting or denial of permissions. * avc_audit - Audit the granting or denial of permissions.
* @state: SELinux state
* @ssid: source security identifier * @ssid: source security identifier
* @tsid: target security identifier * @tsid: target security identifier
* @tclass: target security class * @tclass: target security class
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef _SELINUX_AVC_SS_H_ #ifndef _SELINUX_AVC_SS_H_
#define _SELINUX_AVC_SS_H_ #define _SELINUX_AVC_SS_H_
#include "flask.h" #include <linux/types.h>
struct selinux_avc; struct selinux_avc;
int avc_ss_reset(struct selinux_avc *avc, u32 seqno); int avc_ss_reset(struct selinux_avc *avc, u32 seqno);
...@@ -18,7 +18,7 @@ struct security_class_mapping { ...@@ -18,7 +18,7 @@ struct security_class_mapping {
const char *perms[sizeof(u32) * 8 + 1]; const char *perms[sizeof(u32) * 8 + 1];
}; };
extern struct security_class_mapping secclass_map[]; extern const struct security_class_mapping secclass_map[];
#endif /* _SELINUX_AVC_SS_H_ */ #endif /* _SELINUX_AVC_SS_H_ */
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
* Note: The name for any socket class should be suffixed by "socket", * Note: The name for any socket class should be suffixed by "socket",
* and doesn't contain more than one substr of "socket". * and doesn't contain more than one substr of "socket".
*/ */
struct security_class_mapping secclass_map[] = { const struct security_class_mapping secclass_map[] = {
{ "security", { "security",
{ "compute_av", "compute_create", "compute_member", { "compute_av", "compute_create", "compute_member",
"check_context", "load_policy", "compute_relabel", "check_context", "load_policy", "compute_relabel",
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#ifndef _SELINUX_IB_PKEY_H #ifndef _SELINUX_IB_PKEY_H
#define _SELINUX_IB_PKEY_H #define _SELINUX_IB_PKEY_H
#include <linux/types.h>
#ifdef CONFIG_SECURITY_INFINIBAND #ifdef CONFIG_SECURITY_INFINIBAND
void sel_ib_pkey_flush(void); void sel_ib_pkey_flush(void);
int sel_ib_pkey_sid(u64 subnet_prefix, u16 pkey, u32 *sid); int sel_ib_pkey_sid(u64 subnet_prefix, u16 pkey, u32 *sid);
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
static const char *initial_sid_to_string[] = static const char *const initial_sid_to_string[] = {
{
NULL, NULL,
"kernel", "kernel",
"security", "security",
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#ifndef _SELINUX_NETNODE_H #ifndef _SELINUX_NETNODE_H
#define _SELINUX_NETNODE_H #define _SELINUX_NETNODE_H
#include <linux/types.h>
void sel_netnode_flush(void); void sel_netnode_flush(void);
int sel_netnode_sid(void *addr, u16 family, u32 *sid); int sel_netnode_sid(void *addr, u16 family, u32 *sid);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef _SELINUX_NETPORT_H #ifndef _SELINUX_NETPORT_H
#define _SELINUX_NETPORT_H #define _SELINUX_NETPORT_H
#include <linux/types.h>
void sel_netport_flush(void); void sel_netport_flush(void);
int sel_netport_sid(u8 protocol, u16 pnum, u32 *sid); int sel_netport_sid(u8 protocol, u16 pnum, u32 *sid);
......
...@@ -16,6 +16,6 @@ enum { ...@@ -16,6 +16,6 @@ enum {
}; };
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1) #define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
extern const char *selinux_policycap_names[__POLICYDB_CAP_MAX]; extern const char *const selinux_policycap_names[__POLICYDB_CAP_MAX];
#endif /* _SELINUX_POLICYCAP_H_ */ #endif /* _SELINUX_POLICYCAP_H_ */
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "policycap.h" #include "policycap.h"
/* Policy capability names */ /* Policy capability names */
const char *selinux_policycap_names[__POLICYDB_CAP_MAX] = { const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = {
"network_peer_controls", "network_peer_controls",
"open_perms", "open_perms",
"extended_socket_class", "extended_socket_class",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/delay.h>
#include <linux/printk.h>
#include "flask.h" #include "flask.h"
#include "policycap.h" #include "policycap.h"
...@@ -150,6 +152,8 @@ static inline bool checkreqprot_get(const struct selinux_state *state) ...@@ -150,6 +152,8 @@ static inline bool checkreqprot_get(const struct selinux_state *state)
static inline void checkreqprot_set(struct selinux_state *state, bool value) static inline void checkreqprot_set(struct selinux_state *state, bool value)
{ {
if (value)
pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-checkreqprot\n");
WRITE_ONCE(state->checkreqprot, value); WRITE_ONCE(state->checkreqprot, value);
} }
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#ifndef _SELINUX_XFRM_H_ #ifndef _SELINUX_XFRM_H_
#define _SELINUX_XFRM_H_ #define _SELINUX_XFRM_H_
#include <linux/lsm_audit.h>
#include <net/flow.h> #include <net/flow.h>
#include <net/xfrm.h>
int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
struct xfrm_user_sec_ctx *uctx, struct xfrm_user_sec_ctx *uctx,
......
...@@ -25,8 +25,7 @@ struct nlmsg_perm { ...@@ -25,8 +25,7 @@ struct nlmsg_perm {
u32 perm; u32 perm;
}; };
static const struct nlmsg_perm nlmsg_route_perms[] = static const struct nlmsg_perm nlmsg_route_perms[] = {
{
{ RTM_NEWLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_NEWLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
{ RTM_DELLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_DELLINK, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
{ RTM_GETLINK, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETLINK, NETLINK_ROUTE_SOCKET__NLMSG_READ },
...@@ -97,16 +96,14 @@ static const struct nlmsg_perm nlmsg_route_perms[] = ...@@ -97,16 +96,14 @@ static const struct nlmsg_perm nlmsg_route_perms[] =
{ RTM_GETTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_READ },
}; };
static const struct nlmsg_perm nlmsg_tcpdiag_perms[] = static const struct nlmsg_perm nlmsg_tcpdiag_perms[] = {
{
{ TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, { TCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
{ DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, { DCCPDIAG_GETSOCK, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
{ SOCK_DIAG_BY_FAMILY, NETLINK_TCPDIAG_SOCKET__NLMSG_READ }, { SOCK_DIAG_BY_FAMILY, NETLINK_TCPDIAG_SOCKET__NLMSG_READ },
{ SOCK_DESTROY, NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE }, { SOCK_DESTROY, NETLINK_TCPDIAG_SOCKET__NLMSG_WRITE },
}; };
static const struct nlmsg_perm nlmsg_xfrm_perms[] = static const struct nlmsg_perm nlmsg_xfrm_perms[] = {
{
{ XFRM_MSG_NEWSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, { XFRM_MSG_NEWSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
{ XFRM_MSG_DELSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, { XFRM_MSG_DELSA, NETLINK_XFRM_SOCKET__NLMSG_WRITE },
{ XFRM_MSG_GETSA, NETLINK_XFRM_SOCKET__NLMSG_READ }, { XFRM_MSG_GETSA, NETLINK_XFRM_SOCKET__NLMSG_READ },
...@@ -134,8 +131,7 @@ static const struct nlmsg_perm nlmsg_xfrm_perms[] = ...@@ -134,8 +131,7 @@ static const struct nlmsg_perm nlmsg_xfrm_perms[] =
{ XFRM_MSG_GETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_READ }, { XFRM_MSG_GETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_READ },
}; };
static const struct nlmsg_perm nlmsg_audit_perms[] = static const struct nlmsg_perm nlmsg_audit_perms[] = {
{
{ AUDIT_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ }, { AUDIT_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ },
{ AUDIT_SET, NETLINK_AUDIT_SOCKET__NLMSG_WRITE }, { AUDIT_SET, NETLINK_AUDIT_SOCKET__NLMSG_WRITE },
{ AUDIT_LIST, NETLINK_AUDIT_SOCKET__NLMSG_READPRIV }, { AUDIT_LIST, NETLINK_AUDIT_SOCKET__NLMSG_READPRIV },
......
...@@ -293,6 +293,8 @@ static ssize_t sel_write_disable(struct file *file, const char __user *buf, ...@@ -293,6 +293,8 @@ static ssize_t sel_write_disable(struct file *file, const char __user *buf,
* kernel releases until eventually it is removed * kernel releases until eventually it is removed
*/ */
pr_err("SELinux: Runtime disable is deprecated, use selinux=0 on the kernel cmdline.\n"); pr_err("SELinux: Runtime disable is deprecated, use selinux=0 on the kernel cmdline.\n");
pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-runtime-disable\n");
ssleep(5);
if (count >= PAGE_SIZE) if (count >= PAGE_SIZE)
return -ENOMEM; return -ENOMEM;
...@@ -755,11 +757,13 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf, ...@@ -755,11 +757,13 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
char comm[sizeof(current->comm)]; char comm[sizeof(current->comm)];
memcpy(comm, current->comm, sizeof(comm)); memcpy(comm, current->comm, sizeof(comm));
pr_warn_once("SELinux: %s (%d) set checkreqprot to 1. This is deprecated and will be rejected in a future kernel release.\n", pr_err("SELinux: %s (%d) set checkreqprot to 1. This is deprecated and will be rejected in a future kernel release.\n",
comm, current->pid); comm, current->pid);
} }
checkreqprot_set(fsi->state, (new_value ? 1 : 0)); checkreqprot_set(fsi->state, (new_value ? 1 : 0));
if (new_value)
ssleep(5);
length = count; length = count;
selinux_ima_measure_state(fsi->state); selinux_ima_measure_state(fsi->state);
......
...@@ -40,7 +40,7 @@ static inline int avtab_hash(const struct avtab_key *keyp, u32 mask) ...@@ -40,7 +40,7 @@ static inline int avtab_hash(const struct avtab_key *keyp, u32 mask)
u32 hash = 0; u32 hash = 0;
#define mix(input) { \ #define mix(input) do { \
u32 v = input; \ u32 v = input; \
v *= c1; \ v *= c1; \
v = (v << r1) | (v >> (32 - r1)); \ v = (v << r1) | (v >> (32 - r1)); \
...@@ -48,7 +48,7 @@ static inline int avtab_hash(const struct avtab_key *keyp, u32 mask) ...@@ -48,7 +48,7 @@ static inline int avtab_hash(const struct avtab_key *keyp, u32 mask)
hash ^= v; \ hash ^= v; \
hash = (hash << r2) | (hash >> (32 - r2)); \ hash = (hash << r2) | (hash >> (32 - r2)); \
hash = hash * m + n; \ hash = hash * m + n; \
} } while (0)
mix(keyp->target_class); mix(keyp->target_class);
mix(keyp->target_type); mix(keyp->target_type);
...@@ -385,7 +385,7 @@ void avtab_hash_eval(struct avtab *h, char *tag) ...@@ -385,7 +385,7 @@ void avtab_hash_eval(struct avtab *h, char *tag)
chain2_len_sum); chain2_len_sum);
} }
static uint16_t spec_order[] = { static const uint16_t spec_order[] = {
AVTAB_ALLOWED, AVTAB_ALLOWED,
AVTAB_AUDITDENY, AVTAB_AUDITDENY,
AVTAB_AUDITALLOW, AVTAB_AUDITALLOW,
......
...@@ -61,7 +61,7 @@ struct policydb_compat_info { ...@@ -61,7 +61,7 @@ struct policydb_compat_info {
}; };
/* These need to be updated if SYM_NUM or OCON_NUM changes */ /* These need to be updated if SYM_NUM or OCON_NUM changes */
static struct policydb_compat_info policydb_compat[] = { static const struct policydb_compat_info policydb_compat[] = {
{ {
.version = POLICYDB_VERSION_BASE, .version = POLICYDB_VERSION_BASE,
.sym_num = SYM_NUM - 3, .sym_num = SYM_NUM - 3,
...@@ -159,18 +159,16 @@ static struct policydb_compat_info policydb_compat[] = { ...@@ -159,18 +159,16 @@ static struct policydb_compat_info policydb_compat[] = {
}, },
}; };
static struct policydb_compat_info *policydb_lookup_compat(int version) static const struct policydb_compat_info *policydb_lookup_compat(int version)
{ {
int i; int i;
struct policydb_compat_info *info = NULL;
for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) { for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) {
if (policydb_compat[i].version == version) { if (policydb_compat[i].version == version)
info = &policydb_compat[i]; return &policydb_compat[i];
break;
}
} }
return info;
return NULL;
} }
/* /*
...@@ -314,8 +312,7 @@ static int cat_destroy(void *key, void *datum, void *p) ...@@ -314,8 +312,7 @@ static int cat_destroy(void *key, void *datum, void *p)
return 0; return 0;
} }
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) = static int (*const destroy_f[SYM_NUM]) (void *key, void *datum, void *datap) = {
{
common_destroy, common_destroy,
cls_destroy, cls_destroy,
role_destroy, role_destroy,
...@@ -670,8 +667,7 @@ static int cat_index(void *key, void *datum, void *datap) ...@@ -670,8 +667,7 @@ static int cat_index(void *key, void *datum, void *datap)
return 0; return 0;
} }
static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) = static int (*const index_f[SYM_NUM]) (void *key, void *datum, void *datap) = {
{
common_index, common_index,
class_index, class_index,
role_index, role_index,
...@@ -1639,8 +1635,8 @@ static int cat_read(struct policydb *p, struct symtab *s, void *fp) ...@@ -1639,8 +1635,8 @@ static int cat_read(struct policydb *p, struct symtab *s, void *fp)
return rc; return rc;
} }
static int (*read_f[SYM_NUM]) (struct policydb *p, struct symtab *s, void *fp) = static int (*const read_f[SYM_NUM]) (struct policydb *p,
{ struct symtab *s, void *fp) = {
common_read, common_read,
class_read, class_read,
role_read, role_read,
...@@ -2211,7 +2207,7 @@ static int genfs_read(struct policydb *p, void *fp) ...@@ -2211,7 +2207,7 @@ static int genfs_read(struct policydb *p, void *fp)
return rc; return rc;
} }
static int ocontext_read(struct policydb *p, struct policydb_compat_info *info, static int ocontext_read(struct policydb *p, const struct policydb_compat_info *info,
void *fp) void *fp)
{ {
int i, j, rc; int i, j, rc;
...@@ -2407,7 +2403,7 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -2407,7 +2403,7 @@ int policydb_read(struct policydb *p, void *fp)
u32 len, nprim, nel, perm; u32 len, nprim, nel, perm;
char *policydb_str; char *policydb_str;
struct policydb_compat_info *info; const struct policydb_compat_info *info;
policydb_init(p); policydb_init(p);
...@@ -3241,9 +3237,7 @@ static int user_write(void *vkey, void *datum, void *ptr) ...@@ -3241,9 +3237,7 @@ static int user_write(void *vkey, void *datum, void *ptr)
return 0; return 0;
} }
static int (*write_f[SYM_NUM]) (void *key, void *datum, static int (*const write_f[SYM_NUM]) (void *key, void *datum, void *datap) = {
void *datap) =
{
common_write, common_write,
class_write, class_write,
role_write, role_write,
...@@ -3254,7 +3248,7 @@ static int (*write_f[SYM_NUM]) (void *key, void *datum, ...@@ -3254,7 +3248,7 @@ static int (*write_f[SYM_NUM]) (void *key, void *datum,
cat_write, cat_write,
}; };
static int ocontext_write(struct policydb *p, struct policydb_compat_info *info, static int ocontext_write(struct policydb *p, const struct policydb_compat_info *info,
void *fp) void *fp)
{ {
unsigned int i, j, rc; unsigned int i, j, rc;
...@@ -3611,7 +3605,7 @@ int policydb_write(struct policydb *p, void *fp) ...@@ -3611,7 +3605,7 @@ int policydb_write(struct policydb *p, void *fp)
__le32 buf[4]; __le32 buf[4];
u32 config; u32 config;
size_t len; size_t len;
struct policydb_compat_info *info; const struct policydb_compat_info *info;
/* /*
* refuse to write policy older than compressed avtab * refuse to write policy older than compressed avtab
......
...@@ -99,7 +99,7 @@ static void context_struct_compute_av(struct policydb *policydb, ...@@ -99,7 +99,7 @@ static void context_struct_compute_av(struct policydb *policydb,
struct extended_perms *xperms); struct extended_perms *xperms);
static int selinux_set_mapping(struct policydb *pol, static int selinux_set_mapping(struct policydb *pol,
struct security_class_mapping *map, const struct security_class_mapping *map,
struct selinux_map *out_map) struct selinux_map *out_map)
{ {
u16 i, j; u16 i, j;
...@@ -121,7 +121,7 @@ static int selinux_set_mapping(struct policydb *pol, ...@@ -121,7 +121,7 @@ static int selinux_set_mapping(struct policydb *pol,
/* Store the raw class and permission values */ /* Store the raw class and permission values */
j = 0; j = 0;
while (map[j].name) { while (map[j].name) {
struct security_class_mapping *p_in = map + (j++); const struct security_class_mapping *p_in = map + (j++);
struct selinux_mapping *p_out = out_map->mapping + j; struct selinux_mapping *p_out = out_map->mapping + j;
/* An empty class string skips ahead */ /* An empty class string skips ahead */
...@@ -2980,7 +2980,6 @@ int security_fs_use(struct selinux_state *state, struct super_block *sb) ...@@ -2980,7 +2980,6 @@ int security_fs_use(struct selinux_state *state, struct super_block *sb)
} }
retry: retry:
rc = 0;
rcu_read_lock(); rcu_read_lock();
policy = rcu_dereference(state->policy); policy = rcu_dereference(state->policy);
policydb = &policy->policydb; policydb = &policy->policydb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment