Skip to contentSkip to conversation

libsepol: Fix erroneous genfscon asterisks

PATCH In review Inseob Kim 3 participants 3 messages Aug 13, 2025 – Oct 6, 2025 SELinux security module

lore
Share & tools
lore

Inseob Kim

author
#0 lore raw

PATCH 1/1 libsepol: Fix erroneous genfscon asterisks

When genfs_seclabel_wildcard is on, extra asterisks are added to keep semantics of genfscon entries. That needs to be removed when converting the policy to CIL or conf, but genfscon_to_cil is missing it.

---
 libsepol/src/module_to_cil.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
libsepol/src/module_to_cil.c +15 -2
index b4439b27..8647d928 100644
@@ -2987,10 +2987,22 @@ static int genfscon_to_cil(struct policydb *pdb)
 	struct genfs *genfs;
 	struct ocontext *ocon;
 	uint32_t sclass;
+	char *name;
+	int wildcard = ebitmap_get_bit(&pdb->policycaps, POLICYDB_CAP_GENFS_SECLABEL_WILDCARD);
+	size_t name_len;
 
 	for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
 		for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
 			sclass = ocon->v.sclass;
+			name = ocon->u.name;
+			name_len = strlen(name);
+			if (wildcard) {
+				if (name_len == 0 || name[name_len - 1] != '*') {
+					ERR(NULL, "genfscon path must end with '*' when genfs_seclabel_wildcard");
+					return -1;
+				}
+				--name_len;
+			}
 			if (sclass) {
 				const char *file_type;
 				const char *class_name = pdb->p_class_val_to_name[sclass-1];
@@ -3011,9 +3023,10 @@ static int genfscon_to_cil(struct policydb *pdb)
 				} else {
 					return -1;
 				}
-				cil_printf("(genfscon %s \"%s\" %s ", genfs->fstype, ocon->u.name, file_type);
+				cil_printf("(genfscon %s \"%.*s\" %s ", genfs->fstype, (int)name_len, name,
+				           file_type);
 			} else {
-				cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
+				cil_printf("(genfscon %s \"%.*s\" ", genfs->fstype, (int)name_len, name);
 			}
 			context_to_cil(pdb, &ocon->context[0]);
 			cil_printf(")\n");
Signature · 1 line
2.51.0.rc0.205.g4a044479a3-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Inseob Kim

When genfs_seclabel_wildcard is on, extra asterisks are added to keep semantics of genfscon entries. That needs to be removed when converting the policy to CIL or conf, but genfscon_to_cil is missing it.

Quoted 48 lines
---
 libsepol/src/module_to_cil.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
libsepol/src/module_to_cil.c +15 -3
index b4439b27..8647d928 100644
@@ -2987,10 +2987,22 @@ static int genfscon_to_cil(struct policydb *pdb)
        struct genfs *genfs;
        struct ocontext *ocon;
        uint32_t sclass;
+       char *name;
+       int wildcard = ebitmap_get_bit(&pdb->policycaps, POLICYDB_CAP_GENFS_SECLABEL_WILDCARD);
+       size_t name_len;
 
        for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
                for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
                        sclass = ocon->v.sclass;
+                       name = ocon->u.name;
+                       name_len = strlen(name);
+                       if (wildcard) {
+                               if (name_len == 0 || name[name_len - 1] != '*') {
+                                       ERR(NULL, "genfscon path must end with '*' when genfs_seclabel_wildcard");
+                                       return -1;
+                               }
+                               --name_len;
+                       }
                        if (sclass) {
                                const char *file_type;
                                const char *class_name = pdb->p_class_val_to_name[sclass-1];
@@ -3011,9 +3023,10 @@ static int genfscon_to_cil(struct policydb *pdb)
                                } else {
                                        return -1;
                                }
-                               cil_printf("(genfscon %s \"%s\" %s ", genfs->fstype, ocon->u.name, file_type);
+                               cil_printf("(genfscon %s \"%.*s\" %s ", genfs->fstype, (int)name_len, name,
+                                          file_type);
                        } else {
-                               cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
+                               cil_printf("(genfscon %s \"%.*s\" ", genfs->fstype, (int)name_len, name);
                        }
                        context_to_cil(pdb, &ocon->context[0]);
                        cil_printf(")\n");
--

2.51.0.rc0.205.g4a044479a3-goog

maintainer
#2 lore raw
Quoted 10 lines · James Carter
Quoted 6 lines · Inseob Kim

When genfs_seclabel_wildcard is on, extra asterisks are added to keep semantics of genfscon entries. That needs to be removed when converting the policy to CIL or conf, but genfscon_to_cil is missing it.

Thanks, merged.

Quoted 50 lines
Quoted 49 lines
---
 libsepol/src/module_to_cil.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
libsepol/src/module_to_cil.c +15 -3
index b4439b27..8647d928 100644
@@ -2987,10 +2987,22 @@ static int genfscon_to_cil(struct policydb *pdb)
        struct genfs *genfs;
        struct ocontext *ocon;
        uint32_t sclass;
+       char *name;
+       int wildcard = ebitmap_get_bit(&pdb->policycaps, POLICYDB_CAP_GENFS_SECLABEL_WILDCARD);
+       size_t name_len;
 
        for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
                for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
                        sclass = ocon->v.sclass;
+                       name = ocon->u.name;
+                       name_len = strlen(name);
+                       if (wildcard) {
+                               if (name_len == 0 || name[name_len - 1] != '*') {
+                                       ERR(NULL, "genfscon path must end with '*' when genfs_seclabel_wildcard");
+                                       return -1;
+                               }
+                               --name_len;
+                       }
                        if (sclass) {
                                const char *file_type;
                                const char *class_name = pdb->p_class_val_to_name[sclass-1];
@@ -3011,9 +3023,10 @@ static int genfscon_to_cil(struct policydb *pdb)
                                } else {
                                        return -1;
                                }
-                               cil_printf("(genfscon %s \"%s\" %s ", genfs->fstype, ocon->u.name, file_type);
+                               cil_printf("(genfscon %s \"%.*s\" %s ", genfs->fstype, (int)name_len, name,
+                                          file_type);
                        } else {
-                               cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
+                               cil_printf("(genfscon %s \"%.*s\" ", genfs->fstype, (int)name_len, name);
                        }
                        context_to_cil(pdb, &ocon->context[0]);
                        cil_printf(")\n");
--

2.51.0.rc0.205.g4a044479a3-goog