Bug 1077115 - avc: denied { transition } for comm="runcon" path="/usr/bin/true"
Summary: avc: denied { transition } for comm="runcon" path="/usr/bin/true"
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Beaker
Classification: Retired
Component: beah
Version: 0.16
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: 0.17.1
Assignee: Dan Callaghan
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-03-17 09:41 UTC by Alexander Todorov
Modified: 2018-02-06 00:41 UTC (History)
14 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-06-17 00:14:01 UTC
Embargoed:


Attachments (Terms of Use)

Description Alexander Todorov 2014-03-17 09:41:52 UTC
Description of problem:

Reserving a test system in Beaker with the latest (as of today) Rawhide snapshot logged the following error:


time->Mon Mar 17 04:54:25 2014
type=SYSCALL msg=audit(1395046465.294:46): arch=c000003e syscall=59 success=no exit=-13 a0=7fffd5028b7f a1=7fffd5028de8 a2=7fffd5028df8 a3=3f0b27f items=0 ppid=727 pid=772 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="runcon" exe="/usr/bin/runcon" subj=system_u:system_r:unconfined_service_t:s0 key=(null)
type=AVC msg=audit(1395046465.294:46): avc:  denied  { transition } for  pid=772 comm="runcon" path="/usr/bin/true" dev="dm-1" ino=3151630 scontext=system_u:system_r:unconfined_service_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=process


Version-Release number of selected component (if applicable):
selinux-policy-3.13.1-36.fc21.noarch

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Miroslav Grepl 2014-03-17 10:40:48 UTC
Do you know which test it causes?

Comment 4 Alexander Todorov 2014-03-18 09:42:18 UTC
I didn't find runcon in tests but in the beah harness. All in one file - wrappers.d/unconfined

function _runcon_unconfined_cmd() {
  # Determine correct SELinux context for runcon
  local suser='root'
  local srole='system_r'
  local stype='unconfined_t'
  local additional='-l s0'
  if is_rhel -ge 6 || is_fedora -ge 12; then
    suser='unconfined_u'
    srole='unconfined_r'
    additional='-l s0-s0:c0.c1023'
  elif is_rhel -le 4; then
    additional=''
  fi
  echo runcon -u $suser -r $srole -t $stype $additional
}

function runcon_unconfined() {
  local runcon_cmd=$(_runcon_unconfined_cmd)
  if $runcon_cmd -- true; then
    # Run command with SELinux context of the root
    exec $runcon_cmd -- "$@"
  else
    echo "-- WARNING: '$runcon_cmd -- true' failed. Running in default context!"
    exec "$@"
  fi
}

WRAP_NEXT=$(tortilla get-next-wrapper $(basename $0))
if selinuxenabled; then
  echo "-- INFO: selinux enabled: trying to switch context..."
  runcon_unconfined "$WRAP_NEXT" "$@"
else
  exec "$WRAP_NEXT" "$@"
fi

Comment 5 Alexander Todorov 2014-03-20 09:47:05 UTC
Miroslav,
I see the same failure with other commands:

type=SYSCALL msg=audit(1395250545.584:106): arch=40000003 syscall=11 success=no exit=-13 a0=bf9d539a a1=bf9d4d54 a2=bf9d4db0 a3=0 items=0 ppid=1659 pid=2681 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="runcon" exe="/usr/bin/runcon" subj=system_u:system_r:unconfined_service_t:s0 key=(null)
type=AVC msg=audit(1395250545.584:106): avc:  denied  { transition } for  pid=2681 comm="runcon" path="/mnt/tests/distribution/virt/install/virtinstall.exp" dev="dm-1" ino=531263 scontext=system_u:system_r:unconfined_service_t:s0 tcontext=system_u:system_r:unconfined_t:s0 tclass=process


This is from a test case which launches installation of virtual guest and virtinstall.exp is then executed to detect when the installation is complete.

Comment 6 Miroslav Grepl 2014-03-20 10:14:58 UTC
Ok what happens here is beaker is now running as unconfined_service_t instead of initrc_t. So this is a reason why you get it. 

I am not sure for what this test is? Is it a part of more tests?

Milos?

Comment 7 Daniel Walsh 2014-03-25 13:41:37 UTC
We got to get beaker back to running as initrc_t.  Does beaker always have the same entrypoint? 

We need to label the entrypoint as initrc_exec_t rather then bin_t.

Comment 8 Daniel Walsh 2014-03-25 13:42:37 UTC
Then again, maybe we should allow unconfined_service_t to transition to unconfined_t.

Comment 9 Šimon Lukašík 2014-04-04 14:12:07 UTC
I believe that running unconfined_service_t is a good thing. Further I believe it is a good thing to separate unconfined_service_t from unconfined_t.

On the other hand we need the commands in the tests to be run as unconfined_t (bug 669665).

This "runcon true" is just a noise. What the harness is trying achieve is to run the tests as unconfined (bug 669665). There must be a better (more correct) way to achieve that.

The tortilla command (see comment 4) runs the test snippets from some location. Currently, the tortilla command is run through runcon.

Proposal 
 - If the tests were labelled with unconfined_exec_t we could avoid runcon
 - If the tortilla were using some fixed location we could have unconfined_exec_t auto labeling rule (in rths.te)
 - rhts.te could allow for exec transition from (unconfined_service_t,unconfined_exec_t) to unconfined_t

(Note that there already exists custon rhts.te on each testing machine).

This seems to be more clean way than cluttering upstream policy. Hence I conclude, that this should be a bug against beaker not the policy.

Comment 10 Miroslav Grepl 2014-04-07 07:09:36 UTC
Lukas,
I agree. Not sure to which component the bug should be switched.

Comment 11 Lukas Vrabec 2014-04-07 12:02:04 UTC
Miroslav, 
I think your last comment was addressed to Simon not to me. Am I right?

Comment 12 Miroslav Grepl 2014-04-07 12:40:01 UTC
(In reply to Lukas Vrabec from comment #11)
> Miroslav, 
> I think your last comment was addressed to Simon not to me. Am I right?

Yes. I apologize.

Comment 13 Lukas Vrabec 2014-04-07 12:44:22 UTC
Ok, no problem.

Comment 14 Jakub Jelen 2014-04-15 13:30:36 UTC
After discussion with Simon, we believe that the only place where this bug can be changed is beah. I made a policy and some changes to beah files which works for us on current Fedora Rawhide in Beaker.

The core is changing context of unconfined tortilla wrapper.
Content of file beah.fc:
> /var/lib/beah/tortilla/wrappers.d/unconfined - gen_context(system_u:object_r:unconfined_exec_t,s0)

According to this change we have to allow transitions for unconfined_service_t.
Content of file beah.te:
> gen_require(`
>         type unconfined_t;
>         type unconfined_service_t;
>         type unconfined_exec_t;
> ')
> allow unconfined_service_t unconfined_exec_t:file entrypoint;
> allow unconfined_service_t unconfined_t:process transition;
> type_transition unconfined_service_t unconfined_exec_t:process unconfined_t;

This causes this tortilla wrapper is running in selinux context system_u:unconfined_r:unconfined_t and there is no need to use runcon. So I came with patch testing current selinux context and it we are in desired context, skip runcon. 
http://pastebin.test.redhat.com/203498

I implemented this as a workaround in our Fedora-to-rawhide test to see the result and it works fine.
Before: https://beaker.engineering.redhat.com/recipes/1312044
After: https://beaker.engineering.redhat.com/recipes/1313389

Only problem can be that user is still system_u, so I would like to ask Miroslav for policy correction to achieve unconfined_u and see the same results like runcon did.

Also I would like to ask people from Beaker to take a look at this bugzilla.

Comment 16 Miroslav Grepl 2014-04-16 14:09:38 UTC
(In reply to Jakub Jelen from comment #14)
> After discussion with Simon, we believe that the only place where this bug
> can be changed is beah. I made a policy and some changes to beah files which
> works for us on current Fedora Rawhide in Beaker.
> 
> The core is changing context of unconfined tortilla wrapper.
> Content of file beah.fc:
> > /var/lib/beah/tortilla/wrappers.d/unconfined - gen_context(system_u:object_r:unconfined_exec_t,s0)
> 
> According to this change we have to allow transitions for
> unconfined_service_t.
> Content of file beah.te:
> > gen_require(`
> >         type unconfined_t;
> >         type unconfined_service_t;
> >         type unconfined_exec_t;
> > ')
> > allow unconfined_service_t unconfined_exec_t:file entrypoint;
> > allow unconfined_service_t unconfined_t:process transition;
> > type_transition unconfined_service_t unconfined_exec_t:process unconfined_t;
> 
> This causes this tortilla wrapper is running in selinux context
> system_u:unconfined_r:unconfined_t and there is no need to use runcon. So I
> came with patch testing current selinux context and it we are in desired
> context, skip runcon. 
> http://pastebin.test.redhat.com/203498
> 
> I implemented this as a workaround in our Fedora-to-rawhide test to see the
> result and it works fine.
> Before: https://beaker.engineering.redhat.com/recipes/1312044
> After: https://beaker.engineering.redhat.com/recipes/1313389
> 
> Only problem can be that user is still system_u, so I would like to ask
> Miroslav for policy correction to achieve unconfined_u and see the same
> results like runcon did.

You don't care about "system_u" in targeted policy. This part of SELinux context is inherited from

SYSTEM_U:system_r:unconfined_service_t:s0-s0:c0.c1023

process in this case.

> 
> Also I would like to ask people from Beaker to take a look at this bugzilla.

Comment 17 Nick Coghlan 2014-05-06 04:21:02 UTC
After reading through the bug, I'm not clear on the exact request for Beaker here. Change the "unconfined" wrapper to skip calling runcon if the context is already correct, as Jakub suggests?

Or something else?

Comment 18 Šimon Lukašík 2014-05-06 06:59:14 UTC
Solution are two modification of beah:

 (1) Start shipping beah selinux policy (beah.te, beah.fc) as described by Jakub
 (2) Modify unconfined wrapper to skip runcon, when the process
     is already unconfined.

Jakub has tested this solution on various releases Fedora/RHEL.

Does it sound reasonable to beah upstream?

Comment 19 Jakub Jelen 2014-05-06 08:55:25 UTC
Just to correct Simon, we test this on Fedora Rawhide.

* This is because the change of running context of beaker (initrc_t -> unconfined_service_t).
* Other distributions still runs as initrc_t.

But in other points, Simon is correct. We would like to add selinux policy and modify unconfined wrapper:

And during last days we found one typo (there should be two dashes):

Content of file beah.fc:
> /var/lib/beah/tortilla/wrappers.d/unconfined -- gen_context(system_u:object_r:unconfined_exec_t,s0)

Comment 20 Jakub Jelen 2014-05-30 10:52:30 UTC
And yes,
this is the point:
 * Change selinux context of unconfined wrapper (the above mentioned policy).
 * Modify wrapper not to call runcon, if we are in target context.

And it is again almost one month untouched. Or is there something else what is not certain?

Comment 21 Nick Coghlan 2014-06-02 04:56:46 UTC
Thanks for the nudge Jacob - I had missed the replies above and hadn't added the bug to the accepted list.

I've now added it, and it should be addressed in the next beah release (currently expected later this month).

Comment 22 Dan Callaghan 2014-06-03 06:13:23 UTC
(In reply to Jakub Jelen from comment #20)
>  * Modify wrapper not to call runcon, if we are in target context.

Any hints about what this code should look like? Is there anything better than just

    if [[ $(runcon | cut -d: -f3) == "unconfined_t" ]] ; then
        exit 0
    fi

or similar?

The pastebinned patch mentioned in comment 14 seems to have expired, it comes up empty for me.

Comment 23 Dan Callaghan 2014-06-03 06:23:41 UTC
(In reply to Dan Callaghan from comment #22)

Obviously it can't just exit 0, because of all the tortilla wrapping business... I more meant, is there any better way to check the current context type besides runcon | cut?

Comment 24 Jakub Jelen 2014-06-03 06:29:07 UTC
yes, it expired, thank you for notice. I made new pastebin with diff we are using:

http://pastebin.test.redhat.com/212856

You can skip the first "id -Z" - this is just test output.

Comment 25 Dan Callaghan 2014-06-03 07:47:39 UTC
On Gerrit: http://gerrit.beaker-project.org/3125

Jakub, can you please take a look and see if there's anything I've missed? So far I have only tested that it builds properly, tomorrow I will check if it actually works :-)

Comment 29 xuezhi ma 2014-06-13 03:04:02 UTC
filled a new bug to track the anaconda problem that block the testing, bug 1108973

Comment 32 Amit Saha 2014-06-17 00:14:01 UTC
Beah 0.7.5 has been released on beaker-project.org.

Comment 33 Jakub Jelen 2015-05-26 08:59:09 UTC
Seems to be back here with Fedora 22 [1]. I was hoping that it will fix with final release, but not. Seems like the same issue as bz1149988.

Shall I clone it to Fedora/Beaker give it proper attention? Seems like workaround presented in c43 [2] works for me [3], but it would be great to have it in Beah/SELinux policy/somewhere so I would not have to workaround for every Fedora run in Beaker.

[1] https://beaker.engineering.redhat.com/jobs/964842
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1149988#c43
[3] https://beaker.engineering.redhat.com/jobs/964924

Comment 34 Pavel Studeník 2015-06-02 11:46:35 UTC
I clone your jobs and currently it[1] is failed.

https://beaker.engineering.redhat.com/jobs/970106

type=AVC msg=audit(1433245218.243:113): avc:  denied  { transition } for  pid=778 comm="runcon" path="/usr/bin/true" dev="dm-0" ino=1576042 scontext=system_u:system_r:unconfined_service_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=process permissive=0

Comment 35 Šimon Lukašík 2015-06-03 12:50:51 UTC
Pavel, perhaps you've wanted to re-open the bug?

Comment 36 Pavel Studeník 2015-06-03 13:10:00 UTC
I wanted, but I found current bug 1225007.


Note You need to log in before you can comment on or make changes to this bug.