Skip to contentSkip to conversation

libsepol: update policy capabilities array

PATCH In review Christian Göttsche 2 participants 3 messages Nov 9, 2023 – Nov 16, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: update policy capabilities array

Use their enum values as indices to clarify their relationships. Specify array size to verify it at compile time.
Remove unnecessary trailing entry, since all access is controlled by a check against POLICYDB_CAP_MAX.

---
 libsepol/src/polcaps.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
libsepol/src/polcaps.c +10 -11
index be12580a..8289443a 100644
@@ -5,17 +5,16 @@
 #include <string.h>
 #include <sepol/policydb/polcaps.h>
 
-static const char * const polcap_names[] = {
-	"network_peer_controls",	/* POLICYDB_CAP_NETPEER */
-	"open_perms",			/* POLICYDB_CAP_OPENPERM */
-	"extended_socket_class",	/* POLICYDB_CAP_EXTSOCKCLASS */
-	"always_check_network",		/* POLICYDB_CAP_ALWAYSNETWORK */
-	"cgroup_seclabel",		/* POLICYDB_CAP_SECLABEL */
-	"nnp_nosuid_transition",	/* POLICYDB_CAP_NNP_NOSUID_TRANSITION */
-	"genfs_seclabel_symlinks",	/* POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS */
-	"ioctl_skip_cloexec",		/* POLICYDB_CAP_IOCTL_SKIP_CLOEXEC */
-	"userspace_initial_context",	/* POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT */
-	NULL
+static const char * const polcap_names[POLICYDB_CAP_MAX + 1] = {
+	[POLICYDB_CAP_NETPEER]				= "network_peer_controls",
+	[POLICYDB_CAP_OPENPERM]				= "open_perms",
+	[POLICYDB_CAP_EXTSOCKCLASS]			= "extended_socket_class",
+	[POLICYDB_CAP_ALWAYSNETWORK]			= "always_check_network",
+	[POLICYDB_CAP_CGROUPSECLABEL]			= "cgroup_seclabel",
+	[POLICYDB_CAP_NNP_NOSUID_TRANSITION]		= "nnp_nosuid_transition",
+	[POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS]		= "genfs_seclabel_symlinks",
+	[POLICYDB_CAP_IOCTL_SKIP_CLOEXEC]		= "ioctl_skip_cloexec",
+	[POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT]	= "userspace_initial_context",
 };
 
 int sepol_polcap_getnum(const char *name)
Signature · 1 line
2.42.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Christian Göttsche

Use their enum values as indices to clarify their relationships. Specify array size to verify it at compile time.
Remove unnecessary trailing entry, since all access is controlled by a check against POLICYDB_CAP_MAX.

Quoted 39 lines
---
 libsepol/src/polcaps.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
libsepol/src/polcaps.c +10 -12
index be12580a..8289443a 100644
@@ -5,17 +5,16 @@
 #include <string.h>
 #include <sepol/policydb/polcaps.h>
 
-static const char * const polcap_names[] = {
-       "network_peer_controls",        /* POLICYDB_CAP_NETPEER */
-       "open_perms",                   /* POLICYDB_CAP_OPENPERM */
-       "extended_socket_class",        /* POLICYDB_CAP_EXTSOCKCLASS */
-       "always_check_network",         /* POLICYDB_CAP_ALWAYSNETWORK */
-       "cgroup_seclabel",              /* POLICYDB_CAP_SECLABEL */
-       "nnp_nosuid_transition",        /* POLICYDB_CAP_NNP_NOSUID_TRANSITION */
-       "genfs_seclabel_symlinks",      /* POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS */
-       "ioctl_skip_cloexec",           /* POLICYDB_CAP_IOCTL_SKIP_CLOEXEC */
-       "userspace_initial_context",    /* POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT */
-       NULL
+static const char * const polcap_names[POLICYDB_CAP_MAX + 1] = {
+       [POLICYDB_CAP_NETPEER]                          = "network_peer_controls",
+       [POLICYDB_CAP_OPENPERM]                         = "open_perms",
+       [POLICYDB_CAP_EXTSOCKCLASS]                     = "extended_socket_class",
+       [POLICYDB_CAP_ALWAYSNETWORK]                    = "always_check_network",
+       [POLICYDB_CAP_CGROUPSECLABEL]                   = "cgroup_seclabel",
+       [POLICYDB_CAP_NNP_NOSUID_TRANSITION]            = "nnp_nosuid_transition",
+       [POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS]          = "genfs_seclabel_symlinks",
+       [POLICYDB_CAP_IOCTL_SKIP_CLOEXEC]               = "ioctl_skip_cloexec",
+       [POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT]        = "userspace_initial_context",
 };
 
 int sepol_polcap_getnum(const char *name)
--

2.42.0

#2 lore raw
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 9 lines
Quoted 6 lines

Use their enum values as indices to clarify their relationships. Specify array size to verify it at compile time.
Remove unnecessary trailing entry, since all access is controlled by a check against POLICYDB_CAP_MAX.

This patch has been merged.
Thanks,
Jim

Quoted 39 lines
Quoted 39 lines
---
 libsepol/src/polcaps.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
libsepol/src/polcaps.c +10 -12
index be12580a..8289443a 100644
@@ -5,17 +5,16 @@
 #include <string.h>
 #include <sepol/policydb/polcaps.h>
 
-static const char * const polcap_names[] = {
-       "network_peer_controls",        /* POLICYDB_CAP_NETPEER */
-       "open_perms",                   /* POLICYDB_CAP_OPENPERM */
-       "extended_socket_class",        /* POLICYDB_CAP_EXTSOCKCLASS */
-       "always_check_network",         /* POLICYDB_CAP_ALWAYSNETWORK */
-       "cgroup_seclabel",              /* POLICYDB_CAP_SECLABEL */
-       "nnp_nosuid_transition",        /* POLICYDB_CAP_NNP_NOSUID_TRANSITION */
-       "genfs_seclabel_symlinks",      /* POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS */
-       "ioctl_skip_cloexec",           /* POLICYDB_CAP_IOCTL_SKIP_CLOEXEC */
-       "userspace_initial_context",    /* POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT */
-       NULL
+static const char * const polcap_names[POLICYDB_CAP_MAX + 1] = {
+       [POLICYDB_CAP_NETPEER]                          = "network_peer_controls",
+       [POLICYDB_CAP_OPENPERM]                         = "open_perms",
+       [POLICYDB_CAP_EXTSOCKCLASS]                     = "extended_socket_class",
+       [POLICYDB_CAP_ALWAYSNETWORK]                    = "always_check_network",
+       [POLICYDB_CAP_CGROUPSECLABEL]                   = "cgroup_seclabel",
+       [POLICYDB_CAP_NNP_NOSUID_TRANSITION]            = "nnp_nosuid_transition",
+       [POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS]          = "genfs_seclabel_symlinks",
+       [POLICYDB_CAP_IOCTL_SKIP_CLOEXEC]               = "ioctl_skip_cloexec",
+       [POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT]        = "userspace_initial_context",
 };
 
 int sepol_polcap_getnum(const char *name)
--

2.42.0