All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Lautrbach <plautrba@redhat.com>
To: "SElinux list" <selinux@vger.kernel.org>,
	"James Carter" <jwcart2@gmail.com>,
	"Christian Göttsche" <cgzones@googlemail.com>
Subject: Re: [PATCH v2] libsepol/cil: handle SID without assigned context when writing policy.conf
Date: Wed, 24 Feb 2021 11:59:04 +0100	[thread overview]
Message-ID: <874ki13f5z.fsf@redhat.com> (raw)
In-Reply-To: <CAP+JOzTz0X+AEF3KJ1N-L8DLitit6r-+nFUegkYorFg=GSSv8g@mail.gmail.com>

James Carter <jwcart2@gmail.com> writes:

> On Tue, Feb 23, 2021 at 8:13 AM Christian Göttsche
> <cgzones@googlemail.com> wrote:
>>
>> 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 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 <cgzones@googlemail.com>
>
> Oops, I should have noticed that. I was too focused on the segfault.
>
> Acked-by: James Carter <jwcart2@gmail.com>

Merged, thanks!

>> ---
>> 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(-)
>>
>> diff --git a/libsepol/cil/src/cil_policy.c b/libsepol/cil/src/cil_policy.c
>> index 74edb345..91e767b7 100644
>> --- a/libsepol/cil/src/cil_policy.c
>> +++ b/libsepol/cil/src/cil_policy.c
>> @@ -1660,9 +1660,11 @@ static void cil_sid_contexts_to_policy(FILE *out, struct cil_list *sids, int mls
>>
>>         cil_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
>>


      reply	other threads:[~2021-02-24 11:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20 19:08 [PATCH] libsepol/cil: handle SID without assigned context when writing policy.conf Christian Göttsche
2021-02-22 20:09 ` James Carter
2021-02-23 13:09 ` [PATCH v2] " Christian Göttsche
2021-02-23 15:33   ` James Carter
2021-02-24 10:59     ` Petr Lautrbach [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ki13f5z.fsf@redhat.com \
    --to=plautrba@redhat.com \
    --cc=cgzones@googlemail.com \
    --cc=jwcart2@gmail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.