Skip to content

Commit efd1df1

Browse files
committed
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
2 parents a6b4505 + 1af0e4a commit efd1df1

25 files changed

Lines changed: 144 additions & 115 deletions

include/linux/lsm_audit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct common_audit_data {
7676
#define LSM_AUDIT_DATA_IBENDPORT 14
7777
#define LSM_AUDIT_DATA_LOCKDOWN 15
7878
#define LSM_AUDIT_DATA_NOTIFICATION 16
79+
#define LSM_AUDIT_DATA_ANONINODE 17
7980
union {
8081
struct path path;
8182
struct dentry *dentry;
@@ -96,6 +97,7 @@ struct common_audit_data {
9697
struct lsm_ibpkey_audit *ibpkey;
9798
struct lsm_ibendport_audit *ibendport;
9899
int reason;
100+
const char *anonclass;
99101
} u;
100102
/* this union contains LSM specific data */
101103
union {

include/linux/lsm_hooks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ struct security_hook_list {
15951595
struct hlist_node list;
15961596
struct hlist_head *head;
15971597
union security_list_options hook;
1598-
char *lsm;
1598+
const char *lsm;
15991599
} __randomize_layout;
16001600

16011601
/*
@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
16301630
extern char *lsm_names;
16311631

16321632
extern void security_add_hooks(struct security_hook_list *hooks, int count,
1633-
char *lsm);
1633+
const char *lsm);
16341634

16351635
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
16361636
#define LSM_FLAG_EXCLUSIVE BIT(1)

scripts/selinux/genheaders/genheaders.c

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,27 @@ int main(int argc, char *argv[])
5959
exit(2);
6060
}
6161

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-
7762
fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
7863
fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n");
7964

8065
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);
8370
}
8471

8572
fprintf(fout, "\n");
8673

74+
isids_len = sizeof(initial_sid_to_string) / sizeof(char *);
8775
for (i = 1; i < isids_len; i++) {
8876
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+
}
9183
}
9284
fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
9385
fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
@@ -96,10 +88,14 @@ int main(int argc, char *argv[])
9688
fprintf(fout, "\tswitch (kern_tclass) {\n");
9789
for (i = 0; secclass_map[i].name; i++) {
9890
static char s[] = "SOCKET";
99-
struct security_class_mapping *map = &secclass_map[i];
100-
int len = strlen(map->name), l = sizeof(s) - 1;
101-
if (len >= l && memcmp(map->name + len - l, s, l) == 0)
102-
fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
91+
int len, l;
92+
char *name = stoupperx(secclass_map[i].name);
93+
94+
len = strlen(name);
95+
l = sizeof(s) - 1;
96+
if (len >= l && memcmp(name + len - l, s, l) == 0)
97+
fprintf(fout, "\tcase SECCLASS_%s:\n", name);
98+
free(name);
10399
}
104100
fprintf(fout, "\t\tsock = true;\n");
105101
fprintf(fout, "\t\tbreak;\n");
@@ -110,33 +106,52 @@ int main(int argc, char *argv[])
110106
fprintf(fout, "}\n");
111107

112108
fprintf(fout, "\n#endif\n");
113-
fclose(fout);
109+
110+
if (fclose(fout) != 0) {
111+
fprintf(stderr, "Could not successfully close %s: %s\n",
112+
argv[1], strerror(errno));
113+
exit(4);
114+
}
114115

115116
fout = fopen(argv[2], "w");
116117
if (!fout) {
117118
fprintf(stderr, "Could not open %s for writing: %s\n",
118119
argv[2], strerror(errno));
119-
exit(4);
120+
exit(5);
120121
}
121122

122123
fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
123124
fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n");
124125

125126
for (i = 0; secclass_map[i].name; i++) {
126-
struct security_class_mapping *map = &secclass_map[i];
127-
int len = strlen(map->name);
127+
const struct security_class_mapping *map = &secclass_map[i];
128+
int len;
129+
char *name = stoupperx(map->name);
130+
131+
len = strlen(name);
128132
for (j = 0; map->perms[j]; j++) {
133+
char *permname;
134+
129135
if (j >= 32) {
130136
fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n",
131137
map->name, map->perms[j]);
132138
exit(5);
133139
}
134-
fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name,
135-
39-len, map->perms[j], 1U<<j);
140+
permname = stoupperx(map->perms[j]);
141+
fprintf(fout, "#define %s__%-*s 0x%08xU\n", name,
142+
39-len, permname, 1U<<j);
143+
free(permname);
136144
}
145+
free(name);
137146
}
138147

139148
fprintf(fout, "\n#endif\n");
140-
fclose(fout);
149+
150+
if (fclose(fout) != 0) {
151+
fprintf(stderr, "Could not successfully close %s: %s\n",
152+
argv[2], strerror(errno));
153+
exit(6);
154+
}
155+
141156
exit(0);
142157
}

scripts/selinux/mdp/mdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
8282

8383
/* print out the class permissions */
8484
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];
8686
fprintf(fout, "class %s\n", map->name);
8787
fprintf(fout, "{\n");
8888
for (j = 0; map->perms[j]; j++)
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
103103
#define SYSTEMLOW "s0"
104104
#define SYSTEMHIGH "s1:c0.c1"
105105
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];
107107

108108
fprintf(fout, "mlsconstrain %s {\n", map->name);
109109
for (j = 0; map->perms[j]; j++)

security/lsm_audit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
433433
audit_log_format(ab, " lockdown_reason=\"%s\"",
434434
lockdown_reasons[a->u.reason]);
435435
break;
436+
case LSM_AUDIT_DATA_ANONINODE:
437+
audit_log_format(ab, " anonclass=%s", a->u.anonclass);
438+
break;
436439
} /* switch (a->type) */
437440
}
438441

security/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int lsm_append(const char *new, char **result)
479479
* Each LSM has to register its hooks with the infrastructure.
480480
*/
481481
void __init security_add_hooks(struct security_hook_list *hooks, int count,
482-
char *lsm)
482+
const char *lsm)
483483
{
484484
int i;
485485

security/selinux/avc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
668668
struct common_audit_data *ad = a;
669669
struct selinux_audit_data *sad = ad->selinux_audit_data;
670670
u32 av = sad->audited;
671-
const char **perms;
671+
const char *const *perms;
672672
int i, perm;
673673

674674
audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted");
@@ -1059,7 +1059,7 @@ int avc_has_extended_perms(struct selinux_state *state,
10591059

10601060
node = avc_lookup(state->avc, ssid, tsid, tclass);
10611061
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);
10631063
} else {
10641064
memcpy(&avd, &node->ae.avd, sizeof(avd));
10651065
xp_node = node->ae.xp_node;
@@ -1151,7 +1151,7 @@ inline int avc_has_perm_noaudit(struct selinux_state *state,
11511151

11521152
node = avc_lookup(state->avc, ssid, tsid, tclass);
11531153
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);
11551155
else
11561156
memcpy(avd, &node->ae.avd, sizeof(*avd));
11571157

security/selinux/hooks.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int __init checkreqprot_setup(char *str)
145145
if (!kstrtoul(str, 0, &checkreqprot)) {
146146
selinux_checkreqprot_boot = checkreqprot ? 1 : 0;
147147
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");
149149
}
150150
return 1;
151151
}
@@ -2964,8 +2964,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,
29642964
* allowed to actually create this type of anonymous inode.
29652965
*/
29662966

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 : "?";
29692969

29702970
return avc_has_perm(&selinux_state,
29712971
tsec->sid,
@@ -6487,7 +6487,6 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
64876487
goto abort_change;
64886488

64896489
/* Only allow single threaded processes to change context */
6490-
error = -EPERM;
64916490
if (!current_is_single_threaded()) {
64926491
error = security_bounded_transition(&selinux_state,
64936492
tsec->sid, sid);
@@ -7294,6 +7293,8 @@ static __init int selinux_init(void)
72947293

72957294
memset(&selinux_state, 0, sizeof(selinux_state));
72967295
enforcing_set(&selinux_state, selinux_enforcing_boot);
7296+
if (CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE)
7297+
pr_err("SELinux: CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is non-zero. This is deprecated and will be rejected in a future kernel release.\n");
72977298
checkreqprot_set(&selinux_state, selinux_checkreqprot_boot);
72987299
selinux_avc_init(&selinux_state.avc);
72997300
mutex_init(&selinux_state.status_lock);

security/selinux/include/audit.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#ifndef _SELINUX_AUDIT_H
1313
#define _SELINUX_AUDIT_H
1414

15+
#include <linux/audit.h>
16+
#include <linux/types.h>
17+
1518
/**
1619
* selinux_audit_rule_init - alloc/init an selinux audit rule structure.
1720
* @field: the field this rule refers to
@@ -51,7 +54,7 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule);
5154
* @rule: rule to be checked
5255
* Returns 1 if there are selinux fields specified in the rule, 0 otherwise.
5356
*/
54-
int selinux_audit_rule_known(struct audit_krule *krule);
57+
int selinux_audit_rule_known(struct audit_krule *rule);
5558

5659
#endif /* _SELINUX_AUDIT_H */
5760

security/selinux/include/avc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ int slow_avc_audit(struct selinux_state *state,
104104

105105
/**
106106
* avc_audit - Audit the granting or denial of permissions.
107+
* @state: SELinux state
107108
* @ssid: source security identifier
108109
* @tsid: target security identifier
109110
* @tclass: target security class

0 commit comments

Comments
 (0)