Skip to content

Commit f3f7d16

Browse files
iskim517stephensmalley
authored andcommitted
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. Signed-off-by: Inseob Kim <[email protected]> Acked-by: James Carter <[email protected]>
1 parent e35547a commit f3f7d16

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

libsepol/src/module_to_cil.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,10 +2987,22 @@ static int genfscon_to_cil(struct policydb *pdb)
29872987
struct genfs *genfs;
29882988
struct ocontext *ocon;
29892989
uint32_t sclass;
2990+
char *name;
2991+
int wildcard = ebitmap_get_bit(&pdb->policycaps, POLICYDB_CAP_GENFS_SECLABEL_WILDCARD);
2992+
size_t name_len;
29902993

29912994
for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
29922995
for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
29932996
sclass = ocon->v.sclass;
2997+
name = ocon->u.name;
2998+
name_len = strlen(name);
2999+
if (wildcard) {
3000+
if (name_len == 0 || name[name_len - 1] != '*') {
3001+
ERR(NULL, "genfscon path must end with '*' when genfs_seclabel_wildcard");
3002+
return -1;
3003+
}
3004+
--name_len;
3005+
}
29943006
if (sclass) {
29953007
const char *file_type;
29963008
const char *class_name = pdb->p_class_val_to_name[sclass-1];
@@ -3011,9 +3023,10 @@ static int genfscon_to_cil(struct policydb *pdb)
30113023
} else {
30123024
return -1;
30133025
}
3014-
cil_printf("(genfscon %s \"%s\" %s ", genfs->fstype, ocon->u.name, file_type);
3026+
cil_printf("(genfscon %s \"%.*s\" %s ", genfs->fstype, (int)name_len, name,
3027+
file_type);
30153028
} else {
3016-
cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
3029+
cil_printf("(genfscon %s \"%.*s\" ", genfs->fstype, (int)name_len, name);
30173030
}
30183031
context_to_cil(pdb, &ocon->context[0]);
30193032
cil_printf(")\n");

0 commit comments

Comments
 (0)