Skip to contentSkip to conversation

libsepol: quote paths in CIL conversion

PATCH In review Christian Göttsche 2 participants 3 messages Jun 8, 2021 – Jun 14, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: quote paths in CIL conversion

When generating CIL policy from kernel or module policy quote paths, which are allowed to contain spaces, in the statements genfscon and devicetreecon.

Reported by LuK1337 while building policy for Android via IRC.

---
 libsepol/src/kernel_to_cil.c | 4 ++--
 libsepol/src/module_to_cil.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
libsepol/src/kernel_to_cil.c +2 -2
index 989aacde..30a27bf5 100644
@@ -2654,7 +2654,7 @@ static int write_genfscon_rules_to_cil(FILE *out, struct policydb *pdb)
 				goto exit;
 			}
 
-			rc = strs_create_and_add(strs, "(genfscon %s %s %s)", 3,
+			rc = strs_create_and_add(strs, "(genfscon %s \"%s\" %s)", 3,
 						 fstype, name, ctx);
 			free(ctx);
 			if (rc != 0) {
@@ -3115,7 +3115,7 @@ static int write_xen_devicetree_rules_to_cil(FILE *out, struct policydb *pdb)
 			goto exit;
 		}
 
-		sepol_printf(out, "(devicetreecon %s %s)\n", name, ctx);
+		sepol_printf(out, "(devicetreecon \"%s\" %s)\n", name, ctx);
 
 		free(ctx);
 	}
libsepol/src/module_to_cil.c +1 -1
index 496693f4..19c7c65c 100644
@@ -2963,7 +2963,7 @@ static int genfscon_to_cil(struct policydb *pdb)
 
 	for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
 		for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
-			cil_printf("(genfscon %s %s ", genfs->fstype, ocon->u.name);
+			cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
 			context_to_cil(pdb, &ocon->context[0]);
 			cil_printf(")\n");
 		}
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Christian Göttsche

When generating CIL policy from kernel or module policy quote paths, which are allowed to contain spaces, in the statements genfscon and devicetreecon.

Reported by LuK1337 while building policy for Android via IRC.

Quoted 43 lines
---
 libsepol/src/kernel_to_cil.c | 4 ++--
 libsepol/src/module_to_cil.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
libsepol/src/kernel_to_cil.c +2 -2
index 989aacde..30a27bf5 100644
@@ -2654,7 +2654,7 @@ static int write_genfscon_rules_to_cil(FILE *out, struct policydb *pdb)
                                goto exit;
                        }
 
-                       rc = strs_create_and_add(strs, "(genfscon %s %s %s)", 3,
+                       rc = strs_create_and_add(strs, "(genfscon %s \"%s\" %s)", 3,
                                                 fstype, name, ctx);
                        free(ctx);
                        if (rc != 0) {
@@ -3115,7 +3115,7 @@ static int write_xen_devicetree_rules_to_cil(FILE *out, struct policydb *pdb)
                        goto exit;
                }
 
-               sepol_printf(out, "(devicetreecon %s %s)\n", name, ctx);
+               sepol_printf(out, "(devicetreecon \"%s\" %s)\n", name, ctx);
 
                free(ctx);
        }
libsepol/src/module_to_cil.c +1 -2
index 496693f4..19c7c65c 100644
@@ -2963,7 +2963,7 @@ static int genfscon_to_cil(struct policydb *pdb)
 
        for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
                for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
-                       cil_printf("(genfscon %s %s ", genfs->fstype, ocon->u.name);
+                       cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
                        context_to_cil(pdb, &ocon->context[0]);
                        cil_printf(")\n");
                }
--

2.32.0

#2 lore raw
Quoted 8 lines · James Carter
Quoted 5 lines · Christian Göttsche

When generating CIL policy from kernel or module policy quote paths, which are allowed to contain spaces, in the statements genfscon and devicetreecon.

Quoted 6 lines
Quoted 3 lines

Reported by LuK1337 while building policy for Android via IRC.

Merged.
Thanks,
Jim

Quoted 43 lines
Quoted 43 lines
---
 libsepol/src/kernel_to_cil.c | 4 ++--
 libsepol/src/module_to_cil.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
libsepol/src/kernel_to_cil.c +2 -2
index 989aacde..30a27bf5 100644
@@ -2654,7 +2654,7 @@ static int write_genfscon_rules_to_cil(FILE *out, struct policydb *pdb)
                                goto exit;
                        }
 
-                       rc = strs_create_and_add(strs, "(genfscon %s %s %s)", 3,
+                       rc = strs_create_and_add(strs, "(genfscon %s \"%s\" %s)", 3,
                                                 fstype, name, ctx);
                        free(ctx);
                        if (rc != 0) {
@@ -3115,7 +3115,7 @@ static int write_xen_devicetree_rules_to_cil(FILE *out, struct policydb *pdb)
                        goto exit;
                }
 
-               sepol_printf(out, "(devicetreecon %s %s)\n", name, ctx);
+               sepol_printf(out, "(devicetreecon \"%s\" %s)\n", name, ctx);
 
                free(ctx);
        }
libsepol/src/module_to_cil.c +1 -2
index 496693f4..19c7c65c 100644
@@ -2963,7 +2963,7 @@ static int genfscon_to_cil(struct policydb *pdb)
 
        for (genfs = pdb->genfs; genfs != NULL; genfs = genfs->next) {
                for (ocon = genfs->head; ocon != NULL; ocon = ocon->next) {
-                       cil_printf("(genfscon %s %s ", genfs->fstype, ocon->u.name);
+                       cil_printf("(genfscon %s \"%s\" ", genfs->fstype, ocon->u.name);
                        context_to_cil(pdb, &ocon->context[0]);
                        cil_printf(")\n");
                }
--

2.32.0