selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: "Christian Göttsche" <cgzones@googlemail.com>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: getcon family: returning success while context is NULL
Date: Fri, 24 Jul 2020 09:13:28 -0400	[thread overview]
Message-ID: <CAEjxPJ5nExmrkbgMfD2B9cs-iOdSAVnNfqcqbfns10vOa31=5Q@mail.gmail.com> (raw)
In-Reply-To: <CAJ2a_DfV0M1zD=fjQOGq3KPcBtvQxrgtZHSbBKDcxuOX7pJygA@mail.gmail.com>

On Fri, Jul 24, 2020 at 8:34 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> Hi list,
>
> I stumbled over a systemd commit [1], handling the event where
> getcon_raw returns 0 (success) and the returned context is NULL.
> The commit points to the SELinux userland source lines [2].
>
> Is this by design?
> Or should either errno be set to ENODATA and ret to -1, or this case
> be mentioned in the manpage?

For most of the other process security attributes (e.g. exec,
fscreate, ...), get*con() can return NULL if the attribute has not
been set by the process, and set*con() can be passed NULL to clear the
attribute (i.e. reset to using the policy defaults), and this is not
an error condition.  getprevcon() and getcon() are the exceptions; the
kernel will always return non-zero length contexts for "prev" and
"current", so this will never happen for them (and you can't set
"prev" at all and "current" cannot be set to NULL/0-length).  They
just happen to share the same underlying libselinux implementation as
the others.  So this is not a possible case and doesn't require
handling.  I suppose we could make that clearer in the man pages.

>
>
> [1]: https://github.com/systemd/systemd/commit/199a892218e1f36e7bd7d5da2d78de6b13f04488
> [2]: https://github.com/SELinuxProject/selinux/blob/4246bb550dee5246c8567804325b7da206cd76cf/libselinux/src/procattr.c#L175

      reply	other threads:[~2020-07-24 13:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 12:34 getcon family: returning success while context is NULL Christian Göttsche
2020-07-24 13:13 ` Stephen Smalley [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='CAEjxPJ5nExmrkbgMfD2B9cs-iOdSAVnNfqcqbfns10vOa31=5Q@mail.gmail.com' \
    --to=stephen.smalley.work@gmail.com \
    --cc=cgzones@googlemail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).