Skip to contentSkip to conversation

enforcement and initrds

DISCUSSION Colin Walters 3 participants 7 messages Jul 14, 2003 – Jul 15, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,

I'm having trouble booting up my SE 2.5 system in enforcing mode, because my initrd (which uses ramfs) is completely unlabelled (because ramfs doesn't support xattrs).

When I add enforcing=1 to the Linux command line, it therefore dies almost immediately upon bootup. Perhaps it would be better to have the kernel not do anything with the enforcing=1 commandline, but instead have special code on the initrd to look at /proc/cmdline and if necessary set enforcing mode right before booting init?

--
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.

#1 lore raw
Quoted 11 lines · Colin Walters

Hi,

I'm having trouble booting up my SE 2.5 system in enforcing mode, because my initrd (which uses ramfs) is completely unlabelled (because ramfs doesn't support xattrs).

When I add enforcing=1 to the Linux command line, it therefore dies almost immediately upon bootup. Perhaps it would be better to have the kernel not do anything with the enforcing=1 commandline, but instead have special code on the initrd to look at /proc/cmdline and if necessary set enforcing mode right before booting init?

If CONFIG_SECURITY_SELINUX_DEVELOP=n, then the kernel is always in enforcing mode, so you won't be able to defer setting enforcing mode to the initrd. You can assign a single type to all of the ramfs entries via genfs_contexts (but nothing more granular without further support either in the ramfs code or in the SELinux module) and then grant permissions to it. Or you can grant permissions to unlabeled_t to permit booting.

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.
#2 lore raw
Quoted 3 lines · Stephen Smalley

If CONFIG_SECURITY_SELINUX_DEVELOP=n, then the kernel is always in enforcing mode, so you won't be able to defer setting enforcing mode to the initrd.

That's a good point, but then again we could just make DEVELOP=n instead mean that once enforcing mode was switched on, it couldn't be switched off.

Quoted 4 lines

You can assign a single type to all of the ramfs entries
via genfs_contexts (but nothing more granular without further support either in the ramfs code or in the SELinux module) and then grant permissions to it.

I tried this, but there appears to be a bootstrapping problem; the policy says that romfs uses genfs; but the policy has to be loaded from the initrd, which isn't labeled until we know what the policy is.

Quoted 2 lines

Or you can grant permissions to unlabeled_t to
permit booting.

How? Again that's part of the policy, so we face the same bootstrapping problem.

One other alternative would be to make kernel_t (SECINITSID_KERNEL) a special SID that can do anything. Anything with that type is a kernel thread anyways, right? So it could really do anything.

--
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.

#3 lore raw
Quoted 8 lines · Colin Walters
Quoted 3 lines · Stephen Smalley

If CONFIG_SECURITY_SELINUX_DEVELOP=n, then the kernel is always in enforcing mode, so you won't be able to defer setting enforcing mode to the initrd.

That's a good point, but then again we could just make DEVELOP=n instead mean that once enforcing mode was switched on, it couldn't be switched off.

You could compile with DEVELOP=y and use policy that prevents turning it off which is almost as good (anyone who can load a policy that allows turning it off can load a policy that permits everything).

Quoted 8 lines
Quoted 4 lines

You can assign a single type to all of the ramfs entries
via genfs_contexts (but nothing more granular without further support either in the ramfs code or in the SELinux module) and then grant permissions to it.

I tried this, but there appears to be a bootstrapping problem; the policy says that romfs uses genfs; but the policy has to be loaded from the initrd, which isn't labeled until we know what the policy is.

Last time I did this it worked OK, SE Linux loaded the policy as part of the mount process.

Signature · 10 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.
#4 lore raw
Quoted 3 lines · Russell Coker

You could compile with DEVELOP=y and use policy that prevents turning it off which is almost as good (anyone who can load a policy that allows turning it off can load a policy that permits everything).

True enough.

Quoted 2 lines

Last time I did this it worked OK, SE Linux loaded the policy as part of the mount process.

In 2.5 that doesn't happen anymore, which I think is good. Hardcoding stuff like /etc/security inside Linux is just a bad idea. But we have to figure out exactly how the initrd should work.

--
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.

#5 lore raw
In reply to Colin Walters
Quoted 3 lines · Colin Walters

That's a good point, but then again we could just make DEVELOP=n instead mean that once enforcing mode was switched on, it couldn't be switched off.

I'd prefer to be able to compile out the permissive mode support entirely for production kernels.

Quoted 3 lines

I tried this, but there appears to be a bootstrapping problem; the policy says that romfs uses genfs; but the policy has to be loaded from the initrd, which isn't labeled until we know what the policy is.

romfs or ramfs? It isn't an issue whether it is labeled before the policy is loaded; all permission checks are allowed until the policy is loaded and the security server is initialized. At some point, we'd like to generate an initial bootstrapping policy that is built into the security server, but there isn't any point in doing that until things stabilize a bit more, and that initial policy could be dependent on your particular kernel configuration and your initrd setup.

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.
#6 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 3 lines · Colin Walters

That's a good point, but then again we could just make DEVELOP=n instead mean that once enforcing mode was switched on, it couldn't be switched off.

I'd prefer to be able to compile out the permissive mode support entirely for production kernels.

I can understand that.

Quoted 1 line

romfs or ramfs?

romfs, sorry about my initial misstatement.

Quoted 3 lines

It isn't an issue whether it is labeled before the
policy is loaded; all permission checks are allowed until the policy is loaded and the security server is initialized.

Ahh, I see. Ok.

I've created an initrd.te which appears to work for me. I put it in types/initrd.te.

Quoted 5 lines

At some point, we'd like
to generate an initial bootstrapping policy that is built into the security server, but there isn't any point in doing that until things stabilize a bit more, and that initial policy could be dependent on your particular kernel configuration and your initrd setup.

Yeah...I think this initrd.te is a first step towards that bootstrapping policy.

#
# Description: allow ramfs/cramfs initrd bootstrapping from unlabeled_t # Authors: Colin Walters <[email protected]>

# Operate on unlabeled files.
allow kernel_t unlabeled_t:file_class_set create_file_perms; allow kernel_t unlabeled_t:dir create_dir_perms;
# Allow running scripts and such on the initrd. can_exec(kernel_t, unlabeled_t);

# Mount permissions, stolen from mount.te allow kernel_t unlabeled_t:filesystem mount_fs_perms; allow kernel_t unlabeled_t:dir mounton;
allow kernel_t proc_t:dir mounton;

# Operate on tmpfs.
allow kernel_t tmpfs_t:file_class_set create_file_perms; allow kernel_t tmpfs_t:dir create_dir_perms;