Skip to content

Commit 339949b

Browse files
stephensmalleypcmoore
authored andcommitted
scripts/selinux,selinux: update mdp to enable policy capabilities
Presently mdp does not enable any SELinux policy capabilities in the dummy policy it generates. Thus, policies derived from it will by default lack various features commonly used in modern policies such as open permission, extended socket classes, network peer controls, etc. Split the policy capability definitions out into their own headers so that we can include them into mdp without pulling in other kernel headers and extend mdp generate policycap statements for the policy capabilities known to the kernel. Policy authors may wish to selectively remove some of these from the generated policy. Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 9123e3a commit 339949b

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

scripts/selinux/mdp/mdp.c

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct security_class_mapping {
3535

3636
#include "classmap.h"
3737
#include "initial_sid_to_string.h"
38+
#include "policycap_names.h"
39+
40+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
3841

3942
int main(int argc, char *argv[])
4043
{
@@ -115,6 +118,10 @@ int main(int argc, char *argv[])
115118
}
116119
}
117120

121+
/* enable all policy capabilities */
122+
for (i = 0; i < ARRAY_SIZE(selinux_policycap_names); i++)
123+
fprintf(fout, "policycap %s;\n", selinux_policycap_names[i]);
124+
118125
/* types, roles, and allows */
119126
fprintf(fout, "type base_t;\n");
120127
fprintf(fout, "role base_r;\n");

security/selinux/include/policycap.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _SELINUX_POLICYCAP_H_
3+
#define _SELINUX_POLICYCAP_H_
4+
5+
/* Policy capabilities */
6+
enum {
7+
POLICYDB_CAPABILITY_NETPEER,
8+
POLICYDB_CAPABILITY_OPENPERM,
9+
POLICYDB_CAPABILITY_EXTSOCKCLASS,
10+
POLICYDB_CAPABILITY_ALWAYSNETWORK,
11+
POLICYDB_CAPABILITY_CGROUPSECLABEL,
12+
POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION,
13+
POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS,
14+
__POLICYDB_CAPABILITY_MAX
15+
};
16+
#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
17+
18+
extern const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX];
19+
20+
#endif /* _SELINUX_POLICYCAP_H_ */
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _SELINUX_POLICYCAP_NAMES_H_
3+
#define _SELINUX_POLICYCAP_NAMES_H_
4+
5+
#include "policycap.h"
6+
7+
/* Policy capability names */
8+
const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = {
9+
"network_peer_controls",
10+
"open_perms",
11+
"extended_socket_class",
12+
"always_check_network",
13+
"cgroup_seclabel",
14+
"nnp_nosuid_transition",
15+
"genfs_seclabel_symlinks"
16+
};
17+
18+
#endif /* _SELINUX_POLICYCAP_NAMES_H_ */

security/selinux/include/security.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/refcount.h>
1717
#include <linux/workqueue.h>
1818
#include "flask.h"
19+
#include "policycap.h"
1920

2021
#define SECSID_NULL 0x00000000 /* unspecified SID */
2122
#define SECSID_WILD 0xffffffff /* wildcard SID */
@@ -72,21 +73,6 @@ struct netlbl_lsm_secattr;
7273

7374
extern int selinux_enabled_boot;
7475

75-
/* Policy capabilities */
76-
enum {
77-
POLICYDB_CAPABILITY_NETPEER,
78-
POLICYDB_CAPABILITY_OPENPERM,
79-
POLICYDB_CAPABILITY_EXTSOCKCLASS,
80-
POLICYDB_CAPABILITY_ALWAYSNETWORK,
81-
POLICYDB_CAPABILITY_CGROUPSECLABEL,
82-
POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION,
83-
POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS,
84-
__POLICYDB_CAPABILITY_MAX
85-
};
86-
#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
87-
88-
extern const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX];
89-
9076
/*
9177
* type_datum properties
9278
* available at the kernel policy version >= POLICYDB_VERSION_BOUNDARY

security/selinux/ss/services.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,7 @@
6464
#include "xfrm.h"
6565
#include "ebitmap.h"
6666
#include "audit.h"
67-
68-
/* Policy capability names */
69-
const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = {
70-
"network_peer_controls",
71-
"open_perms",
72-
"extended_socket_class",
73-
"always_check_network",
74-
"cgroup_seclabel",
75-
"nnp_nosuid_transition",
76-
"genfs_seclabel_symlinks"
77-
};
67+
#include "policycap_names.h"
7868

7969
static struct selinux_ss selinux_ss;
8070

0 commit comments

Comments
 (0)