Skip to contentSkip to conversation

libsepol: Quote paths when generating policy.conf from binary policy

PATCH In review James Carter 2 participants 3 messages Jun 16, 2021 – Jun 22, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Quote paths when generating policy.conf from binary policy

Christian Göttsche <[email protected]> submitted a similar patch to quote paths when generating CIL policy from a binary policy.

Since genfscon and devicetreecon rules have paths which are allowed to contain spaces, always quote the path when writing out these rules.

---
 libsepol/src/kernel_to_conf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/kernel_to_conf.c +2 -2
index 5db47fe4..ffdf179a 100644
@@ -2527,7 +2527,7 @@ static int write_genfscon_rules_to_conf(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) {
@@ -2992,7 +2992,7 @@ static int write_xen_devicetree_rules_to_conf(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);
 	}
Signature · 1 line
2.26.3
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · James Carter

Christian Göttsche <[email protected]> submitted a similar patch to quote paths when generating CIL policy from a binary policy.

Since genfscon and devicetreecon rules have paths which are allowed to contain spaces, always quote the path when writing out these rules.

Quoted 28 lines
---
 libsepol/src/kernel_to_conf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/kernel_to_conf.c +2 -2
index 5db47fe4..ffdf179a 100644
@@ -2527,7 +2527,7 @@ static int write_genfscon_rules_to_conf(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) {
@@ -2992,7 +2992,7 @@ static int write_xen_devicetree_rules_to_conf(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);
 	}
Signature · 1 line
2.26.3
#2 lore raw
Quoted 6 lines · Petr Lautrbach
Quoted 3 lines · James Carter

Christian Göttsche <[email protected]> submitted a similar patch to quote paths when generating CIL policy from a binary policy.

Quoted 7 lines
Quoted 4 lines

Since genfscon and devicetreecon rules have paths which are allowed to contain spaces, always quote the path when writing out these rules.

This has been merged.
Jim

Quoted 31 lines
Quoted 30 lines

---
 libsepol/src/kernel_to_conf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsepol/src/kernel_to_conf.c +2 -3
index 5db47fe4..ffdf179a 100644
@@ -2527,7 +2527,7 @@ static int write_genfscon_rules_to_conf(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) {
@@ -2992,7 +2992,7 @@ static int write_xen_devicetree_rules_to_conf(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);
      }
--

2.26.3