MIME-Version: 1.0 In-Reply-To: <1257802044.31440.4.camel@localhost> References: <81092d890911041557u78860e4ar65d2a1eb6964656e@mail.gmail.com> <4AF482CA.4090109@tycho.nsa.gov> <81092d890911061239t22c15f7p9aa4c907962de8cf@mail.gmail.com> <20091106221120.GA4921@notebook3.grift.internal> <4AF4AFFC.9060505@tycho.nsa.gov> <81092d890911091254g1b9616e6l54d352ab51610b07@mail.gmail.com> <1257802044.31440.4.camel@localhost> Date: Tue, 10 Nov 2009 15:54:25 -0800 Message-ID: <81092d890911101554u37233080q43523f3069b93a2e@mail.gmail.com> Subject: Re: "security_compute_sid: invalid context" error when starting/stopping mysqld daemon From: Larry Ross To: selinux@tycho.nsa.gov Cc: Eamon Walsh , Dominick Grift , paul@city-fan.org Content-Type: multipart/alternative; boundary=001485e9aa08b4232c04780d0763 Sender: owner-selinux@tycho.nsa.gov List-Id: selinux@tycho.nsa.gov --001485e9aa08b4232c04780d0763 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 9, 2009 at 1:27 PM, Dominick Grift wrote: > On Mon, 2009-11-09 at 12:54 -0800, Larry Ross wrote: > > On Fri, Nov 6, 2009 at 3:23 PM, Eamon Walsh > > wrote: > > > > On 11/06/2009 05:11 PM, Dominick Grift wrote: > > > On Fri, Nov 06, 2009 at 12:39:57PM -0800, Larry Ross wrote: > > > > > >> On Fri, Nov 6, 2009 at 12:10 PM, Eamon Walsh > > wrote: > > >> > > >> > > >>> On 11/04/2009 06:57 PM, Larry Ross wrote: > > >>> > > >>>> I have two selinux users that need to be able to stop and > > start the > > >>>> mysql daemon, which is started by the initialization > > scripts. When > > >>>> the daemon is stopped and started by the secadm_u user, > > it ends up in > > >>>> the context secadm_u:secadm_r:mysqld_t. When it is > > stopped and > > >>>> started by the dbadm_u user, it ends up in the > > >>>> dbadm_u:dbadm_r:mysqld_t context. When it is started by > > the init > > >>>> scripts it ends up in the system_u:system_r:mysqld_t > > domain. > > >>>> > > >>>> I would like it to alway end up in the system_r:mysqld_t > > domain, but > > >>>> can't seem to find any documentation that describes how > > to get that to > > >>>> work. > > >>>> > > >>>> If I add a role_transition rule to transition the role to > > system_r > > >>>> when the executable is run: > > >>>> role_transition sysadm_r mysqld_safe_exec_t system_r; > > >>>> role_transition dbadm_r mysqld_safe_exec_t system_r; > > >>>> I end up getting these errors: > > >>>> > > >>>> Nov 4 15:41:36 localhost kernel: type=1401 > > audit(1257378096.775:46): > > >>>> security_compute_sid: invalid context > > >>>> dbadm_u:system_r:mysqld_safe_t:s0 for > > >>>> scontext=dbadm_u:dbadm_r:initrc_t:s0 > > >>>> tcontext=system_u:object_r:mysqld_safe_exec_t:s0 > > tclass=process > > >>>> > > >>>> I believe I have the rules that should allow this, but > > obviously I am > > >>>> missing something. > > >>>> role dbadm_r types mysqld_safe_t; > > >>>> role sysadm_r types mysqld_safe_t; > > >>>> role system_r types mysqld_safe_t; > > >>>> and this: > > >>>> allow initrc_t mysqld_safe_t : process transition ; > > >>>> which is what the "security_compute_sid" message looks > > like it is > > >>>> > > >>> missing. > > >>> > > >>>> Does anyone know where I can find a good description of > > how to get a > > >>>> service to transistion back into system_r when started by > > a user or > > >>>> have any idea what I am missing? > > >>>> > > >>> > > >>> The run_init program was designed to solve this problem, > > take a look at > > >>> the man page. > > >>> > > >>> On Fedora at least, the "service" command calls run_init > > internally, so > > >>> doing "service mysqld start" should in theory start it up > > in the > > >>> system_r role. If you're just running "/etc/init.d/mysld > > start" it > > >>> won't transition. > > >>> > > >>> > > >> That would be great, but I am trying to use this as normal > > users on a system > > >> to which the root account is locked. As far as I know, > > run_init always asks > > >> for the root password. Is there a way to use it without > > having access to > > >> the root password? > > >> > > > I think you can use pam_rootok in /etc/pam.d/run_init. I > > dont know the details of the top of my head because i use > > Fedora and the policy that i posted earlier so that i > > automatically transition to initrc_t without run_init. > > > > > > > > > > > Yes, /etc/pam.d/run_init controls the password check done by > > run_init. > > Also, it only asks for the password of whatever user is > > running it, not > > always the root password. The only reason it asks for a > > password is to > > verify that a human is present. > > > > "run_init id -Z" from sysadm_r should print out > > "system_u:system_r:initrc_t". Other roles might need the > > following line > > of policy to be able to run run_init (using the example of > > staff): > > > > seutil_run_runinit(staff_t, staff_r) > > > > The policy snippet Dominick posted earlier also works. > > > > I get a syntax error when I try to use that snippet: > > > > # make -f /usr/share/selinux/devel/Makefile > > Compiling strict appmysql module > > /usr/bin/checkmodule: loading policy configuration from > > tmp/appmysql.tmp > > appmysql.te:62:ERROR 'syntax error' at token > > 'init_labeled_script_domtrans' on line 92695: > > init_labeled_script_domtrans(mysqld_safe_t, mysqld_safe_exec_t) > > /usr/bin/checkmodule: error(s) encountered while parsing > > configuration > > make: *** [tmp/appmysql.mod] Error 1 > > > > is init_labeled_script_domtrans defined for RHEL 5.3? I see it used > > in the files below: > > > > /usr/src/redhat/BUILD/serefpolicy-2.4.6/policy/modules/services/virt.if: > init_labeled_script_domtrans($1, virtd_initrc_exec_t) > > /usr/src/redhat/BUILD/serefpolicy-2.4.6/policy/modules/services/avahi.if: > init_labeled_script_domtrans($1, avahi_initrc_exec_t) > > > /usr/src/redhat/BUILD/serefpolicy-2.4.6/policy/modules/services/spamassassin.if: > init_labeled_script_domtrans($1,spamd_script_exec_t) > > > > but I don't see it defined anywhere. > > If it is there then it should be defined in init.if. > > You could simply add this to your mysqladm interface file: > > ######################################## > ## > ## Transition to the init script domain > ## on a specified labeled init script. > ## > ## > ## > ## Domain allowed access. > ## > ## > ## > ## > ## Labeled init script file. > ## > ## > # > interface(`init_labeled_script_domtrans',` > gen_require(` > type initrc_t; > ') > > domtrans_pattern($1, $2, initrc_t) > files_search_etc($1) > ') > > That should atleast make it work for that module. Hopefully the other > policy in the snippit is supported. > I have seen this before, and I find it confusing, I get denials: Nov 10 15:03:43 localhost kernel: type=1400 audit(1257894223.988:43): avc: denied { transition } for pid=3799 comm="mysql" path="/usr/bin/mysqld_safe" dev=dm-1 ino=460035 scontext=app_dbadm_u:app_dbadm_r:initrc_t:s0 tcontext=app_dbadm_u:system_r:mysqld_safe_t:s0 tclass=process I run that denial through audit2allow and I get this: #============= initrc_t ============== allow initrc_t mysqld_safe_t:process transition; That rule is already present in the policy: allow initrc_t mysqld_safe_t:process transition; Can anyone tell me why this happens? Am I missing something? Is audit2allow confused? Is the rule not being honored for some reason? -- Larry > > -- Larry > > > > > > > > > > > > > > BTW, I am using RHEL 5.3, do you know if service there calls > > run_init > > > internally? > > > > > > I was mistaken about this, as pointed out by Paul, service > > doesn't call > > run_init. > > > > > > > > -- > > > > > > Eamon Walsh > > National Security Agency > > > > > > > > > --001485e9aa08b4232c04780d0763 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Mon, Nov 9, 2009 at 1:27 PM, Dominick Grift <= span dir=3D"ltr"><domg472@gmail.com= > wrote:
On Mon, 2009-11-09 at 12:54 -0800, Larry Ross wrote:
&= gt; On Fri, Nov 6, 2009 at 3:23 PM, Eamon Walsh <ewalsh@tycho.nsa.gov>
> wrote:
>
>= ; =A0 =A0 =A0 =A0 On 11/06/2009 05:11 PM, Dominick Grift wrote:
> =A0 =A0 =A0 =A0 > On Fri, Nov 06, 2009 at 12:39:57PM -0800, Larry R= oss wrote:
> =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 >> On= Fri, Nov 6, 2009 at 12:10 PM, Eamon Walsh
> =A0 =A0 =A0 =A0 <ewalsh@tycho.nsa.gov> wrote:
> =A0 =A0 =A0 =A0 >>
> =A0 =A0 =A0 =A0 >>
> =A0 = =A0 =A0 =A0 >>> =A0On 11/04/2009 06:57 PM, Larry Ross wrote:
&g= t; =A0 =A0 =A0 =A0 >>>
> =A0 =A0 =A0 =A0 >>>> I = have two selinux users that need to be able to stop and
> =A0 =A0 =A0 =A0 start the
> =A0 =A0 =A0 =A0 >>>> mys= ql daemon, which is started by the initialization
> =A0 =A0 =A0 =A0 s= cripts. =A0When
> =A0 =A0 =A0 =A0 >>>> the daemon is stop= ped and started by the secadm_u user,
> =A0 =A0 =A0 =A0 it ends up in
> =A0 =A0 =A0 =A0 >>>>= the context secadm_u:secadm_r:mysqld_t. =A0When it is
> =A0 =A0 =A0 = =A0 stopped and
> =A0 =A0 =A0 =A0 >>>> started by the dba= dm_u user, it ends up in the
> =A0 =A0 =A0 =A0 >>>> dbadm_u:dbadm_r:mysqld_t context. =A0= When it is started by
> =A0 =A0 =A0 =A0 the init
> =A0 =A0 =A0 = =A0 >>>> scripts it ends up in the system_u:system_r:mysqld_t> =A0 =A0 =A0 =A0 domain.
> =A0 =A0 =A0 =A0 >>>>
> =A0 =A0 =A0 =A0 >>>&= gt; I would like it to alway end up in the system_r:mysqld_t
> =A0 = =A0 =A0 =A0 domain, but
> =A0 =A0 =A0 =A0 >>>> can't = seem to find any documentation that describes how
> =A0 =A0 =A0 =A0 to get that to
> =A0 =A0 =A0 =A0 >>>>= ; work.
> =A0 =A0 =A0 =A0 >>>>
> =A0 =A0 =A0 =A0 &g= t;>>> If I add a role_transition rule to transition the role to> =A0 =A0 =A0 =A0 system_r
> =A0 =A0 =A0 =A0 >>>> whe= n the executable is run:
> =A0 =A0 =A0 =A0 >>>> role_transition sysadm_r mysqld_safe_= exec_t system_r;
> =A0 =A0 =A0 =A0 >>>> role_transition d= badm_r =A0mysqld_safe_exec_t system_r;
> =A0 =A0 =A0 =A0 >>>= > I end up getting these errors:
> =A0 =A0 =A0 =A0 >>>>
> =A0 =A0 =A0 =A0 >>>&= gt; Nov =A04 15:41:36 localhost kernel: type=3D1401
> =A0 =A0 =A0 =A0= audit(1257378096.775:46):
> =A0 =A0 =A0 =A0 >>>> securit= y_compute_sid: =A0invalid context
> =A0 =A0 =A0 =A0 >>>> dbadm_u:system_r:mysqld_safe_t:s0 for=
> =A0 =A0 =A0 =A0 >>>> scontext=3Ddbadm_u:dbadm_r:initrc= _t:s0
> =A0 =A0 =A0 =A0 >>>> tcontext=3Dsystem_u:object_r= :mysqld_safe_exec_t:s0
> =A0 =A0 =A0 =A0 tclass=3Dprocess
> =A0 =A0 =A0 =A0 >>>&= gt;
> =A0 =A0 =A0 =A0 >>>> I believe I have the rules tha= t should allow this, but
> =A0 =A0 =A0 =A0 obviously I am
> =A0= =A0 =A0 =A0 >>>> missing something.
> =A0 =A0 =A0 =A0 >>>> role dbadm_r types mysqld_safe_t;
= > =A0 =A0 =A0 =A0 >>>> role sysadm_r types mysqld_safe_t;> =A0 =A0 =A0 =A0 >>>> role system_r types mysqld_safe_t;> =A0 =A0 =A0 =A0 >>>> and this:
> =A0 =A0 =A0 =A0 >>>> allow initrc_t mysqld_safe_t : proces= s transition ;
> =A0 =A0 =A0 =A0 >>>> which is what the &= quot;security_compute_sid" message looks
> =A0 =A0 =A0 =A0 like = it is
> =A0 =A0 =A0 =A0 >>>>
> =A0 =A0 =A0 =A0 >>> missing.
> =A0 =A0 =A0 =A0 >>= >
> =A0 =A0 =A0 =A0 >>>> Does anyone know where I can = find a good description of
> =A0 =A0 =A0 =A0 how to get a
> =A0= =A0 =A0 =A0 >>>> service to transistion back into system_r whe= n started by
> =A0 =A0 =A0 =A0 a user or
> =A0 =A0 =A0 =A0 >>>> hav= e any idea what I am missing?
> =A0 =A0 =A0 =A0 >>>>
&= gt; =A0 =A0 =A0 =A0 >>>
> =A0 =A0 =A0 =A0 >>> The r= un_init program was designed to solve this problem,
> =A0 =A0 =A0 =A0 take a look at
> =A0 =A0 =A0 =A0 >>> th= e man page.
> =A0 =A0 =A0 =A0 >>>
> =A0 =A0 =A0 =A0 &g= t;>> On Fedora at least, the "service" command calls run_in= it
> =A0 =A0 =A0 =A0 internally, so
> =A0 =A0 =A0 =A0 >>> doing "service mysqld start" sh= ould in theory start it up
> =A0 =A0 =A0 =A0 in the
> =A0 =A0 = =A0 =A0 >>> system_r role. =A0If you're just running "/et= c/init.d/mysld
> =A0 =A0 =A0 =A0 start" it
> =A0 =A0 =A0 =A0 >>> won't transition.
> =A0 =A0 =A0= =A0 >>>
> =A0 =A0 =A0 =A0 >>>
> =A0 =A0 =A0 = =A0 >> That would be great, but I am trying to use this as normal
= > =A0 =A0 =A0 =A0 users on a system
> =A0 =A0 =A0 =A0 >> to which the root account is locked. =A0As fa= r as I know,
> =A0 =A0 =A0 =A0 run_init always asks
> =A0 =A0 = =A0 =A0 >> for the root password. =A0Is there a way to use it without=
> =A0 =A0 =A0 =A0 having access to
> =A0 =A0 =A0 =A0 >> the root password?
> =A0 =A0 =A0 =A0 &g= t;>
> =A0 =A0 =A0 =A0 > I think you can use pam_rootok in /etc/= pam.d/run_init. I
> =A0 =A0 =A0 =A0 dont know the details of the top = of my head because i use
> =A0 =A0 =A0 =A0 Fedora and the policy that i posted earlier so that i<= br>> =A0 =A0 =A0 =A0 automatically transition to initrc_t without run_in= it.
> =A0 =A0 =A0 =A0 >
>
>
>
> =A0 =A0 = =A0 =A0 Yes, /etc/pam.d/run_init controls the password check done by
> =A0 =A0 =A0 =A0 run_init.
> =A0 =A0 =A0 =A0 Also, it only asks f= or the password of whatever user is
> =A0 =A0 =A0 =A0 running it, not=
> =A0 =A0 =A0 =A0 always the root password. =A0The only reason it as= ks for a
> =A0 =A0 =A0 =A0 password is to
> =A0 =A0 =A0 =A0 verify that a human is present.
>
> =A0 = =A0 =A0 =A0 "run_init id -Z" from sysadm_r should print out
&g= t; =A0 =A0 =A0 =A0 "system_u:system_r:initrc_t". =A0Other roles m= ight need the
> =A0 =A0 =A0 =A0 following line
> =A0 =A0 =A0 =A0 of policy to be able to run run_init (using the exampl= e of
> =A0 =A0 =A0 =A0 staff):
>
> =A0 =A0 =A0 =A0 seutil= _run_runinit(staff_t, staff_r)
>
> =A0 =A0 =A0 =A0 The policy s= nippet Dominick posted earlier also works.
>
> I get a syntax error when I try to use that snippet:
>> # make -f /usr/share/selinux/devel/Makefile
> Compiling strict= appmysql module
> /usr/bin/checkmodule: =A0loading policy configurat= ion from
> tmp/appmysql.tmp
> appmysql.te:62:ERROR 'syntax error' a= t token
> 'init_labeled_script_domtrans' on line 92695:
&g= t; init_labeled_script_domtrans(mysqld_safe_t, mysqld_safe_exec_t)
> = /usr/bin/checkmodule: =A0error(s) encountered while parsing
> configuration
> make: *** [tmp/appmysql.mod] Error 1
>
= > is init_labeled_script_domtrans defined for RHEL 5.3? =A0I see it used=
> in the files below:
>
> /usr/src/redhat/BUILD/serefpol= icy-2.4.6/policy/modules/services/virt.if: =A0 =A0 =A0 =A0init_labeled_scri= pt_domtrans($1, virtd_initrc_exec_t)
> /usr/src/redhat/BUILD/serefpolicy-2.4.6/policy/modules/services/avahi.= if: =A0 =A0 =A0 init_labeled_script_domtrans($1, avahi_initrc_exec_t)
&g= t; /usr/src/redhat/BUILD/serefpolicy-2.4.6/policy/modules/services/spamassa= ssin.if: =A0 =A0 =A0 =A0init_labeled_script_domtrans($1,spamd_script_exec_t= )
>
> but I don't see it defined anywhere.

If= it is there then it should be defined in init.if.

You could simply = add this to your mysqladm interface file:

##########################= ##############
## <summary>
## =A0 =A0 =A0Transition to the init script domain## =A0 =A0 =A0on a specified labeled init script.
## </summary>## <param name=3D"domain">
## =A0 =A0 =A0<summary&g= t;
## =A0 =A0 =A0Domain allowed access.
## =A0 =A0 =A0</summary>
## </param>
## <param name=3D= "init_script_file">
## =A0 =A0 =A0<summary>
## =A0= =A0 =A0Labeled init script file.
## =A0 =A0 =A0</summary>
## &= lt;/param>
#
interface(`init_labeled_script_domtrans',`
=A0 =A0 =A0 =A0gen_requir= e(`
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0type initrc_t;
=A0 =A0 =A0 =A0'= ;)

=A0 =A0 =A0 =A0domtrans_pattern($1, $2, initrc_t)
=A0 =A0 =A0 = =A0files_search_etc($1)
')

That should atleast make it work f= or that module. Hopefully the other
policy in the snippit is supported.
=A0
I have seen this before, and I find it confusing, I get denials:
=A0
Nov 10 15:03:43 localhost kernel: type=3D1400 audit(1257894223.988:43)= : avc:=A0 denied=A0 { transition } for=A0 pid=3D3799 comm=3D"mysql&quo= t; path=3D"/usr/bin/mysqld_safe" dev=3Ddm-1 ino=3D460035 scontext= =3Dapp_dbadm_u:app_dbadm_r:initrc_t:s0 tcontext=3Dapp_dbadm_u:system_r:mysq= ld_safe_t:s0 tclass=3Dprocess
I run that denial through audit2allow and I get this:
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D initrc_t =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D
allow initrc_t mysqld_safe_t:process transition= ;
That rule is already present in the policy:
allow initrc_t mysqld_safe_t:process transition;
Can anyone tell me why this happens?=A0 Am I missing something?=A0 Is = audit2allow confused?=A0 Is the rule not being honored for some reason?
=A0
=A0 -- Larry
=A0
=A0
=A0
> =A0 -- Larry
>
>
>
>
>= =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 > BTW, I am using RHEL 5.3= , do you know if service there calls
> =A0 =A0 =A0 =A0 run_init
&g= t; =A0 =A0 =A0 =A0 > internally?
>
>
> =A0 =A0 =A0 =A0 I was mistaken about this, as pointed = out by Paul, service
> =A0 =A0 =A0 =A0 doesn't call
> =A0 = =A0 =A0 =A0 run_init.
>
>
>
> =A0 =A0 =A0 =A0 -->
>
> =A0 =A0 =A0 =A0 Eamon Walsh
> =A0 =A0 =A0 =A0 National Security Agency
>
>
>


--001485e9aa08b4232c04780d0763-- -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with the words "unsubscribe selinux" without quotes as the message.