Skip to contentSkip to conversation

libsepol: Free context on genfscon wildcard error in kernel_to_*

PATCH In review James Carter 2 participants 3 messages Aug 12 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Free context on genfscon wildcard error in kernel_to_*

A policy with the policy capability genfs_seclabel_wildcard should have all of its genfscon paths end with "*" (which is added for backwards compatibility when compiling the policy). When converting a kernel policy to CIL or a policy.conf, an error occurs if the genfscon path does not end with "*". On this error path the context is not freed in either kernel_to_cil or kernel_to_conf.

Free the context when exiting with an error for a genfscon path not ending with a "*" when required.

---
 libsepol/src/kernel_to_cil.c  | 1 +
 libsepol/src/kernel_to_conf.c | 1 +
 2 files changed, 2 insertions(+)
libsepol/src/kernel_to_cil.c +1 -0
index f64eb896..f274d597 100644
@@ -2964,6 +2964,7 @@ static int write_genfscon_rules_to_cil(FILE *out, struct policydb *pdb)
 				    name[name_len - 1] != '*') {
 					ERR(NULL,
 					    "genfscon path must end with '*' when genfs_seclabel_wildcard");
+					free(ctx);
 					rc = -1;
 					goto exit;
 				}
libsepol/src/kernel_to_conf.c +1 -0
index 9bfe5b38..c6e8fadd 100644
@@ -2825,6 +2825,7 @@ static int write_genfscon_rules_to_conf(FILE *out, struct policydb *pdb)
 				    name[name_len - 1] != '*') {
 					ERR(NULL,
 					    "genfscon path must end with '*' when genfs_seclabel_wildcard");
+					free(ctx);
 					rc = -1;
 					goto exit;
 				}
Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · James Carter

A policy with the policy capability genfs_seclabel_wildcard should have all of its genfscon paths end with "*" (which is added for backwards compatibility when compiling the policy). When converting a kernel policy to CIL or a policy.conf, an error occurs if the genfscon path does not end with "*". On this error path the context is not freed in either kernel_to_cil or kernel_to_conf.

Quoted 4 lines

Free the context when exiting with an error for a genfscon path not ending with a "*" when required.

maintainer
#2 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 8 lines · James Carter

A policy with the policy capability genfs_seclabel_wildcard should have all of its genfscon paths end with "*" (which is added for backwards compatibility when compiling the policy). When converting a kernel policy to CIL or a policy.conf, an error occurs if the genfscon path does not end with "*". On this error path the context is not freed in either kernel_to_cil or kernel_to_conf.

Quoted 6 lines
Quoted 4 lines

Free the context when exiting with an error for a genfscon path not ending with a "*" when required.

Merged.