libsepol: Write "NO_IDENTIFIER" for empty constraint expression
PATCH 1/2 libsepol: Write "NO_IDENTIFIER" for empty constraint expression
If a role attribute with no roles associated with it is used in a constraint expression, then the role bitmap will be empty. This is not a problem for the kernel, but does cause problems when converting a kernel policy to policy.conf.
When creating a policy.conf from a kernel policy, if an empty bitmap is encountered, use the string "NO_IDENTIFIER". An error will occur if an attempt is made to compile the resulting policy, but this is better than exiting with an error without creating a policy.conf.
--- libsepol/src/kernel_to_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/kernel_to_conf.c +1 -1
@@ -186,7 +186,7 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_expr names =ebitmap_to_str (&curr->names, pdb->p_role_val_to_name,1 ); }if (!names) { - goto exit; + names =strdup ("NO_IDENTIFIER" ); } new_val =create_str ("%s %s %s" ,3 , attr1, op, names);free (names);
Signature · 1 line
2.26.2
PATCH 2/2 libsepol: Enclose identifier lists in constraint expressions
When writing a policy.conf from a kernel policy, if there are multiple users, roles, or types, then the list needs to be enclosed by "{" and "}".
When writing a constraint expression, check to see if there are multiple identifiers in the names string and enclose the list with "{" and "}" if there are.
--- libsepol/src/kernel_to_conf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
libsepol/src/kernel_to_conf.c +5 -1
@@ -188,7 +188,11 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_exprif (!names) { names =strdup ("NO_IDENTIFIER" ); } - new_val =create_str ("%s %s %s" ,3 , attr1, op, names); +if (strchr (names,' ' )) { + new_val =create_str ("%s %s { %s }" ,3 , attr1, op, names); + }else { + new_val =create_str ("%s %s %s" ,3 , attr1, op, names); + }free (names); } }else {
Signature · 1 line
2.26.2
Quoted 6 lines · James Carter
If a role attribute with no roles associated with it is used in a constraint expression, then the role bitmap will be empty. This is not a problem for the kernel, but does cause problems when converting a kernel policy to policy.conf.
Quoted 6 lines
When creating a policy.conf from a kernel policy, if an empty bitmap is encountered, use the string "
NO_IDENTIFIER". An error will occur if an attempt is made to compile the resulting policy, but this is better than exiting with an error without creating a policy.conf.Signed-off-by James Carter <[email protected]>
For these 2 patches:
Quoted 20 lines
--- libsepol/src/kernel_to_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsepol/src/kernel_to_conf.c +1
-2@@ -186,7 +186,7 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_expr names =ebitmap_to_str (&curr->names, pdb->p_role_val_to_name,1 ); }if (!names) { - goto exit; + names =strdup ("NO_IDENTIFIER" ); } new_val =create_str ("%s %s %s" ,3 , attr1, op, names);free (names); --2.26.2
Quoted 13 lines · Nicolas Iooss
Quoted 11 lines · James Carter
If a role attribute with no roles associated with it is used in a constraint expression, then the role bitmap will be empty. This is not a problem for the kernel, but does cause problems when converting a kernel policy to policy.conf.
When creating a policy.conf from a kernel policy, if an empty bitmap is encountered, use the string "
NO_IDENTIFIER". An error will occur if an attempt is made to compile the resulting policy, but this is better than exiting with an error without creating a policy.conf.
Quoted 5 lines
Quoted 1 line
Signed-off-by James Carter <[email protected]>For these 2 patches:
Acked-by Nicolas Iooss <[email protected]>
These 2 patches have been merged.
Thanks,
Jim
Quoted 21 lines
Quoted 20 lines
--- libsepol/src/kernel_to_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsepol/src/kernel_to_conf.c +1
-2@@ -186,7 +186,7 @@ static char *constraint_expr_to_str(struct policydb *pdb, struct constraint_expr names =ebitmap_to_str (&curr->names, pdb->p_role_val_to_name,1 ); }if (!names) { - goto exit; + names =strdup ("NO_IDENTIFIER" ); } new_val =create_str ("%s %s %s" ,3 , attr1, op, names);free (names); --2.26.2