All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: bauen1 <j2468h@googlemail.com>, SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH] chcat: don't crash if access to binary policy is prohibited
Date: Sun, 10 May 2020 19:25:43 +0200	[thread overview]
Message-ID: <CAJfZ7=kn951BnLbJKKLKkzXaeGEnME1P=rBsczFumf3S7=3MjA@mail.gmail.com> (raw)
In-Reply-To: <d204aaea-ca46-49c2-f7cd-6f20889cecbf@gmail.com>

On Sat, May 9, 2020 at 4:06 PM bauen1 <j2468h@googlemail.com> wrote:
>
> sobject will crash if access to the binary policy is prohibited by
> selinux, e.g. refpolicy
> this also breaks file operations that don't require seobject.
>
> Signed-off-by: bauen1 <j2468h@gmail.com>

Hello,
This patch looks very hackish. In fact, an underlying issue that
exists with seobject is that "import seobject" raises an exception
when it is used from an environment that is not allowed to read the
policy:

>>> import seobject
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/seobject.py", line 33, in <module>
    import sepolicy
  File "/usr/lib/python3.8/site-packages/sepolicy/__init__.py", line
186, in <module>
    raise e
  File "/usr/lib/python3.8/site-packages/sepolicy/__init__.py", line
182, in <module>
    policy_file = get_installed_policy()
  File "/usr/lib/python3.8/site-packages/sepolicy/__init__.py", line
137, in get_installed_policy
    raise ValueError(_("No SELinux Policy installed"))
ValueError: No SELinux Policy installed

Is this the issue you encountered when you write "seobject will crash"?

In my humble opinion, trying to hide such an issue by moving "import
seobject" makes maintaining the project more difficult. I would prefer
seeing a way to allow using "import seobject" without raising
exceptions, but working on this is unfortunately quite time-consuming
(I have not seen a straightforward way to deal with this, and there
exist several ways to solve this in not-very-direct ways, for example
with lazy loading of the policy when needed or with replacing some API
with stub functions if the policy cannot be loaded).

Therefore I will not ack this patch, but I will not block ("Nack") it
if another maintainer wants to include it.

Thanks,
Nicolas

> ---
>  python/chcat/chcat | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/python/chcat/chcat b/python/chcat/chcat
> index fdd2e46e..55408577 100755
> --- a/python/chcat/chcat
> +++ b/python/chcat/chcat
> @@ -28,7 +28,6 @@ import os
>  import pwd
>  import getopt
>  import selinux
> -import seobject
>
>  PROGNAME = "policycoreutils"
>  try:
> @@ -65,6 +64,7 @@ def verify_users(users):
>
>
>  def chcat_user_add(newcat, users):
> +    import seobject
>      errors = 0
>      logins = seobject.loginRecords()
>      seusers = logins.get_all()
> @@ -144,6 +144,7 @@ def chcat_add(orig, newcat, objects, login_ind):
>
>
>  def chcat_user_remove(newcat, users):
> +    import seobject
>      errors = 0
>      logins = seobject.loginRecords()
>      seusers = logins.get_all()
> @@ -233,6 +234,7 @@ def chcat_remove(orig, newcat, objects, login_ind):
>
>
>  def chcat_user_replace(newcat, users):
> +    import seobject
>      errors = 0
>      logins = seobject.loginRecords()
>      seusers = logins.get_all()
> @@ -376,6 +378,7 @@ def listcats():
>
>
>  def listusercats(users):
> +    import seobject
>      if len(users) == 0:
>          try:
>              users.append(os.getlogin())
> --
> 2.26.2
>


  reply	other threads:[~2020-05-10 17:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 14:06 [PATCH] chcat: don't crash if access to binary policy is prohibited bauen1
2020-05-10 17:25 ` Nicolas Iooss [this message]
2020-05-29 13:16   ` Stephen Smalley
2021-02-17 21:16     ` [PATCH v2] chcat: allow usage if binary policy is inaccessible bauen1
2021-02-22 18:27       ` Petr Lautrbach
2021-02-22 20:33         ` bauen1

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='CAJfZ7=kn951BnLbJKKLKkzXaeGEnME1P=rBsczFumf3S7=3MjA@mail.gmail.com' \
    --to=nicolas.iooss@m4x.org \
    --cc=j2468h@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 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.