Introduce an initial SID for early boot processes
cover Introduce an initial SID for early boot processes
These are userspace support patches corresponding to the following kernel patch submission:
https://lore.kernel.org/selinux/[email protected]/
The first patch merely removes the names of the discontinued initial SIDs. The second patch adds the new policy capability and re-adds the "init" initial SID's name as it's being reused for the new functionality added by the kernel patch.
Ondrej Mosnacek (2):
libsepol: stop translating deprecated intial SIDs to strings
libsepol: add support for the new "init" initial SID
libsepol/include/sepol/policydb/polcaps.h | 1 + libsepol/src/kernel_to_cil.c | 4 +-- libsepol/src/kernel_to_common.h | 34 +++++++++++------------ libsepol/src/kernel_to_conf.c | 4 +-- libsepol/src/module_to_cil.c | 2 +- libsepol/src/polcaps.c | 1 + 6 files changed, 24 insertions(+), 22 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/2 libsepol: stop translating deprecated intial SIDs to strings
Many of the initial SIDs are no longer used by the kernel, so translating them to the legacy names doesn't bring much value. Clear the legacy names from the table and let the code translate them to the fallback "unknown" names instead.
Note that this only affects the generated text output when converting policies from binary to text form. The text policy languages let the policy define its own names for the initial SIDs based on the order in which they are declared, so the table is never used to convert from name to SID. Thus this is just a cosmetic change and has no functional impact.
--- libsepol/src/kernel_to_cil.c | 4 ++-- libsepol/src/kernel_to_common.h | 36 ++++++++++++++++----------------- libsepol/src/kernel_to_conf.c | 4 ++-- libsepol/src/module_to_cil.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-)
libsepol/src/kernel_to_cil.c +2 -2
@@ -567,7 +567,7 @@ static int write_sids_to_cil(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);
@@ -2577,7 +2577,7 @@ static int write_sid_context_rules_to_cil(FILE *out, struct policydb *pdb, constfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);
libsepol/src/kernel_to_common.h +18 -18
@@ -13,33 +13,33 @@// initial sid names aren't actually stored in the pp files, need to a have // a mapping, taken from the linux kernel static const char *const selinux_sid_to_str[] = { -"null" , +NULL ,"kernel" ,"security" ,"unlabeled" , -"fs" , +NULL ,"file" , -"file_labels" , -"init" , +NULL , +NULL ,"any_socket" ,"port" ,"netif" ,"netmsg" ,"node" , -"igmp_packet" , -"icmp_socket" , -"tcp_socket" , -"sysctl_modprobe" , -"sysctl" , -"sysctl_fs" , -"sysctl_kernel" , -"sysctl_net" , -"sysctl_net_unix" , -"sysctl_vm" , -"sysctl_dev" , -"kmod" , -"policy" , -"scmp_packet" , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL ,"devnull" , };
libsepol/src/kernel_to_conf.c +2 -2
@@ -464,7 +464,7 @@ static int write_sids_to_conf(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);
@@ -2445,7 +2445,7 @@ static int write_sid_context_rules_to_conf(FILE *out, struct policydb *pdb, consfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);
libsepol/src/module_to_cil.c +1 -1
@@ -2549,7 +2549,7 @@ static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_string[i]) { sid = (char *)sid_to_string[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);
Signature · 1 line
2.40.1
Re: [PATCH userspace 1/2] libsepol: stop translating deprecated intial SIDs to strings
Quoted 6 lines · Ondrej Mosnacek
Many of the initial SIDs are no longer used by the kernel, so translating them to the legacy names doesn't bring much value. Clear the legacy names from the table and let the code translate them to the fallback "unknown" names instead.
Quoted 8 lines
Note that this only affects the generated text output when converting policies from binary to text form. The text policy languages let the policy define its own names for the initial SIDs based on the order in which they are declared, so the table is never used to convert from name to SID. Thus this is just a cosmetic change and has no functional impact.
Signed-off-by Ondrej Mosnacek <[email protected]>
For these two patches:
Quoted 123 lines
--- libsepol/src/kernel_to_cil.c | 4 ++-- libsepol/src/kernel_to_common.h | 36 ++++++++++++++++----------------- libsepol/src/kernel_to_conf.c | 4 ++-- libsepol/src/module_to_cil.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-)libsepol/src/kernel_to_cil.c +2
-2@@ -567,7 +567,7 @@ static int write_sids_to_cil(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);@@ -2577,7 +2577,7 @@ static int write_sid_context_rules_to_cil(FILE *out, struct policydb *pdb, constfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);libsepol/src/kernel_to_common.h +18
-18@@ -13,33 +13,33 @@// initial sid names aren't actually stored in the pp files, need to a have // a mapping, taken from the linux kernel static const char *const selinux_sid_to_str[] = { -"null" , +NULL ,"kernel" ,"security" ,"unlabeled" , -"fs" , +NULL ,"file" , -"file_labels" , -"init" , +NULL , +NULL ,"any_socket" ,"port" ,"netif" ,"netmsg" ,"node" , -"igmp_packet" , -"icmp_socket" , -"tcp_socket" , -"sysctl_modprobe" , -"sysctl" , -"sysctl_fs" , -"sysctl_kernel" , -"sysctl_net" , -"sysctl_net_unix" , -"sysctl_vm" , -"sysctl_dev" , -"kmod" , -"policy" , -"scmp_packet" , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL ,"devnull" , };libsepol/src/kernel_to_conf.c +2
-2@@ -464,7 +464,7 @@ static int write_sids_to_conf(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);@@ -2445,7 +2445,7 @@ static int write_sid_context_rules_to_conf(FILE *out, struct policydb *pdb, consfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);libsepol/src/module_to_cil.c +1
-2@@ -2549,7 +2549,7 @@ static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_string[i]) { sid = (char *)sid_to_string[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i); --2.40.1
Re: [PATCH userspace 1/2] libsepol: stop translating deprecated intial SIDs to strings
Quoted 14 lines · James Carter
Quoted 13 lines · Ondrej Mosnacek
Many of the initial SIDs are no longer used by the kernel, so translating them to the legacy names doesn't bring much value. Clear the legacy names from the table and let the code translate them to the fallback "unknown" names instead.
Note that this only affects the generated text output when converting policies from binary to text form. The text policy languages let the policy define its own names for the initial SIDs based on the order in which they are declared, so the table is never used to convert from name to SID. Thus this is just a cosmetic change and has no functional impact.
Quoted 4 lines
Quoted 1 line
Signed-off-by Ondrej Mosnacek <[email protected]>For these two patches:
Acked-by James Carter <[email protected]>
Both merged. Thanks!
Quoted 123 lines
Quoted 123 lines
--- libsepol/src/kernel_to_cil.c | 4 ++-- libsepol/src/kernel_to_common.h | 36 ++++++++++++++++----------------- libsepol/src/kernel_to_conf.c | 4 ++-- libsepol/src/module_to_cil.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-)libsepol/src/kernel_to_cil.c +2
-2@@ -567,7 +567,7 @@ static int write_sids_to_cil(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);@@ -2577,7 +2577,7 @@ static int write_sid_context_rules_to_cil(FILE *out, struct policydb *pdb, constfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i);libsepol/src/kernel_to_common.h +18
-18@@ -13,33 +13,33 @@// initial sid names aren't actually stored in the pp files, need to a have // a mapping, taken from the linux kernel static const char *const selinux_sid_to_str[] = { -"null" , +NULL ,"kernel" ,"security" ,"unlabeled" , -"fs" , +NULL ,"file" , -"file_labels" , -"init" , +NULL , +NULL ,"any_socket" ,"port" ,"netif" ,"netmsg" ,"node" , -"igmp_packet" , -"icmp_socket" , -"tcp_socket" , -"sysctl_modprobe" , -"sysctl" , -"sysctl_fs" , -"sysctl_kernel" , -"sysctl_net" , -"sysctl_net_unix" , -"sysctl_vm" , -"sysctl_dev" , -"kmod" , -"policy" , -"scmp_packet" , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL , +NULL ,"devnull" , };libsepol/src/kernel_to_conf.c +2
-2@@ -464,7 +464,7 @@ static int write_sids_to_conf(FILE *out, const char *const *sid_to_str,for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);@@ -2445,7 +2445,7 @@ static int write_sid_context_rules_to_conf(FILE *out, struct policydb *pdb, consfor (isid = pdb->ocontexts[0 ]; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_str[i]) { sid = (char *)sid_to_str[i]; }else {snprintf (unknown,sizeof (unknown),"%s%u" ,"UNKNOWN" , i);libsepol/src/module_to_cil.c +1
-2@@ -2549,7 +2549,7 @@ static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_for (isid = isids; isid !=NULL ; isid = isid->next) { i = isid->sid[0 ]; -if (i < num_sids) { +if (i < num_sids && sid_to_string[i]) { sid = (char *)sid_to_string[i]; }else {snprintf (unknown,18 ,"%s%u" ,"UNKNOWN" , i); --2.40.1
PATCH 2/2 libsepol: add support for the new "init" initial SID
In reply to Ondrej MosnacekResurrect the naming of the "init" initial SID, as it has been reintroduced in the kernel. Also add the new "userspace_initial_context" policy capability that is used to enable the new semantics for this initial SID.
--- libsepol/include/sepol/policydb/polcaps.h | 1 + libsepol/src/kernel_to_common.h | 2 +- libsepol/src/polcaps.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
libsepol/include/sepol/policydb/polcaps.h +1 -0
@@ -15,6 +15,7 @@ enum {POLICYDB_CAP_NNP_NOSUID_TRANSITION ,POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS ,POLICYDB_CAP_IOCTL_SKIP_CLOEXEC , +POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT , __POLICYDB_CAP_MAX };#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
libsepol/src/kernel_to_common.h +1 -1
@@ -20,7 +20,7 @@ static const char * const selinux_sid_to_str[] = {NULL ,"file" ,NULL , -NULL , +"init" ,"any_socket" ,"port" , "netif",
libsepol/src/polcaps.c +1 -0
@@ -14,6 +14,7 @@ static const char * const polcap_names[] = {"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 };
Signature · 1 line
2.40.1