All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bond Masuda <bond.masuda@jlbond.com>
To: Stephen Smalley <sds@tycho.nsa.gov>, selinux@tycho.nsa.gov
Subject: Re: How do you relabel all SELinux file contexts of an offline system's file system?
Date: Mon, 17 Aug 2015 16:27:49 -0700	[thread overview]
Message-ID: <55D26DF5.3010203@jlbond.com> (raw)
In-Reply-To: <55CC9A6D.5040005@tycho.nsa.gov>



On 08/13/2015 06:23 AM, Stephen Smalley wrote:
>>
>> Ok, figured this one out mostly, I think. Thanks to manpage
>> setfiles_selinux, I first had to set setfiles_mac_t to permissive with:
>>
>> semanage permissive -a setfiles_mac_t
> That suggests that setfiles_mac_t policy needs to be augmented with
> further allow rules; you can tell which ones based on ausearch -m AVC
> -se setfiles_mac_t
>
Ok. so on Fedora 21, (using
selinux-policy-targeted-3.13.1-105.20.fc21.noarch), it looks like I need
this:

# ausearch -m AVC -se setfiles_mac_t | audit2allow


#============= setfiles_mac_t ==============
allow setfiles_mac_t bin_t:file entrypoint;


>> Then, I ran the setfiles commands under runcon as:
>>
>> runcon -t setfiles_mac_t -- chroot /mnt /sbin/setfiles -v -F -e /proc -e
>> /sys -e /dev -e /selinux
>> /etc/selinux/targeted/contexts/files/file_contexts /
>>
>> This fixes the previous "invalid argument" errors from setfiles.
> I think those errors reflect a bug/gap in setfiles.  Usually setfiles
> validates and canonicalizes the contexts in file_contexts by writing
> them to /sys/fs/selinux/context (a pseudo file) and reading back the
> result.  This will fail if selinuxfs is mounted in your chroot and your
> host policy doesn't define the context.  If selinuxfs is not mounted in
> your chroot, then this will just create a regular file under
> /sys/fs/selinux/context containing the context and read it back again,
> so it will "pass".  I'm guessing that it was failing in enforcing mode
> because it wasn't allowed to create files under /sys/fs/selinux in the
> chroot.  I think we need a change to setfiles (e.g. a new option) to
> fully disable this validation/canonicalization.

That would seem useful in my use-case.
>
>> this process, there are still 2 labels that are wrong:
>>
>> [root@localhost ~]# restorecon -v -n -r /
>> restorecon reset / context system_u:runcon -t setfiles_mac_t -- getfattr -n security.selinux /mnt/rootobject_r:mnt_t:s0->system_u:object_r:root_t:s0
>> restorecon reset /.autofsck context system_u:object_r:mnt_t:s0->system_u:object_r:etc_runtime_t:s0
>>
>> I think the /.autofsck is getting created during boot, and maybe just
>> inheriting from /. So, the question is why is / (root) still labeled as
>> mnt_t instead of root_t ? When the system is still mounted under
>> /mnt/test, /mnt/test (where / of the system is mounted) is correctly
>> labeled as root_t, but this seems to change once unmounted and i boot
>> the offline system?
>>
>> Any insights?
> No, that seems very strange.  How did you check the context of /mnt/root
> before unmounting it?  Try checking it this way:
> runcon -t setfiles_mac_t -- getfattr -n security.selinux /mnt/root
>
> And likewise, once you unmount and reboot the offline system, try it as:
> runcon -t setfiles_mac_t -- getfattr -n security.selinux /
>
This turned out to be an error due to an external process. The labeling
of /mnt/root is in fact correct. We are building a system in /mnt/root,
and when we use the recovery boot option from the install DVD, it
appears to relabel / to mnt_t. We did this in order to setup grub in the
bootsector. We noticed this because when we automated the grub-install
w/o using the recovery DVD, / was labeled correctly as expected.

Thanks for your help!
-Bond

  reply	other threads:[~2015-08-17 23:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04 22:33 How do you relabel all SELinux file contexts of an offline system's file system? Bond Masuda
2015-08-05  6:54 ` Jason Zaman
2015-08-05 12:37   ` Stephen Smalley
2015-08-12  1:02   ` Bond Masuda
2015-08-12  3:37     ` Bond Masuda
2015-08-12  8:46       ` 答复: " rowan
2015-08-12  9:07       ` Bond Masuda
2015-08-13 13:23         ` Stephen Smalley
2015-08-17 23:27           ` Bond Masuda [this message]
2015-08-18 12:43             ` Daniel J Walsh

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=55D26DF5.3010203@jlbond.com \
    --to=bond.masuda@jlbond.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /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.