learning about policies/transitions
Hi,
I've been trying (on and off for some time) to get a very simple test policy working on a FC2 selinux system. I just want it to have the following types:
boot_d: default domain login_d: domain automatically entered by /bin/login user_d: domain voluntarily entered by login_d obj_t: type for all fs objects login_et: type for /bin/login
The policy files are attached. I did
checkpolicy -o basic.bin basic.pol cp basic.bin /etc/security/selinux/policy.17 (boot with selinux=0)
setfiles basic.ctx /
Doing these same steps with /etc/security/selinux/src/policy/policy.conf and /etc/security/selinux/src/policy/file_contexts/file_contexts results in a working selinux system.
With my basic policy, though, boot_d will not transition to login_d on execution of /bin/login. ls -Z /bin/login shows that it is labeled as login_et. Since logging in doesn't work, I test by booting single user mode, and running
ps -Z
[everything is running under boot_d]/bin/login & ps -Z
[login is running under boot_d]
What am I missing in the policy that would enable this automatic domain transition to happen?
thanks,
-serge
Quoted 5 lines · Serge Hallyn
With my basic policy, though,
boot_dwill not transition tologin_don execution of/bin/login. ls -Z/bin/loginshows that it is labeled aslogin_et. Since logging in doesn't work, I test by booting single user mode, and running
Quoted 7 lines
ps -Z
[everything is running underboot_d]/bin/login& ps -Z
[login is running underboot_d]What am I missing in the policy that would enable this automatic domain transition to happen?
Your policy looks sufficient for that purpose, although there are some oddities in it (e.g. you shouldn't be authorizing system_r for object types, you should be using object_r in file contexts, a file descriptor is not labeled with a file type). A possible explanation would be an inconsistency between the on-disk xattr and the incore inode SID, e.g. type wasn't defined at the time that the inode was attached to a dentry. Try setfilecon system_u:object_r:login_et /bin/login and then re-trying. setfiles and chcon tend to not bother setting the context if it already appears to be correct, but they only can see the on-disk xattr via the xattr API, not the incore inode context.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Ah, running setfilecon worked.
I don't understand why, though. The security.selinux xattr (as given by getxattr(2)) looked the same before and after. What else is being changed by setfilecon?
Thanks!
-serge
Quoted 11 lines
Your policy looks sufficient for that purpose, although there are some oddities in it (e.g. you shouldn't be authorizing
system_rfor object types, you should be usingobject_rin file contexts, a file descriptor is not labeled with a file type). A possible explanation would be an inconsistency between the on-disk xattr and the incore inode SID, e.g. type wasn't defined at the time that the inode was attached to a dentry. Try setfilecon system_u:object_r:login_et/bin/loginand then re-trying. setfiles and chcon tend to not bother setting the context if it already appears to be correct, but they only can see the on-disk xattr via the xattr API, not the incore inode context.
Quoted 5 lines
--
Stephen Smalley <[email protected]>
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Serge Hallyn
Ah, running setfilecon worked.
I don't understand why, though. The security.selinux xattr (as given by getxattr(2)) looked the same before and after. What else is being changed by setfilecon?
The incore inode SID. setfilecon(1) unconditionally calls setfilecon(3), which invokes setxattr(2), which will invoke the post_setxattr hook and update the incore inode SID. setfiles and/or chcon would have just looked at the existing on-disk xattr value (via getfilecon(3)->getxattr(2)), seen that the on-disk xattr was already correct, and not bothered to call setfilecon(3), so the incore inode SID wasn't being updated by those programs. I think RedHat is/has added an option to chcon(1) to force the call to setfilecon(3) regardless of its current value. Perhaps setfiles(1) should unconditionally call setfilecon(3) too.
This is an unfortunate side effect of using the xattr API (vs. the original SELinux API, which directly fetched the incore inode SID and returned it to the caller), because the xattr API always consults the filesystem and reports the on-disk xattr. SELinux maps the on-disk xattr to a SID at the time of d_instantiate, but if the on-disk xattr is invalid at that time (e.g. type isn't defined in the policy), then the inode SID is left unlabeled and it requires an explicit setxattr(2) to correct.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Addendum: running setfilecon works once. After each reboot, I must again run setfilecon.before /bin/login will cause the transition to login_d. Again, running/bin/ls -Z /bin/login shows no difference before and after the setifilecon - it is always
of type login_et.
At this point, I suppose I should just switch to the latest fedora deverlopment release and see whether this problem magically resolves itself. If not, I guess some
debug info at d_instantiate will be order.
thanks,
-serge
Quoted 27 lines · Stephen Smalley
Quoted 5 lines · Serge Hallyn
Ah, running setfilecon worked.
I don't understand why, though. The security.selinux xattr (as given by getxattr(2)) looked the same before and after. What else is being changed by setfilecon?
The incore inode SID. setfilecon(1) unconditionally calls setfilecon(3), which invokes setxattr(2), which will invoke the
post_setxattrhook and update the incore inode SID. setfiles and/or chcon would have just looked at the existing on-disk xattr value (via getfilecon(3)->getxattr(2)), seen that the on-disk xattr was already correct, and not bothered to call setfilecon(3), so the incore inode SID wasn't being updated by those programs. I think RedHat is/has added an option to chcon(1) to force the call to setfilecon(3) regardless of its current value. Perhaps setfiles(1) should unconditionally call setfilecon(3) too.This is an unfortunate side effect of using the xattr API (vs. the original SELinux API, which directly fetched the incore inode SID and returned it to the caller), because the xattr API always consults the filesystem and reports the on-disk xattr. SELinux maps the on-disk xattr to a SID at the time of
d_instantiate, but if the on-disk xattr is invalid at that time (e.g. type isn't defined in the policy), then the inode SID is left unlabeled and it requires an explicit setxattr(2) to correct.
Quoted 7 lines
--
Stephen Smalley <[email protected]>
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 6 lines · Serge Hallyn
Addendum: running setfilecon works once. After each reboot, I must again run setfilecon.before
/bin/loginwill cause the transition tologin_d. Again, running/bin/ls-Z/bin/loginshows no difference before and after the setifilecon - it is always
of typelogin_et.
Two scenarios:
1) At boot time (e.g. usual policy load by /sbin/init), you are loading a policy that does not define login_et, /bin/login inode is brought incore and mapped to the unlabeled SID, and you then load a policy that does define login_et, but this doesn't automatically fix the incore inode SID.
2) At boot time, you are loading a policy that does define login_et, /bin/login inode is brought incore and mapped to the correct SID, you then load a policy that does not define login_et (e.g. Fedora policy), invalidating that SID, and you later reload a policy that does define login_et, but this doesn't automatically fix the incore inode SID.
While it would be possible to walk the inode lists upon a policy reload and retry mapping of the on-disk xattr for any inode with the unlabeled SID, I'm not sure it is worthwhile to do so.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Thanks for your help, Stephen. I've *briefly* looked around at the inird and /bin/init sources, and can't find an initiial policy that would be loaded before the root filesystem pivot_root. I expect to have more time at the end of this week to figure it out, though.
thanks,
-serge
Quoted 24 lines · Stephen Smalley
Quoted 6 lines · Serge Hallyn
Addendum: running setfilecon works once. After each reboot, I must again run setfilecon.before
/bin/loginwill cause the transition tologin_d. Again, running/bin/ls-Z/bin/loginshows no difference before and after the setifilecon - it is always
of typelogin_et.Two scenarios:
1) At boot time (e.g. usual policy load by/sbin/init), you are loading a policy that does not definelogin_et,/bin/logininode is brought incore and mapped to the unlabeled SID, and you then load a policy that does definelogin_et, but this doesn't automatically fix the incore inode SID.
2) At boot time, you are loading a policy that does definelogin_et,/bin/logininode is brought incore and mapped to the correct SID, you then load a policy that does not definelogin_et(e.g. Fedora policy), invalidating that SID, and you later reload a policy that does definelogin_et, but this doesn't automatically fix the incore inode SID.While it would be possible to walk the inode lists upon a policy reload and retry mapping of the on-disk xattr for any inode with the unlabeled SID, I'm not sure it is worthwhile to do so.
Quoted 7 lines
--
Stephen Smalley <[email protected]>
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 4 lines · Serge Hallyn
Thanks for your help, Stephen. I've *briefly* looked around at the inird and
/bin/initsources, and can't find an initiial policy that would be loaded before the root filesystempivot_root. I expect to have more time at the end of this week to figure it out, though.
In Fedora, policy is loaded from the real root filesystem by /sbin/init, not from the initrd. We did use an initrd originally when we first overhauled SELinux for mainline inclusion and moved the initial policy load into userspace, but RedHat encountered practical issues with using an initrd and migrated to a patched /sbin/init. So /sbin/init is loading policy from /etc/security/selinux/policy.NN under FC2 or /etc/selinux/(strict|targeted)/policy/policy.NN under FC3. The question is whether you are subsequently loading a different policy, possibly too late, after /bin/login has already been looked up and brought incore.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Stephen Smalley
/etc/selinux/(strict|targeted)/policy/policy.NN under FC3. The question is whether you are subsequently loading a different policy, possibly too late, after
/bin/loginhas already been looked up and brought incore.
Alas no, the custom policy is in /etc/security/selinux/policy.17 (on a FC2 throwaway partition).
-serge
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Serge Hallyn
Quoted 3 lines · Stephen Smalley
/etc/selinux/(strict|targeted)/policy/policy.NN under FC3. The question is whether you are subsequently loading a different policy, possibly too late, after
/bin/loginhas already been looked up and brought incore.Alas no, the custom policy is in
/etc/security/selinux/policy.17(on a FC2 throwaway partition).
Not sure if I understand your meaning (FC2 throwaway partition?), but the above statement makes me wonder if you also have an /etc/security/selinux/policy.18 file, and whether /sbin/init is loading it instead. FC2 shipped with policy.17, then subsequent FC2 kernel updates yielded kernels that understood policy.18 (but still support policy.17 for backward compatibility) without corresponding updates to the policy tools and policy itself. /sbin/init will try to load the latest policy supported by the kernel, so if you have a policy.18, it will try to load it first, and failing that, it will fall back to policy.17. But you shouldn't have a policy.18 unless you grabbed a newer checkpolicy yourself from the NSA site or from the Fedora development tree.
In any event, migrating to FC3 is a good idea for continued use of SELinux, as the FC2 SELinux support was never well maintained.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 1 line · Stephen Smalley
Not sure if I understand your meaning (FC2 throwaway partition?), but
Just that it's purely a test partition, which is why I haven't yet upgraded it. But of course that also means there's no reason not to upgrade it.
Quoted 2 lines
In any event, migrating to FC3 is a good idea for continued use of SELinux, as the FC2 SELinux support was never well maintained.
I'll try FC3.
thanks,
-serge
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Serge Hallyn
Thanks for your help, Stephen. I've *briefly* looked around at the inird and
/bin/initsources, and can't find an initiial policy that would be loaded before the root filesystempivot_root. I expect to
Only the initrd is running before pivot_root and the initrd does not load policy any more. So there is no policy loaded until after the root file system is mounted as "/" and /sbin/init is executed.
/sbin/init loads the policy and then re-exec's itself to transition from kernel_t to init_t.
Signature · 9 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.