libsepol/cil: handle SID without assigned context when writing policy.conf
PATCH 1/1 libsepol/cil: handle SID without assigned context when writing policy.conf
CIL permits not assigning a context to a SID, e.g. to an unused initial SID, e.g. 'any_socket'.
When using the example policy from the SELinux Notebook,
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/notebook-examples/cil-policy/cil-policy.cil,
secilc logs:
No context assigned to SID any_socket, omitting from policy at cil-policy.cil:166
But secil2conf segfaults when writing the policy.conf:
../cil/src/cil_policy.c:274:2: runtime error: member access within null pointer of type 'struct cil_context'
Only print the assigned context if actually available.
--- libsepol/cil/src/cil_policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_policy.c +3 -1
@@ -1661,7 +1661,9 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mlscil_list_for_each (i1, sids) { sid = i1->data;fprintf (out,"sid %s " , sid->datum.fqn); -cil_context_to_policy (out, sid->context, mls); +if (sid->context) { +cil_context_to_policy (out, sid->context, mls); + }fprintf (out,"\n" ); } }
Signature · 1 line
2.30.1
Quoted 10 lines · Christian Göttsche
CIL permits not assigning a context to a SID, e.g. to an unused initial SID, e.g. '
any_socket'.When using the example policy from the SELinux Notebook,
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/notebook-examples/cil-policy/cil-policy.cil,
secilc logs:No context assigned to SID
any_socket, omitting from policy at cil-policy.cil:166
Quoted 7 lines
But secil2conf segfaults when writing the policy.conf:
../cil/src/cil_policy.c:274:2: runtime error: member access within null pointer of type 'structcil_context'Only print the assigned context if actually available.
Signed-off-by Christian Göttsche <[email protected]>
Quoted 22 lines
--- libsepol/cil/src/cil_policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/cil/src/cil_policy.c +3
-2@@ -1661,7 +1661,9 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mlscil_list_for_each (i1, sids) { sid = i1->data;fprintf (out,"sid %s " , sid->datum.fqn); -cil_context_to_policy (out, sid->context, mls); +if (sid->context) { +cil_context_to_policy (out, sid->context, mls); + }fprintf (out,"\n" ); } } --2.30.1
PATCH v2 1/1 libsepol/cil: handle SID without assigned context when writing policy.conf
In reply to Christian GöttscheCIL permits not assigning a context to a SID, e.g. to an unused initial SID, e.g. 'any_socket'.
When using the example policy from the SELinux Notebook,
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/notebook-examples/cil-policy/cil-policy.cil,
secilc logs:
No context assigned to SID any_socket, omitting from policy at cil-policy.cil:166
But secil2conf segfaults when writing the policy.conf:
../cil/src/cil_policy.c:274:2: runtime error: member access within null pointer of type 'struct cil_context'
Only print the sid context statement if a context was actually assigned. The sid declaration is still included via cil_sid_decls_to_policy().
---
v2:
Drop the statement completely in cil_sid_contexts_to_policy(), cause cil_sid_decls_to_policy() will have printed the context less declaration already.
libsepol/cil/src/cil_policy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
libsepol/cil/src/cil_policy.c +5 -3
@@ -1660,9 +1660,11 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mlscil_list_for_each (i1, sids) { sid = i1->data; -fprintf (out,"sid %s " , sid->datum.fqn); -cil_context_to_policy (out, sid->context, mls); -fprintf (out,"\n" ); +if (sid->context) { +fprintf (out,"sid %s " , sid->datum.fqn); +cil_context_to_policy (out, sid->context, mls); +fprintf (out,"\n" ); + } } }
Signature · 1 line
2.30.1
Quoted 10 lines · Christian Göttsche
CIL permits not assigning a context to a SID, e.g. to an unused initial SID, e.g. '
any_socket'.When using the example policy from the SELinux Notebook,
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/notebook-examples/cil-policy/cil-policy.cil,
secilc logs:No context assigned to SID
any_socket, omitting from policy at cil-policy.cil:166
Quoted 8 lines
But secil2conf segfaults when writing the policy.conf:
../cil/src/cil_policy.c:274:2: runtime error: member access within null pointer of type 'structcil_context'Only print the sid context statement if a context was actually assigned. The sid declaration is still included via
cil_sid_decls_to_policy().Signed-off-by Christian Göttsche <[email protected]>
Oops, I should have noticed that. I was too focused on the segfault.
Quoted 31 lines
---
v2:
Drop the statement completely incil_sid_contexts_to_policy(), causecil_sid_decls_to_policy()will have printed the context less declaration already.libsepol/cil/src/cil_policy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)libsepol/cil/src/cil_policy.c +5
-4@@ -1660,9 +1660,11 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mlscil_list_for_each (i1, sids) { sid = i1->data; -fprintf (out,"sid %s " , sid->datum.fqn); -cil_context_to_policy (out, sid->context, mls); -fprintf (out,"\n" ); +if (sid->context) { +fprintf (out,"sid %s " , sid->datum.fqn); +cil_context_to_policy (out, sid->context, mls); +fprintf (out,"\n" ); + } } } --2.30.1
Petr Lautrbach
AppliedQuoted 16 lines · James Carter
Quoted 14 lines · Christian Göttsche
CIL permits not assigning a context to a SID, e.g. to an unused initial SID, e.g. '
any_socket'.When using the example policy from the SELinux Notebook,
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/notebook-examples/cil-policy/cil-policy.cil,
secilc logs:No context assigned to SID
any_socket, omitting from policy at cil-policy.cil:166But secil2conf segfaults when writing the policy.conf:
../cil/src/cil_policy.c:274:2: runtime error: member access within null pointer of type 'structcil_context'
Quoted 8 lines
Quoted 4 lines
Only print the sid context statement if a context was actually assigned. The sid declaration is still included via
cil_sid_decls_to_policy().Signed-off-by Christian Göttsche <[email protected]>Oops, I should have noticed that. I was too focused on the segfault.
Acked-by James Carter <[email protected]>
Merged, thanks!
Quoted 31 lines
Quoted 31 lines
---
v2:
Drop the statement completely incil_sid_contexts_to_policy(), causecil_sid_decls_to_policy()will have printed the context less declaration already.libsepol/cil/src/cil_policy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)libsepol/cil/src/cil_policy.c +5
-4@@ -1660,9 +1660,11 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mlscil_list_for_each (i1, sids) { sid = i1->data; -fprintf (out,"sid %s " , sid->datum.fqn); -cil_context_to_policy (out, sid->context, mls); -fprintf (out,"\n" ); +if (sid->context) { +fprintf (out,"sid %s " , sid->datum.fqn); +cil_context_to_policy (out, sid->context, mls); +fprintf (out,"\n" ); + } } } --2.30.1