Skip to contentSkip to conversation

packet/socket owner match (fireflier) using skfilter

RFC In review Török Edwin 39 participants 272 messages Apr 2, 2006 – May 3, 2006 2 messages not in the archive Page 2 of 2

Subsystems (9)
Documentation VFS Kbuild PCI +5 more subsystems
lore
Share & tools
lore
#247 lore raw

Re: Labeling only policy and problems with booleans

In reply to Stephen Smalley
Quoted 7 lines · Stephen Smalley
Quoted 2 lines · Török Edwin

domain_auto_trans(unconfined_t,myapp_exec_t,myapp_t) domain_auto_trans(initrc_t,myapp_exec_t,myapp_t)

Should be some higher level interface for running a program as a user app and as a daemon, right? You don't want to make direct references to other modules' types if it can be avoided.

There isn't one currently for unconfined users, but that should be added for 3rd party use. There are two potentials for the initrc, init_daemon_domain() and init_system_domain(). The first one is (obviously) for daemons, and the second one is for short running initialization-style processes such as mount and ifconfig; they both have the same parameters, for example:

init_daemon_domain(myapp_t,myapp_exec_t)

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
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.
#248 lore raw

Re: Labeling only policy and problems with booleans

Quoted 8 lines · Christopher J. PeBenito
Quoted 4 lines · Stephen Smalley

Should be some higher level interface for running a program as a user app and as a daemon, right? You don't want to make direct references to other modules' types if it can be avoided.

There isn't one currently for unconfined users, but that should be added for 3rd party use.

What about interface(`unconfined_domain', (in unconfined.fc)?

Quoted 7 lines

There are two potentials for the initrc, init_daemon_domain() and init_system_domain(). The first one is (obviously) for daemons, and the second one is for short running initialization-style processes such as mount and ifconfig; they both have the same parameters, for example:

init_daemon_domain(myapp_t,myapp_exec_t)

I'll use this one and unconfined_domain.

Is using unconfined_domain enough, or should I also add init_daemon_domain? Does init_daemon_domain grant any privileges that unconfined domain doesn't have?

I also need to remove the ability to load policy from an unconfined domain (see my previous mail), if I remove that from unconfined.te, build a base.pp, and distribute that along with fireflier, will that be ok?
Or will you consider including a boolean to disable policy loading for unconfined domains (separate from the boolean that restrict policy loading for the kernel), so that I can turn off policy loading for unconfined domains, but keep it for "privileged" domains?

Thanks,
Edwin

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

#249 lore raw

Re: Labeling only policy and problems with booleans

Quoted 16 lines · Török Edwin
Quoted 8 lines · Christopher J. PeBenito
Quoted 4 lines · Stephen Smalley

Should be some higher level interface for running a program as a user app and as a daemon, right? You don't want to make direct references to other modules' types if it can be avoided.

There isn't one currently for unconfined users, but that should be added for 3rd party use.

What about interface(`unconfined_domain', (in unconfined.fc)?

Quoted 6 lines

There are two potentials for the initrc, init_daemon_domain() and init_system_domain(). The first one is (obviously) for daemons, and the second one is for short running initialization-style processes such as mount and ifconfig; they both have the same parameters, for example:

Quoted 6 lines
Quoted 1 line

init_daemon_domain(myapp_t,myapp_exec_t)

I'll use this one and unconfined_domain.

Is using unconfined_domain enough, or should I also add init_daemon_domain? Does init_daemon_domain grant any privileges that unconfined domain doesn't have?

unconfined_domain() only makes the specified domain unconfined, it doesn't make a transition from unconfined_t to the domain. init_daemon_domain() makes a transition from initrc_t to the specified domain. Perhaps we should consider renaming the interfaces to clear up this confusion.

Quoted 3 lines

I also need to remove the ability to load policy from an unconfined domain (see my previous mail), if I remove that from unconfined.te, build a base.pp, and distribute that along with fireflier, will that be ok?

If you want the fierflier policy to replace the distro's policy, that seems reasonable.

Quoted 4 lines

Or will you consider including a boolean to disable policy loading for unconfined domains (separate from the boolean that restrict policy loading for the kernel), so that I can turn off policy loading for unconfined domains, but keep it for "privileged" domains?

Right now in the upstream policy, unconfined_domain() means fully unconfined. It might be more acceptable if we do a labeled boolean so only access to that boolean is disabled when secure mode is enabled, rather than disabling all boolean access.

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
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.
#250 lore raw

Re: Labeling only policy and problems with booleans

In reply to Stephen Smalley
Quoted 7 lines · Stephen Smalley
Quoted 1 line · Török Edwin

domain_auto_trans(unlabeled_t,myapp_exec_t,myapp_t)

No process should be running in unlabeled_t (a process might be re-mapped to unlabeled_t if its type was removed from policy and policy was reloaded while the process was still running, but this would quickly lead to death for the process as it would lose access to its resources).

Ok, I won't add rules for unlabeled_t.

Quoted 7 lines
Quoted 3 lines

But why didn't the booleans work? I tried setting their default values in booleans.conf to true, and still the same result, they weren' t taken into consideration.

I think we need more details to see whether this is a bug or not. What
version of refpolicy?

20060307

Quoted 1 line

What version of checkpolicy?

checkpolicy 1.30-1, runnning on AMD64, kernel 2.6.16, debian sid. I also tried:checkpolicy-1.30.3-1.fc5 on fedora core 5. The virtual machine I tested my policy is emulating an x86_64 too. I tried loading the policies generated by both versions, and I had the "boolean problem" with both.

Quoted 6 lines

There was a problem
with the boolean mapping at link time with the optionals-in-base changes to refpolicy and certain versions of checkpolicy, but I think that has been resolved in the current version (although optionals-in-base still doesn't work properly, but that doesn't affect you as long as you are building everything you need into base).

If I have only the base module loaded (and anything else besides unconfined.pp) then setting secure_mode_policyload works as expected. However if I load unconfined.pp, I can change the policy even after secure_mode_policyload
As soon as I remove unconfined.pp (and its dependencies), secure_mode_policyload works again.

Quoted 7 lines
Quoted 5 lines

(btw, I also ran into a make bug:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=358903, I hope this booleans problems isn't another build-tool related bug, if needed I can make the compiled policy module available for analysis)

Yes, that would be helpful.

The policy where I had unconfined linked (boolean not working)
http://edwintorok.googlepages.com/policybad.tar.gz

The policy where I didn't have unconfined linked:
http://edwintorok.googlepages.com/policyok.tar.gz

kernel messages: http://edwintorok.googlepages.com/messages
full build directory: http://edwintorok.googlepages.com/refpolicy.tgz

Let me know if anything else is needed to trace the problem.

There is another thing that worries me.
I was able to do mknod xx c 1 2 creating an equivalent of /dev/kmem, and it wasn't labeled memory_device_t, it was labeled unlabeled_t.
So I guess giving access to unlabeled_t files is very dangerous (as you say below). I assume one could exploit this by writing a program that creates a kmem equivalent, and then he can do anything he wishes, including replacing policy, loading another kernel module, patch syscalls...., am I right?

Quoted 8 lines

Originally, attributes were all expanded when policy was compiled, and the kernel just dealt with the individual pairs. But current kernels and policies retain attributes in the rules when feasible, so the representation is more compact if you use attributes in your rules. So you save memory that way. Runtime processing itself is largely unaffected, as the access vector cache provides most of the security decisions, so security server computations are infrequent.

So I shouldn't worry about the number of types/attributes in my policy as far as performance is concerned. I might optimize when the policy is final, to save some memory.

Quoted 10 lines
Quoted 6 lines

Also since all programs will have unlabeled_t by default, there is no point to do an initial relabeling, so either:
- mount -o context=unconfined_t
- do nothing, and the programs will get by default unlabeled_t, or
file_t, right?

Using unlabeled_t in this way is a bad idea; it is used internally for various purposes to identity unlabeled entities or entities that have become unlabeled due to label invalidation.

I'll avoid using unlabeled_t.

What is the best practice to do when: most of the programs on the system will run as unconfined_t, so they'll all have the same (default) label (on my system file_t seems to be the default label) except:
- devices in /dev (handled by udev policy?)
- selinux policy loading programs (loadpolicy, semodule)
But I do want to be able to label individual files (when fireflier generates policies for them).

If I don't run setfiles, and I run restorecon only for the: selinux policy loading programs, and fireflier, will that be safe? (will an unlabeled program be able to gain access to another domain besides unconfined_t) Also, should I consider doing the policy loading myself in fireflier (via libselinux,libsemanage...) instead of relying on an external program?

Quoted 7 lines
Quoted 4 lines

One of the other goals is the ability to be able to boot the system in enforcing mode, without any manual policy modifications. If all programs are unconfined_t/default_t will this be possible?

If everything is unconfined, then naturally enforcing mode has no real impact on behavior.

Ok. But let me clarify, by unconfined_t I don't mean unconfined_t from the targeted policy, since that has policy loading allowed.
I want to allow unconfined_t everything except:
- loading policy
- changing labels
- kernel module loading (boolean controlled, if I get booleans working)
- changing iptables rules
- writing to raw memory
Fireflier doesn't aim to be a full security solution, I just want it to create proper labels for skfilter to use, and as such there should be no way for an unconfined_t process to change labels/load policy.

I however don't care (maybe in a future version of fireflier I will) if an unconfined_t writes to raw disk devices for example, etc. as long as it doesn't "escape" the packet filtering rules.

I could have just created a policy that imposes no restrictions (like secure_mode_policyload, protection from raw memory writes, protection from security context transitions), since a program that is able to do that is root, and if he is root he could just 'iptables -F', and all is over. But I considered to provide some of the protections of the targeted policy, since if people see fireflier creates&uses selinux policies, will think "ah it uses selinux, this must be safe, so if I put this iptables rule here it will make sure that only this program is allowed to receive on that port. Not even if somebody gains root, will he be able to alter my iptables rules". I'll document clearly that fireflier doesn't aim at protecting you from root exploits, and the actions of root; but I think that offering "some" protection against root is better, than none at all.

Quoted 7 lines
Quoted 6 lines

I also thought of creating an even more minimal base policy, but I am not sure what I should remove from there, without breaking anything (I've seen class, inherit, constrain, sid, portcon, fs_xattr,... I think these are critical for selinux policy work, aren't they?) Would a more minimal policy make selinux work faster?

Quoted 5 lines

The flask definitions (classes, initial SIDs, access vectors) shouldn't be disturbed, as they are generated into definitions that are built into the kernel. The fs_use definitions are fundamental and shouldn't be modified except possibly to add new ones if appropriate for some filesystem type that you are using.

I won't touch them.

Quoted 4 lines

Constraints do slow down processing
of the security server computation, but most security decisions are provided by the AVC after the first such computation, so it isn't really critical, and the constraints do provide important restrictions.

So I'll leave these ones alone too.

Quoted 4 lines

Object
context definitions like portcon, netifcon, etc. can be omitted if you aren't truly using the SELinux network access controls. Primarily, you just want to minimize the TE rules for memory efficiency.

Ok, I'll do this as a final optimization step.

Quoted 11 lines
Quoted 7 lines

Since all the programs that need access to the socket are running already (we are generating policies on-the-fly), we can ask the user which programs he wants to give access to the socket, and create a policy for that. Maybe creating an attribute, and applying that attribute to those programs' types, and create a "neverallow ~myattribute" rule for the socket access.

neverallow rules don't grant access; they just specify invariants that should be checked when policy is compiled (or in the case of modules, when policy is linked and expanded to kernel policy).

I intend to use neverallow to catch policy generation bugs, and ...policy creating logic errors. Also will it stop somebody from loading a policy module that overrides my restrictions?

Quoted 9 lines

Hmmm...there used to be a clone statement in the language, but it was ultimately dropped because the semantics were ambiguous and what you usually want is not truly complete equivalence, just structural parallel. e.g. for the new type, you don't want to allow it access to private/derived types of the old type - you want to allow it to access its own private/derived types. And you don't necessarily want to allow the same relationships with ancestors and descendants.

Consider this scenario:
- there is a type: original_exec_t, that transitions to original_t domain;
and 10 programs are labeled with it
- files created by original_t can be written by another_t
- I want to create a rule for only 2 programs out of those, so I create a new
type: sub_original_exec_t, sub_original_t and apply this label to these 2 programs. (and I'll create skfilter rules for these labels).
I want to keep the allowed interactions between the 10 programs in original_t, so I'll have to give programs that are now sub_original_t, the same right they would have had if they stayed original_t. And I also want to be give another_t write access to files created by sub_original_t (creating files that have the same label as original_t would have gave them should he enough?)

Is this what you referred to as structural equivalence?

But you are right, if somebody creates descendant types he has to consider which type he actually wants original_t, or sub_original_t .

How can I create a type that is structurally equivalent? (read all rules associated with that type from the binary policy, and generate allow/transition/etc. rules based on them?)

Thanks in advance,
Edwin

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

#251 lore raw

Re: Labeling only policy and problems with booleans

Quoted 5 lines · Török Edwin

The policy where I had unconfined linked (boolean not working)
http://edwintorok.googlepages.com/policybad.tar.gz

The policy where I didn't have unconfined linked:
http://edwintorok.googlepages.com/policyok.tar.gz

sediff of these two policies shows a _lot_ of differences, including 107 added types in the "bad" policy. Are you sure they are identical except for linking unconfined? What is in that module (source)?

I do see an allow unconfined_t security_t:security load_policy under a different boolean in the "bad" policy; looks like a boolean mapping problem at link time. We did see those when the optionals-in-base support was first merged, so the Debian checkpolicy might have an issue there, but that should have been resolved in 1.30.3 or newer, built against libsepol 1.12.3 or newer.

Quoted 2 lines

kernel messages: http://edwintorok.googlepages.com/messages
full build directory: http://edwintorok.googlepages.com/refpolicy.tgz

This one returned a 404 error.

Quoted 9 lines

Let me know if anything else is needed to trace the problem.

There is another thing that worries me.
I was able to do mknod xx c 1 2 creating an equivalent of /dev/kmem, and it wasn't labeled memory_device_t, it was labeled unlabeled_t.
So I guess giving access to unlabeled_t files is very dangerous (as you say below). I assume one could exploit this by writing a program that creates a kmem equivalent, and then he can do anything he wishes, including replacing policy, loading another kernel module, patch syscalls...., am I right?

Not entirely. Keep in mind that opening the memory devices requires CAP_SYS_RAWIO, so you also need the SELinux sys_rawio permission in the capability class to make use of such a device node even if you can create one. However, ensuring a consistent label on devices irrespective of filesystem node used to access them would be nice; there has been some consideration of labeling the internal objects rather than just the filesystem nodes and applying access control at that layer to ensure consistent control. In the meantime, be careful about who you allow to create device nodes and who you allow sys_rawio in your policy.

Quoted 3 lines

What is the best practice to do when: most of the programs on the system will run as unconfined_t, so they'll all have the same (default) label (on my system file_t seems to be the default label) except:

If you don't assign an xattr, then SELinux uses the context associated with the 'file' initial SID in initial_sid_contexts as the default label for the file.

Quoted 10 lines

- devices in /dev (handled by udev policy?)
- selinux policy loading programs (loadpolicy, semodule)
But I do want to be able to label individual files (when fireflier generates policies for them).

If I don't run setfiles, and I run restorecon only for the: selinux policy loading programs, and fireflier, will that be safe? (will an unlabeled program be able to gain access to another domain besides unconfined_t) Also, should I consider doing the policy loading myself in fireflier (via libselinux,libsemanage...) instead of relying on an external program?

Normative pattern is to install policy modules via semodule, which calls libsemanage to perform the actual installation and loading of policy. libsemanage uses the external programs as appropriate. Then you just have to invoke restorecon as appropriate to label the desired files. Using the external program is preferred, and may be enforced via policy under some policies.

Quoted 11 lines

Ok. But let me clarify, by unconfined_t I don't mean unconfined_t from the targeted policy, since that has policy loading allowed.
I want to allow unconfined_t everything except:
- loading policy
- changing labels
- kernel module loading (boolean controlled, if I get booleans working)
- changing iptables rules
- writing to raw memory
Fireflier doesn't aim to be a full security solution, I just want it to create proper labels for skfilter to use, and as such there should be no way for an unconfined_t process to change labels/load policy.

I'm not certain how useful this is, as there are obvious bypasses here unless you start dealing with all of the dependencies for the associated programs and their data, e.g. can unconfined_t still update glibc? At which point unconfined_t becomes a misnomer and you start approximating the strict policy more and more.

Quoted 3 lines

I intend to use neverallow to catch policy generation bugs, and ...policy creating logic errors. Also will it stop somebody from loading a policy module that overrides my restrictions?

semodule/libsemanage should end up rejecting a module if it violates a neverallow rule in the base or any other module, so in one sense, yes. But keep in mind that if the person loading the policy module has the ability to manipulate the module store, then they can always remove/replace the module that has those assertions, so you have to ensure non-bypassability there. Ultimately, libsemanage will interface to a policy management daemon that will enforce such restriction more strongly, with the policy ensuring that the daemon can't be bypassed to directly manipulate the store.

Quoted 3 lines

How can I create a type that is structurally equivalent? (read all rules associated with that type from the binary policy, and generate allow/transition/etc. rules based on them?)

Usually we do this by defining interfaces/macros in the policy itself, and then instantiating multiple types from it. Rather than trying to automatically infer it.

Signature · 8 lines
Stephen Smalley
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.
#252 lore raw

Re: Labeling only policy and problems with booleans

Quoted 4 lines · Stephen Smalley

sediff of these two policies shows a _lot_ of differences, including 107 added types in the "bad" policy. Are you sure they are identical except for linking unconfined? What is in that module (source)?

Hmm, that is *bad*. The module source is in the refpolicy.tgz. I linked unconfined _and_ all its dependencies (which is quite a lot, from memory:
init,udev,userdomain,locallogin,libraries,storage,miscfiles,authlogin,...)

Quoted 7 lines

I do see an allow unconfined_t security_t:security load_policy under a different boolean in the "bad" policy; looks like a boolean mapping problem at link time. We did see those when the optionals-in-base support was first merged, so the Debian checkpolicy might have an issue there, but that should have been resolved in 1.30.3 or newer, built against libsepol 1.12.3 or newer.

I'll try upgrading libsepol in fc5, and I'll also try to build checkpolicy+libsepol manually from the latest sources. I'll let you know (possibbly tomorrow) if this makes a difference.
btw, wouldn't it be nice for checkpolicy to have a --version option, currently I have to use apt-cache policy for debian, rpm -q for redhat, etc. to find out which version I have.

Quoted 3 lines
Quoted 3 lines

kernel messages: http://edwintorok.googlepages.com/messages
full build directory: http://edwintorok.googlepages.com/refpolicy.tgz

Upload size limit :(, try this one:
http://projects.emerge.upt.ro/Kernel-Dev/browser/fireflier/refpolicy.tgz?format=raw

Quoted 14 lines

This one returned a 404 error.

Quoted 10 lines

Let me know if anything else is needed to trace the problem.

There is another thing that worries me.
I was able to do mknod xx c 1 2 creating an equivalent of /dev/kmem, and it wasn't labeled memory_device_t, it was labeled unlabeled_t. So I guess giving access to unlabeled_t files is very dangerous (as you say below). I assume one could exploit this by writing a program that creates a kmem equivalent, and then he can do anything he wishes, including replacing policy, loading another kernel module, patch syscalls...., am I right?

Quoted 8 lines

Not entirely. Keep in mind that opening the memory devices requires CAP_SYS_RAWIO, so you also need the SELinux sys_rawio permission in the capability class to make use of such a device node even if you can create one. However, ensuring a consistent label on devices irrespective of filesystem node used to access them would be nice; there has been some consideration of labeling the internal objects rather than just the filesystem nodes and applying access control at that layer to ensure consistent control.

That would be nice. Then device under /dev would automatically get the correct label? It would also eliminate a few bootstrapping problems (currently I have to reboot using init=/bin/sh, relabel /dev, and then reboot&relabel after udev is up).

Quoted 2 lines

In the meantime, be careful about who you
allow to create device nodes and who you allow sys_rawio in your policy.

Ok

Quoted 14 lines
Quoted 7 lines

- devices in /dev (handled by udev policy?)
- selinux policy loading programs (loadpolicy, semodule)
But I do want to be able to label individual files (when fireflier generates policies for them).

Quoted 6 lines

If I don't run setfiles, and I run restorecon only for the: selinux policy loading programs, and fireflier, will that be safe? (will an unlabeled program be able to gain access to another domain besides unconfined_t) Also, should I consider doing the policy loading myself in fireflier (via libselinux,libsemanage...) instead of relying on an external program?

Quoted 6 lines

Normative pattern is to install policy modules via semodule, which calls libsemanage to perform the actual installation and loading of policy. libsemanage uses the external programs as appropriate. Then you just have to invoke restorecon as appropriate to label the desired files. Using the external program is preferred, and may be enforced via policy under some policies.

I'll use semodule then. Would it make sense to add file integrity check to fireflier (checksum/secure hash/digital signature)? (for checking if semodule is actually what it should be)

Quoted 13 lines
Quoted 12 lines

Ok. But let me clarify, by unconfined_t I don't mean unconfined_t from the targeted policy, since that has policy loading allowed. I want to allow unconfined_t everything except:
- loading policy
- changing labels
- kernel module loading (boolean controlled, if I get booleans working)
- changing iptables rules
- writing to raw memory
Fireflier doesn't aim to be a full security solution, I just want it to create proper labels for skfilter to use, and as such there should be no way for an unconfined_t process to change labels/load policy.

Quoted 5 lines

I'm not certain how useful this is, as there are obvious bypasses here unless you start dealing with all of the dependencies for the associated programs and their data, e.g. can unconfined_t still update glibc? At which point unconfined_t becomes a misnomer and you start approximating the strict policy more and more.

Like I said, fireflier is going to deal with the networking part only. I just wanted to add some simple protection to prevent simple bypasses. By simple I mean those that can be done instantly: if somebody loads a policy it has bypassed fireflier. OTOH if he wouldn't have had fireflier installed, somebody could have just flushed the iptables rules.
So maybe I'll focus on the networking part, and label transition part only, and _not_ think of N possible ways to punch holes in the system, if somebody really wants to.

So the only kind of protection that still makes sense, and would be easy to do (I hope) is to prevent programs from switching contexts(AFAIK there are some libselinux functions, that can be called to do that switch).

Quoted 11 lines
Quoted 4 lines

I intend to use neverallow to catch policy generation bugs, and ...policy creating logic errors. Also will it stop somebody from loading a policy module that overrides my restrictions?

semodule/libsemanage should end up rejecting a module if it violates a neverallow rule in the base or any other module, so in one sense, yes. But keep in mind that if the person loading the policy module has the ability to manipulate the module store, then they can always remove/replace the module that has those assertions, so you have to ensure non-bypassability there.

I didn't mean to protect against malicious users with neverallow. I only wanted to give the user/sysadmin a warning, that he breaks some rules he has previously set: so that he doesn't "by accident" invalidate fireflier's rules.

Quoted 5 lines

Ultimately, libsemanage will interface
to a policy management daemon that will enforce such restriction more strongly, with the policy ensuring that the daemon can't be bypassed to directly manipulate the store.

Quoted 7 lines
Quoted 3 lines

How can I create a type that is structurally equivalent? (read all rules associated with that type from the binary policy, and generate allow/transition/etc. rules based on them?)

Usually we do this by defining interfaces/macros in the policy itself, and then instantiating multiple types from it. Rather than trying to automatically infer it.

Right, but in that case you are writing the policy, you are designing the policy. Considering the scenario I gave earlier, if the user/admin had known that he needs separate rules for those 2 programs, he wouldn't have put them in the same domain. Maybe it is just too complicated to handle this automatically, and fireflier should do just this:
- let the user know what is the domain of the program(s) accessing that
socket
- let the user decide if he wants _all_ the programs in that domain to give
access, and if not (here comes the change):
- let fireflier create a new type, that the user will(could) customize
later
- use a predefined domain (already in policy)
- let the user modify the policy that only those programs remain in the
same domain, that need same access rights

When fireflier creates a type, it would be based on unconfined_t by default.

After all, if the user has Selinux enabled on his system:
- he either knows how to write selinux policies, so he can customize the .te
generated by fireflier
, or he uses a distro where the policy has already been written (properly), in which case he should choose from a list of predefined domains only

Edwin

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

#253 lore raw

Re: Labeling only policy and problems with booleans

In reply to Stephen Smalley
Quoted 11 lines · Stephen Smalley

sediff of these two policies shows a _lot_ of differences, including 107 added types in the "bad" policy. Are you sure they are identical except for linking unconfined? What is in that module (source)?

I do see an allow unconfined_t security_t:security load_policy under a different boolean in the "bad" policy; looks like a boolean mapping problem at link time. We did see those when the optionals-in-base support was first merged, so the Debian checkpolicy might have an issue there, but that should have been resolved in 1.30.3 or newer, built against libsepol 1.12.3 or newer.

I rebuilt the policy under FC5, with checkpolicy 1.30.3, and libsepol-1.12.4-1.fc5, checkpolicy-1.30.3-1.fc5, here it is
http://edwintorok.googlepages.com/policy.20.
Using sediff shows almost no difference to the bad policy (some te rules I removed, since they violated assertions), and the same 100+ differences to the good policy.
Looking at this line:
F + allow unconfined_t security_t : security { compute_member
compute_user compute_create setenforce check_context setcheckreqprot compute_relabel setbool load_policy setsecparam compute_av }; [ allow_execmem allow_execstack && ]

I tried setting allow_execmem and allow_execstack to true, and then I couldn't load policy anymore. Clearly, at linktime secure_mode_policyload was mapped to allow_execmem && allow_execstack.
And AFAICT this bug it is still present in the latest checkpolicy+libsepol.

Is there a bugtracker for selinux?

(you said that a bug like this has been fixed, do you recall where that patch is?, it might be a good starting point on fixing this issue)

Edwin

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

#254 lore raw

Re: Labeling only policy and problems with booleans

Quoted 29 lines · Török Edwin
Quoted 11 lines · Stephen Smalley

sediff of these two policies shows a _lot_ of differences, including 107 added types in the "bad" policy. Are you sure they are identical except for linking unconfined? What is in that module (source)?

I do see an allow unconfined_t security_t:security load_policy under a different boolean in the "bad" policy; looks like a boolean mapping problem at link time. We did see those when the optionals-in-base support was first merged, so the Debian checkpolicy might have an issue there, but that should have been resolved in 1.30.3 or newer, built against libsepol 1.12.3 or newer.

I rebuilt the policy under FC5, with checkpolicy 1.30.3, and libsepol-1.12.4-1.fc5, checkpolicy-1.30.3-1.fc5, here it is
http://edwintorok.googlepages.com/policy.20.
Using sediff shows almost no difference to the bad policy (some te rules I removed, since they violated assertions), and the same 100+ differences to the good policy.
Looking at this line:
F + allow unconfined_t security_t : security { compute_member
compute_user compute_create setenforce check_context setcheckreqprot compute_relabel setbool load_policy setsecparam compute_av }; [ allow_execmem allow_execstack && ]

I tried setting allow_execmem and allow_execstack to true, and then I couldn't load policy anymore. Clearly, at linktime secure_mode_policyload was mapped to allow_execmem && allow_execstack.
And AFAICT this bug it is still present in the latest checkpolicy+libsepol.

Quoted 7 lines

Is there a bugtracker for selinux?

(you said that a bug like this has been fixed, do you recall where that patch is?, it might be a good starting point on fixing this issue)

Edwin

We have a patch that fixes this, but unfortunately it is part of a larger patch that fixes several bugs and introduces a minor policy module file format change. I'm trying to track down the exact part of the larger patch that fixes this bug now and will hopefully have a smaller patch soon.

Karl

Signature · 3 lines
Karl MacMillan
Tresys Technology
www.tresys.com
Quoted 4 lines

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

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

#255 lore raw

PATCH 1/1 consistent labeling of block|character devices

In reply to Stephen Smalley
Quoted 5 lines · Stephen Smalley

However, ensuring a consistent label on devices
irrespective of filesystem node used to access them would be nice; there has been some consideration of labeling the internal objects rather than just the filesystem nodes and applying access control at that layer to ensure consistent control.

IMHO there are two approaches here:
1) introduce a sid member in struct block_device and struct cdev and then each time someone reads the sid of an inode of class SECCLASS_BLKFILE|SECCLASS_CHR_FILE, returns the sid of the associated device. If relabeling is to be allowed, then relabeling the inode would mean relabeling the associated device.
But this would introduce additional overhead (the extra if to determine if we are dealing with device files) every time we read the sid of an inode. This seems not acceptable to me.

2) put a constant(invariant) label on devices, defined by policy Policy would define what label a device with giver major/minor number. We would then use this as the security context of the inode, no matter what its xattr would say.
So no matter how many device files we have pointing to the same device (same major/minor no.) all will have the same sid.

I tried putting an additional condition in inode_doinit_with_dentry, to compute the sid of block and character devices in a different way than for normal files. This would take care of initial labeling.
What should happen on relabeling, should the policy deny it (and we rely on that), or should some explicit code be added to return denied (somewhere in security_compute_av?) when tclass==SECCLASS_BLK_FILE|| tclass==SECCLASS_CHR_FILE, and requested==RELABEL_TO.

How time critical is inode_doinit_with_dentry, does adding an addittional if matter?

I am not sure how to implement map_device_to_sid, should I use selinux_genfs_context?

With the current policy language, what would be the easiest way of defining block device,character device initial sids?

And what would happen with modules that create block devices with dinamic major/minor numbers? How should those be labeled?

Any ideas,suggestions?

----
diff -uprN -X vanilla/linux-2.6.16/Documentation/dontdiff vanilla/linux-2.6.16/security/selinux/hooks.c linux-2.6.16/security/selinux/hooks.c
--- vanilla/linux-2.6.16/security/selinux/hooks.c 2006-03-20
18:29:57.000000000 +0200
+++ linux-2.6.16/security/selinux/hooks.c 2006-05-01 18:27:05.000000000 +0300
@@ -731,7 +731,7 @@ static int inode_doinit_with_dentry(stru
hold_sem = 1;
if (isec->initialized)
goto out;
-
+
sbsec = inode->i_sb->s_security;
if (!sbsec->initialized) {
/* Defer initialization until selinux_complete_init,
@@ -744,6 +744,18 @@ static int inode_doinit_with_dentry(stru
goto out;
}

+        int sclass = inode_mode_to_security_class(inode->i_mode);  
+        if(sclass == SECCLASS_BLK_FILE || sclass == SECCLASS_CHR_FILE)
+        {	
+	   char dev[16];
+	   isec->sclass = sclass;
+	   map_device_to_sid(inode->i_rdev,sclass,&sid);
+	   isec->sid=sid;
+	   isec->initialized=1;
+	   goto out;

+ }
+
+
switch (sbsec->behavior) {
case SECURITY_FS_USE_XATTR:
if (!inode->i_op->getxattr) {
@@ -833,7 +845,7 @@ static int inode_doinit_with_dentry(stru
isec->sid = sbsec->sid;

/* Try to obtain a transition SID. */
- isec->sclass = inode_mode_to_security_class(inode->i_mode);
+ isec->sclass = sclass;
rc = security_transition_sid(isec->task_sid,
sbsec->sid, isec->sclass,
@@ -849,7 +861,7 @@ static int inode_doinit_with_dentry(stru
if (sbsec->proc) {
struct proc_inode *proci = PROC_I(inode); if (proci->pde) {
- isec->sclass = inode_mode_to_security_class(inode->i_mode);
+ isec->sclass = sclass;
rc = selinux_proc_get_sid(proci->pde,
isec->sclass, &sid);

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

#256 lore raw

Re: [PATCH ] consistent labeling of block|character devices

Quoted 6 lines · Török Edwin
Quoted 5 lines · Stephen Smalley

However, ensuring a consistent label on devices
irrespective of filesystem node used to access them would be nice; there has been some consideration of labeling the internal objects rather than just the filesystem nodes and applying access control at that layer to ensure consistent control.

Quoted 9 lines

IMHO there are two approaches here:
1) introduce a sid member in struct block_device and struct cdev and then each time someone reads the sid of an inode of class SECCLASS_BLKFILE|SECCLASS_CHR_FILE, returns the sid of the associated device. If relabeling is to be allowed, then relabeling the inode would mean relabeling the associated device.
But this would introduce additional overhead (the extra if to determine if we are dealing with device files) every time we read the sid of an inode. This seems not acceptable to me.

This assumes that the label of the filesystem node used to access the device has to be the same as the label of the device itself. Instead consider labeling both objects and apply the appropriate access controls at each layer. Determining precisely the right objects to label and control likely requires some investigation and discussion with the maintainers of the driver core, e.g. Greg KH.

Quoted 6 lines

2) put a constant(invariant) label on devices, defined by policy Policy would define what label a device with giver major/minor number. We would then use this as the security context of the inode, no matter what its xattr would say.
So no matter how many device files we have pointing to the same device (same major/minor no.) all will have the same sid.

This also makes the same assumption, and the device number is not really a good way of identifying the devices and mapping them to labels, particularly moving forward toward dynamic device numbers.

Quoted 3 lines

I tried putting an additional condition in inode_doinit_with_dentry, to compute the sid of block and character devices in a different way than for normal files. This would take care of initial labeling.

I don't think this is the right approach.

Quoted 1 line

Any ideas,suggestions?

I think more investigation and discussion is required before we start tossing code around, and requires the involvement of the relevant kernel maintainers. If you want to start such a dialogue just by asking the relevant questions, feel free (but cc me and James Morris). Greg is likely a good starting point. The hard part is asking the right questions ;)

Signature · 8 lines
Stephen Smalley
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.
#257 lore raw

PATCH 1/4 Labeling only policy for fireflier

In reply to Stephen Smalley

Hi,
[I have split this mail in several parts for easier reading.]

I have create a stripped down policy for use with fireflier.
(for those who didn't read the entire thread: the purpose of this policy is to provide labels for sockets, to be used with skfilter/secmark)

This policy doesn't intend to protect from the actions of root (since as Stephen Smalley suggested that would eventually lead me closer to the strict policy).

So I made many types aliases, but I left the flask classess, initial sids, genfs intact.

If a user is not root is he able to override the security context of a process/file/socket? (relabel, or otherwise change context)

Furthermore, if a user is not root, load_policy/restorecon/setfiles won't function, am I right? Even if the user recompiles them (to remove any uid==0 checks)?

I've also seen a capability named dac_override, it is needed when root needs to override dac (creating a file in the user's home directory, for example), but a user can't gain that capability, right? (IOW if DAC denies something, selinux won't allow it either)

So if I intend to provide no protection from root, I could use an even simpler base policy?

fireflier_base.conf:
-----------
class security
class process
class system
class capability
class filesystem
class file
class dir
class fd
class lnk_file
class chr_file
class blk_file
class sock_file
class fifo_file
class socket
class tcp_socket
class udp_socket
class rawip_socket
class node
class netif
class netlink_socket
class packet_socket
class key_socket
class unix_stream_socket
class unix_dgram_socket
class sem
class msg
class msgq
class shm
class ipc
class passwd # userspace
class drawable # userspace
class window # userspace
class gc # userspace
class font # userspace
class colormap # userspace
class property # userspace
class cursor # userspace
class xclient # userspace
class xinput # userspace
class xserver # userspace
class xextension # userspace
class pax
class netlink_route_socket
class netlink_firewall_socket
class netlink_tcpdiag_socket
class netlink_nflog_socket
class netlink_xfrm_socket
class netlink_selinux_socket
class netlink_audit_socket
class netlink_ip6fw_socket
class netlink_dnrt_socket
class dbus # userspace
class nscd # userspace
class association
class netlink_kobject_uevent_socket
sid kernel
sid security
sid unlabeled
sid fs
sid file
sid file_labels
sid init
sid any_socket
sid port
sid netif
sid netmsg
sid node
sid igmp_packet
sid icmp_socket
sid tcp_socket
sid sysctl_modprobe
sid sysctl
sid sysctl_fs
sid sysctl_kernel
sid sysctl_net
sid sysctl_net_unix
sid sysctl_vm
sid sysctl_dev
sid kmod
sid policy
sid scmp_packet
sid devnull
common file
{
ioctl
read
write
create
getattr
setattr
lock
relabelfrom
relabelto
append
unlink
link
rename
execute
swapon
quotaon
mounton
}
common socket
{
ioctl
read
write
create
getattr
setattr
lock
relabelfrom
relabelto
append
bind
connect
listen
accept
getopt
setopt
shutdown
recvfrom
sendto
recv_msg
send_msg
name_bind
}
common ipc
{
create
destroy
getattr
setattr
read
write
associate
unix_read
unix_write
}
class filesystem
{
mount
remount
unmount
getattr
relabelfrom
relabelto
transition
associate
quotamod
quotaget
}
class dir
inherits file
{
add_name
remove_name
reparent
search
rmdir
}
class file
inherits file
{
execute_no_trans
entrypoint
execmod
}
class lnk_file
inherits file
class chr_file
inherits file
{
execute_no_trans
entrypoint
execmod
}
class blk_file
inherits file
class sock_file
inherits file
class fifo_file
inherits file
class fd
{
use
}
class socket
inherits socket
class tcp_socket
inherits socket
{
connectto
newconn
acceptfrom
node_bind
name_connect
}
class udp_socket
inherits socket
{
node_bind
}
class rawip_socket
inherits socket
{
node_bind
}
class node
{
tcp_recv
tcp_send
udp_recv
udp_send
rawip_recv
rawip_send
enforce_dest
}
class netif
{
tcp_recv
tcp_send
udp_recv
udp_send
rawip_recv
rawip_send
}
class netlink_socket
inherits socket
class packet_socket
inherits socket
class key_socket
inherits socket
class unix_stream_socket
inherits socket
{
connectto
newconn
acceptfrom
}
class unix_dgram_socket
inherits socket
class process
{
fork
transition
sigchld # commonly granted from child to parent sigkill # cannot be caught or ignored
sigstop # cannot be caught or ignored
signull # for kill(pid, 0)
signal # all other signals
ptrace
getsched
setsched
getsession
getpgid
setpgid
getcap
setcap
share
getattr
setexec
setfscreate
noatsecure
siginh
setrlimit
rlimitinh
dyntransition
setcurrent
execmem
execstack
execheap
}
class ipc
inherits ipc
class sem
inherits ipc
class msgq
inherits ipc
{
enqueue
}
class msg
{
send
receive
}
class shm
inherits ipc
{
lock
}
class security
{
compute_av
compute_create
compute_member
check_context
load_policy
compute_relabel
compute_user
setenforce # was avc_toggle in system class
setbool
setsecparam
setcheckreqprot
}
class system
{
ipc_info
syslog_read
syslog_mod
syslog_console
}
class capability
{
# The capabilities are defined in include/linux/capability.h # Care should be taken to ensure that these are consistent with # those definitions. (Order matters)
chown
dac_override
dac_read_search
fowner
fsetid
kill
setgid
setuid
setpcap
linux_immutable
net_bind_service
net_broadcast
net_admin
net_raw
ipc_lock
ipc_owner
sys_module
sys_rawio
sys_chroot
sys_ptrace
sys_pacct
sys_admin
sys_boot
sys_nice
sys_resource
sys_time
sys_tty_config
mknod
lease
audit_write
audit_control
}
class passwd
{
passwd # change another user passwd
chfn # change another user finger info
chsh # change another user shell
rootok # pam_rootok check (skip auth)
crontab # crontab on another user
}
class drawable
{
create
destroy
draw
copy
getattr
}
class gc
{
create
free
getattr
setattr
}
class window
{
addchild
create
destroy
map
unmap
chstack
chproplist
chprop
listprop
getattr
setattr
setfocus
move
chselection
chparent
ctrllife
enumerate
transparent
mousemotion
clientcomevent
inputevent
drawevent
windowchangeevent
windowchangerequest
serverchangeevent
extensionevent
}
class font
{
load
free
getattr
use
}
class colormap
{
create
free
install
uninstall
list
read
store
getattr
setattr
}
class property
{
create
free
read
write
}
class cursor
{
create
createglyph
free
assign
setattr
}
class xclient
{
kill
}
class xinput
{
lookup
getattr
setattr
setfocus
warppointer
activegrab
passivegrab
ungrab
bell
mousemotion
relabelinput
}
class xserver
{
screensaver
gethostlist
sethostlist
getfontpath
setfontpath
getattr
grab
ungrab
}
class xextension
{
query
use
}
class pax
{
pageexec # Paging based non-executable pages
emutramp # Emulate trampolines
mprotect # Restrict mprotect()
randmmap # Randomize mmap() base
randexec # Randomize ET_EXEC base
segmexec # Segmentation based non-executable pages
}
class netlink_route_socket
inherits socket
{
nlmsg_read
nlmsg_write
}
class netlink_firewall_socket
inherits socket
{
nlmsg_read
nlmsg_write
}
class netlink_tcpdiag_socket
inherits socket
{
nlmsg_read
nlmsg_write
}
class netlink_nflog_socket
inherits socket
class netlink_xfrm_socket
inherits socket
{
nlmsg_read
nlmsg_write
}
class netlink_selinux_socket
inherits socket
class netlink_audit_socket
inherits socket
{
nlmsg_read
nlmsg_write
nlmsg_relay
nlmsg_readpriv
}
class netlink_ip6fw_socket
inherits socket
{
nlmsg_read
nlmsg_write
}
class netlink_dnrt_socket
inherits socket
class dbus
{
acquire_svc
send_msg
}
class nscd
{
getpwd
getgrp
gethost
getstat
admin
shmempwd
shmemgrp
shmemhost
}
class association
{
sendto
recvfrom
setcontext
}
class netlink_kobject_uevent_socket
inherits socket
# 8118 is for privoxy
attribute device_node;
attribute memory_raw_read;
attribute memory_raw_write;
attribute domain;
attribute unconfined_domain_type;
attribute set_curr_context;
attribute entry_type;
attribute privfd;
attribute can_change_process_identity;
attribute can_change_process_role;
attribute can_change_object_identity;
attribute can_system_change;
attribute process_user_target;
attribute cron_source_domain;
attribute cron_job_domain;
attribute process_uncond_exempt; # add userhelperdomain to this one
attribute file_type;
attribute lockfile;
attribute mountpoint;
attribute pidfile;
attribute polydir;
attribute usercanread;
attribute polyparent;
attribute polymember;
attribute security_file_type;
attribute tmpfile;
attribute tmpfsfile;
attribute filesystem_type;
attribute noxattrfs;
attribute can_load_kernmodule;
attribute can_receive_kernel_messages;
attribute kern_unconfined;
attribute proc_type;
attribute sysctl_type;
attribute mcskillall;
attribute mlsfileread;
attribute mlsfilereadtoclr;
attribute mlsfilewrite;
attribute mlsfilewritetoclr;
attribute mlsfileupgrade;
attribute mlsfiledowngrade;
attribute mlsnetread;
attribute mlsnetreadtoclr;
attribute mlsnetwrite;
attribute mlsnetwritetoclr;
attribute mlsnetupgrade;
attribute mlsnetdowngrade;
attribute mlsnetrecvall;
attribute mlsipcread;
attribute mlsipcreadtoclr;
attribute mlsipcwrite;
attribute mlsipcwritetoclr;
attribute mlsprocread;
attribute mlsprocreadtoclr;
attribute mlsprocwrite;
attribute mlsprocwritetoclr;
attribute mlsprocsetsl;
attribute mlsxwinread;
attribute mlsxwinreadtoclr;
attribute mlsxwinwrite;
attribute mlsxwinwritetoclr;
attribute mlsxwinreadproperty;
attribute mlsxwinwriteproperty;
attribute mlsxwinreadcolormap;
attribute mlsxwinwritecolormap;
attribute mlsxwinwritexinput;
attribute mlstrustedobject;
attribute privrangetrans;
attribute mlsrangetrans;
attribute can_load_policy;
attribute can_setenforce;
attribute can_setsecparam;
attribute ttynode;
attribute ptynode;
attribute server_ptynode;
attribute serial_device;
attribute netif_type;
attribute node_type;
attribute port_type;
attribute reserved_port_type;

type selinux_config_t;
type init_t,domain;
type unconfined_t,domain;
type file_t alias {bin_t sbin_t}, file_type;
type default_t, file_type,mountpoint,filesystem_type;
type device_t alias {mtrr_device_t null_device_t bdev_t console_device_t zero_device_t devtty_t}, device_node;
type fs_t alias {sysfs_t usbfs_t usbdevfs_t debugfs_t root_t binfmt_misc_fs_t capifs_t configfs_t eventpollfs_t futexfs_t hugetlbfs_t inotifyfs_t nfsd_fs_t ramfs_t romfs_t rpc_pipefs_t autofs_t cifs_t dosfs_t iso9660_t nfs_t tmpfs_t devpts_t}, file_type,filesystem_type;
type kernel_t, can_load_kernmodule, file_type;
type proc_t alias {proc_mdstat_t proc_net_t} , proc_type, file_type; type proc_kmsg_t , proc_type,file_type;
type proc_kcore_t, proc_type,file_type;
type sysctl_t alias {sysctl_irq_t sysctl_rpc_t sysctl_fs_t sysctl_kernel_t sysctl_modprobe_t sysctl_hotplug_t sysctl_net_t sysctl_net_unix_t sysctl_vm_t sysctl_dev_t}, sysctl_type,file_type;
type unlabeled_t;
type security_t,file_type;
type port_t, port_type,file_type;
type node_t, node_type,file_type;
type netif_t, netif_type,file_type;

bool secure_mode false;
bool secure_mode_insmod false;
bool secure_mode_policyload false;

typeattribute kernel_t can_change_process_identity;

allow device_t tmpfs_t:filesystem associate;
allow device_t fs_t:filesystem associate;
allow device_t noxattrfs:filesystem associate;

allow kernel_t file_t:dir mounton;
allow kernel_t root_t:dir mounton;
allow kernel_t self:dir { read getattr lock search ioctl }; allow kernel_t self:lnk_file { read getattr lock ioctl }; allow kernel_t self:file { getattr read write append ioctl lock };

# allow kernel_t to create child processes in this domain
allow kernel_t self:process { fork sigchld };
allow kernel_t self:capability *;
allow kernel_t unlabeled_t:dir mounton;
allow kernel_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit 
execmem execstack execheap };
allow kernel_t self:shm { associate getattr setattr create destroy read write 
lock unix_read unix_write };
allow kernel_t self:sem { associate getattr setattr create destroy read write 
unix_read unix_write };
allow kernel_t self:msg { send receive };
allow kernel_t self:msgq { associate getattr setattr create destroy read write 
enqueue unix_read unix_write };
allow kernel_t self:unix_dgram_socket { create { ioctl read getattr write 
setattr append bind connect getopt setopt shutdown } };
allow kernel_t self:unix_stream_socket { { create { ioctl read getattr write 
setattr append bind connect getopt setopt shutdown } } listen accept };
allow kernel_t self:unix_dgram_socket sendto;
allow kernel_t self:unix_stream_socket connectto;
allow kernel_t self:fifo_file { getattr read write append ioctl lock };
allow kernel_t self:sock_file { read getattr lock ioctl };
allow kernel_t self:fd use;
allow kernel_t proc_t:dir { read getattr lock search ioctl };
allow kernel_t proc_t:{ lnk_file file } { read getattr lock ioctl };
allow kernel_t proc_net_t:dir { read getattr lock search ioctl };
allow kernel_t proc_net_t:file { read getattr lock ioctl };
allow kernel_t proc_mdstat_t:file { read getattr lock ioctl };
allow kernel_t proc_kcore_t:file getattr;
allow kernel_t proc_kmsg_t:file getattr;
allow kernel_t sysctl_t:dir { read getattr lock search ioctl };
allow kernel_t sysctl_kernel_t:dir { read getattr lock search ioctl };
allow kernel_t sysctl_kernel_t:file { read getattr lock ioctl };
allow kernel_t unlabeled_t:fifo_file { getattr read write append ioctl lock };
allow kernel_t unlabeled_t:association { sendto recvfrom };
allow kernel_t netif_type:netif rawip_send;
#allow kernel_t self:capability net_raw;
allow kernel_t netif_type:netif rawip_recv;
allow kernel_t node_type:node rawip_send;
allow kernel_t node_type:node rawip_recv;
allow kernel_t netif_t:netif rawip_send;
#allow kernel_t self:capability net_raw;
allow kernel_t netif_type:netif { tcp_send tcp_recv };
allow kernel_t node_type:node { tcp_send tcp_recv };
allow kernel_t node_t:node rawip_send;
allow kernel_t sysfs_t:dir { read getattr lock search ioctl };
allow kernel_t sysfs_t:{ file lnk_file } { read getattr lock ioctl };
allow kernel_t usbfs_t:dir search;
allow kernel_t filesystem_type:filesystem mount;
allow kernel_t security_t:dir { read search getattr };
allow kernel_t security_t:file { getattr read write };
allow kernel_t security_t:security load_policy;
auditallow kernel_t security_t:security load_policy;
allow kernel_t device_t:dir { read getattr lock search ioctl };
allow kernel_t device_t:lnk_file { getattr read };
allow kernel_t console_device_t:chr_file { getattr read write append ioctl 
lock };
allow kernel_t bin_t:dir { read getattr lock search ioctl };
allow kernel_t bin_t:lnk_file { read getattr lock ioctl };
allow kernel_t sbin_t:dir { read getattr lock search ioctl };
allow kernel_t bin_t:dir { read getattr lock search ioctl };
allow kernel_t bin_t:lnk_file { read getattr lock ioctl };
allow kernel_t bin_t:file { { read getattr lock execute ioctl } 
execute_no_trans };
allow kernel_t domain:process signal;
allow kernel_t proc_t:dir search;
allow kernel_t domain:dir search;
allow kernel_t root_t:dir { read getattr lock search ioctl };
allow kernel_t root_t:lnk_file { read getattr lock ioctl };
allow kernel_t self:capability *;
allow kernel_t self:fifo_file { create ioctl read getattr lock write setattr 
append link unlink rename };
allow kernel_t self:process transition;
allow kernel_t self:file { getattr read write append ioctl lock };
allow kernel_t self:nscd *;
allow kernel_t self:dbus *;
allow kernel_t self:passwd *;
allow kernel_t proc_type:{ dir file } *;
allow kernel_t sysctl_t:{ dir file } *;
allow kernel_t kernel_t:system *;
allow kernel_t unlabeled_t:{ dir file lnk_file sock_file fifo_file chr_file 
blk_file } *;
allow kernel_t unlabeled_t:filesystem *;
allow kernel_t unlabeled_t:association *;
allow kernel_t { proc_t proc_net_t }:dir search;
allow kernel_t sysctl_type:dir { read getattr lock search ioctl };
allow kernel_t sysctl_type:file { { getattr read write append ioctl lock } 
setattr };
allow kernel_t node_type:node *;
allow kernel_t netif_type:netif *;
allow kernel_t port_type:tcp_socket { send_msg recv_msg name_connect };
allow kernel_t port_type:udp_socket { send_msg recv_msg };
allow kernel_t port_type:{ tcp_socket udp_socket rawip_socket } name_bind;
allow kernel_t node_type:{ tcp_socket udp_socket rawip_socket } node_bind;
allow kernel_t unlabeled_t:association { sendto recvfrom };
allow kernel_t device_node:{ chr_file blk_file } *;
allow kernel_t mtrr_device_t:{ dir file } *;
allow kernel_t self:capability sys_rawio;
allow kernel_t domain:{ { tcp_socket udp_socket rawip_socket netlink_socket 
packet_socket unix_stream_socket unix_dgram_socket netlink_route_socket 
netlink_firewall_socket netlink_tcpdiag_socket netlink_nflog_socket 
netlink_xfrm_socket netlink_selinux_socket netlink_audit_socket 
netlink_ip6fw_socket netlink_dnrt_socket netlink_kobject_uevent_socket } 
socket key_socket } *;
allow kernel_t domain:fd use;
allow kernel_t domain:fifo_file { getattr read write append ioctl lock };
allow kernel_t domain:process ~{ transition dyntransition execmem execstack 
execheap };
allow kernel_t domain:{ sem msgq shm } *;
allow kernel_t domain:msg { send receive };
allow kernel_t domain:dir { read getattr lock search ioctl };
allow kernel_t domain:file { read getattr lock ioctl };
allow kernel_t domain:lnk_file { read getattr lock ioctl };
allow kernel_t file_type:{ file chr_file } ~execmod;
allow kernel_t file_type:{ dir lnk_file sock_file fifo_file blk_file } *;
allow kernel_t file_type:filesystem *;
allow kernel_t file_type:{ unix_stream_socket unix_dgram_socket } name_bind;
allow kernel_t file_type:file execmod;
allow kernel_t filesystem_type:filesystem *;
allow kernel_t filesystem_type:{ dir file lnk_file sock_file fifo_file 
chr_file blk_file } *;
allow kernel_t security_t:dir { getattr search read };
allow kernel_t security_t:file { getattr read write };
allow kernel_t security_t:security *;
auditallow kernel_t security_t:security { load_policy setenforce setbool };
allow kernel_t self:process execheap;
allow kernel_t self:process execmem;
allow kernel_t self:process execstack;
auditallow kernel_t self:process execstack;
auditallow kernel_t self:process execheap;
auditallow kernel_t self:process execmem;

allow kernel_t unlabeled_t:dir mounton;
allow kernel_t unlabeled_t:fifo_file { getattr read write append ioctl lock }; allow kernel_t unlabeled_t:association { sendto recvfrom };
allow kernel_t unlabeled_t:{ dir file lnk_file sock_file fifo_file chr_file blk_file } *;
allow kernel_t unlabeled_t:filesystem *;
allow kernel_t unlabeled_t:association *;
allow kernel_t unlabeled_t:association { sendto recvfrom };

allow kernel_t default_t:dir { read getattr lock search ioctl }; allow kernel_t default_t:file { read getattr lock ioctl }; allow kernel_t default_t:lnk_file { read getattr lock ioctl }; allow kernel_t default_t:sock_file { read getattr lock ioctl }; allow kernel_t default_t:fifo_file { read getattr lock ioctl };

allow file_type self:filesystem associate;
allow file_t fs_t:filesystem associate;
allow file_t noxattrfs:filesystem associate;

allow filesystem_type fs_t:filesystem associate; allow filesystem_type noxattrfs:filesystem associate;

allow proc_t self:filesystem associate;

allow sysctl_t fs_t:filesystem associate;

allow unlabeled_t self:filesystem associate;

allow kernel_t security_t:dir { read search getattr }; allow kernel_t security_t:file { getattr read write }; typeattribute kernel_t can_load_policy;

if(!secure_mode_policyload) {
	allow kernel_t security_t:security load_policy;
	auditallow kernel_t security_t:security load_policy;
}
allow kernel_t security_t:dir { getattr search read };
allow kernel_t security_t:file { getattr read write };
typeattribute kernel_t can_load_policy, can_setenforce, can_setsecparam;
if(!secure_mode_policyload) {
	# Access the security API.
	allow kernel_t security_t:security *;
	auditallow kernel_t security_t:security { load_policy setenforce setbool };
}

typeattribute security_t filesystem_type;
allow security_t self:filesystem associate; neverallow ~can_load_policy security_t:security load_policy; neverallow ~can_load_kernmodule self:capability sys_module; neverallow ~can_setenforce security_t:security setenforce; neverallow ~can_setsecparam security_t:security setsecparam;

role system_r;
role user_r;
role system_r types kernel_t;
user system_u roles { system_r };
user user_u roles { user_r system_r };
user root roles { user_r system_r };

constrain process transition

	( u1 == u2
	or t1 == can_change_process_identity
);
constrain process transition 
	( r1 == r2
	or t1 == can_change_process_role
);
constrain process dyntransition
	( u1 == u2 and r1 == r2 );
constrain { dir file lnk_file sock_file fifo_file chr_file blk_file } { create 
relabelto relabelfrom } 
	( u1 == u2 or t1 == can_change_object_identity );

constrain { tcp_socket udp_socket rawip_socket netlink_socket packet_socket unix_stream_socket unix_dgram_socket netlink_route_socket netlink_firewall_socket netlink_tcpdiag_socket netlink_nflog_socket netlink_xfrm_socket netlink_selinux_socket netlink_audit_socket netlink_ip6fw_socket netlink_dnrt_socket netlink_kobject_uevent_socket } { create relabelto relabelfrom }

	( u1 == u2 or t1 == can_change_object_identity );

sid devnull system_u:object_r:null_device_t
sid file system_u:object_r:file_t
sid fs system_u:object_r:fs_t
sid kernel system_u:system_r:kernel_t
sid sysctl system_u:object_r:sysctl_t
sid unlabeled system_u:object_r:unlabeled_t
sid any_socket system_u:object_r:unlabeled_t
sid file_labels system_u:object_r:unlabeled_t
sid icmp_socket system_u:object_r:unlabeled_t
sid igmp_packet system_u:object_r:unlabeled_t
sid init system_u:object_r:unlabeled_t
sid kmod system_u:object_r:unlabeled_t
sid netmsg system_u:object_r:unlabeled_t
sid policy system_u:object_r:unlabeled_t
sid scmp_packet system_u:object_r:unlabeled_t
sid sysctl_modprobe system_u:object_r:unlabeled_t
sid sysctl_fs system_u:object_r:unlabeled_t
sid sysctl_kernel system_u:object_r:unlabeled_t
sid sysctl_net system_u:object_r:unlabeled_t
sid sysctl_net_unix system_u:object_r:unlabeled_t
sid sysctl_vm system_u:object_r:unlabeled_t
sid sysctl_dev system_u:object_r:unlabeled_t
sid tcp_socket system_u:object_r:unlabeled_t
sid security system_u:object_r:security_t
sid port system_u:object_r:port_t
sid node system_u:object_r:node_t
sid netif system_u:object_r:netif_t

fs_use_xattr ext2 system_u:object_r:fs_t;
fs_use_xattr ext3 system_u:object_r:fs_t;
fs_use_xattr gfs system_u:object_r:fs_t;
fs_use_xattr jfs system_u:object_r:fs_t;
fs_use_xattr reiserfs system_u:object_r:fs_t;
fs_use_xattr xfs system_u:object_r:fs_t;
fs_use_task sockfs system_u:object_r:fs_t;
fs_use_trans mqueue system_u:object_r:tmpfs_t;
fs_use_trans shm system_u:object_r:tmpfs_t;
fs_use_trans tmpfs system_u:object_r:tmpfs_t;
fs_use_trans devpts system_u:object_r:devpts_t;

genfscon proc /mtrr system_u:object_r:mtrr_device_t genfscon sysfs / system_u:object_r:sysfs_t
genfscon usbfs / system_u:object_r:usbfs_t
genfscon usbdevfs / system_u:object_r:usbfs_t
genfscon rootfs / system_u:object_r:root_t
genfscon bdev / system_u:object_r:bdev_t
genfscon binfmt_misc / system_u:object_r:binfmt_misc_fs_t genfscon capifs / system_u:object_r:capifs_t
genfscon configfs / system_u:object_r:configfs_t
genfscon eventpollfs / system_u:object_r:eventpollfs_t genfscon futexfs / system_u:object_r:futexfs_t
genfscon hugetlbfs / system_u:object_r:hugetlbfs_t
genfscon inotifyfs / system_u:object_r:inotifyfs_t
genfscon nfsd / system_u:object_r:nfsd_fs_t
genfscon ramfs / system_u:object_r:ramfs_t
genfscon romfs / system_u:object_r:romfs_t
genfscon cramfs / system_u:object_r:romfs_t
genfscon rpc_pipefs / system_u:object_r:rpc_pipefs_t genfscon autofs / system_u:object_r:autofs_t
genfscon automount / system_u:object_r:autofs_t
genfscon cifs / system_u:object_r:cifs_t
genfscon smbfs / system_u:object_r:cifs_t
genfscon fat / system_u:object_r:dosfs_t
genfscon msdos / system_u:object_r:dosfs_t
genfscon ntfs / system_u:object_r:dosfs_t
genfscon vfat / system_u:object_r:dosfs_t
genfscon iso9660 / system_u:object_r:iso9660_t
genfscon udf / system_u:object_r:iso9660_t
genfscon nfs / system_u:object_r:nfs_t
genfscon nfs4 / system_u:object_r:nfs_t
genfscon afs / system_u:object_r:nfs_t
genfscon debugfs / system_u:object_r:debugfs_t
genfscon proc / system_u:object_r:proc_t
genfscon proc /sysvipc system_u:object_r:proc_t
genfscon proc /kmsg system_u:object_r:proc_kmsg_t
genfscon proc /kcore system_u:object_r:proc_kcore_t genfscon proc /mdstat system_u:object_r:proc_mdstat_t genfscon proc /net system_u:object_r:proc_net_t
genfscon proc /sys system_u:object_r:sysctl_t
genfscon proc /irq system_u:object_r:sysctl_irq_t
genfscon proc /net/rpc system_u:object_r:sysctl_rpc_t genfscon proc /sys/fs system_u:object_r:sysctl_fs_t genfscon proc /sys/kernel system_u:object_r:sysctl_kernel_t genfscon proc /sys/kernel/modprobe system_u:object_r:sysctl_modprobe_t genfscon proc /sys/kernel/hotplug system_u:object_r:sysctl_hotplug_t genfscon proc /sys/net system_u:object_r:sysctl_net_t genfscon proc /sys/net/unix system_u:object_r:sysctl_net_unix_t genfscon proc /sys/vm system_u:object_r:sysctl_vm_t genfscon proc /sys/dev system_u:object_r:sysctl_dev_t genfscon selinuxfs / system_u:object_r:security_t

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

#258 lore raw

Re: [2/4] Labeling only policy for fireflier (fireflier.pp)

[this policy (together with the base in mail [1/4]) is intended for systems where there is no selinux by default. for selinux enabled systems i'll create modules to be used with reference policy, i'll send that in a separate mail when it will be ready]

Still I want to provide "some" protection against changing labels (it would be just too easy to escape protection, but only for root, right?)

So I implemented something similar to what selinuxutil.te does to protect the module store, and also restricted policy loading to only a few domains. Also restricted policy loading/setbool/setenforce with booleans. Also restricted module loading, and rawio.

I didn't use the unconfined interfaces from the reference policy, since they allowed too much rights to programs (IMHO). So I modified them to fit my needs, and put them in unconfined_norelabel.if.

So nobody besides a domain with policymanager attribute can load policy, and nobody besides them are allowed to change the module store.
Any bypasses?
Of course if somebody replaces load_policy he can load any policy (but that isn't possible with this policy, right?). If load_policy & friends aren't statically linked, than someone can bypass it by changing libc, and protecting against that brings me very close to strict policy. So let's assume that load_policy would be statically linked, and it would get a sanitized environment.

The module store is managed via semodule, so it has to have write access. The problem is whom I allow to execute semodule, because anybody doing that will override my policy. So I restricted transition to semanage_t only for policymanager domains.

Last I have a program named policymanager, that will generate the policy (doesn't exist yet). Obviously this will be the weakest link in the chain. So in the end, I am not sure it is worth all this policy store protection, maybe I could do with a simpler policy.

Maybe just using auditallow&allow for loading policy protected with a boolean would be enough? (audit: so that the sysadmin thas the chance to know somebody changed the policy, if he uses remote logging, otherwise all is lost if somebody changes policy.) But then somebody could just replace the binary policy, and have it loaded automatically on next reboot?

(why i don't want too much protection against root:
- if somebody didn't have selinux, with fireflier 1.1.x somebody could just
have deleted the iptables rules to bypass fireflier's protection. You can't get real protection against this, unless you use a strict policy,right? Also I don't intend to make fireflier an selinux rule management tool,besides there are some nice tools from tresys that do that ;)
)

fireflier.te:
-----
policy_module(fireflier,0.1.0)
########################################
#
# Declarations
#
gen_require(`

	      type file_t;
	      type sbin_t;
	      bool secure_mode_policyload;
	      bool secure_mode;
	      type selinux_config_t;

')
bool dac_override_audit true;

type fireflier_unconfined_t;

attribute can_unconfined_sockets;
attribute fireflier_unconfined_domain;
attribute has_restricted_sockets;

fireflier_unconfined(fireflier_unconfined_t,file_t,can_unconfined_sockets) domain_auto_trans(fireflier_unconfined_domain,file_t,fireflier_unconfined_t) kernel_domtrans_to(fireflier_unconfined_t,sbin_t)
neverallow fireflier_unconfined_t file_type:file {relabelfrom relabelto};

attribute policymanager;

gen_policymanager_type(load_policy)
gen_policymanager_type(boolset)
gen_policymanager_type(semanage)
gen_policymanager_type(restorecon) gen_policymanager_type(policy_manager) domain_auto_trans(fireflier_unconfined_domain,policy_manager_exec_t,policy_manager_t)

attribute policy_config;
type policy_config_t;
typeattribute policy_config_t policy_config;
typeattribute selinux_config_t policy_config;
#avoiding files_type(policy_config_t), because unconfined domains have access to all files
allow policy_config_t fs_t:filesystem associate;
allow selinux_config_t fs_t:filesystem associate;

type_transition domain policy_config_t:{dir file lnk_file} policy_config_t; attribute can_relabelto_binary_policy;
neverallow ~can_relabelto_binary_policy policy_config_t:file relabelto;

type semanage_lock_t;
allow semanage_lock_t fs_t:filesystem associate;
allow load_policy_t semanage_lock_t:file rw_file_perms; allow load_policy_t selinux_config_t:file rw_file_perms; allow fireflier_unconfined_domain semanage_lock_t:file rw_file_perms;

typeattribute restorecon_t can_relabelto_binary_policy;
allow restorecon_t self:capability { dac_override dac_read_search fowner }; allow restorecon_t self:fifo_file rw_file_perms;
allow fireflier_unconfined_domain policy_config :dir r_dir_perms; allow fireflier_unconfined_domain policy_config :file r_file_perms; allow fireflier_unconfined_domain policy_config :lnk_file r_file_perms; allow fireflier_unconfined_domain policy_config:dir search;

if(!secure_mode_policyload) {
	auditallow load_policy_t security_t:security {load_policy};
	allow load_policy_t security_t:security {load_policy};
	auditallow boolset_t security_t:security {setbool};
	allow boolset_t security_t:security {setbool};
	auditallow semanage_t policy_config_t:file { read write };
	allow semanage_t policy_config_t:file { read write lock create unlink 
rename};
	allow semanage_t selinux_config_t:file { read write lock create unlink 
rename};	
	allow semanage_t unlabeled_t:process sigchld;
	allow semanage_t policy_config_t:dir { read write getattr unlink create 

rename add_name remove_name rmdir};
allow semanage_t selinux_config_t:dir { read write getattr unlink create
rename add_name remove_name rmdir};
}
if(!secure_mode) {
auditallow restorecon_t {selinux_config_t policy_config_t file_type}:{dir

file} {relabelfrom relabelto};
	allow restorecon_t {selinux_config_t policy_config_t file_type}:{dir file} 

{relabelfrom relabelto};
}
#allow fireflier_unconfined_domain selinux_config_t:{dir file} *;

#from test_module

-----------
fireflier.if:
-------------
########################################
## <summary>
## Make the specified domain unconfined.
## Except that it does not allow it to change labels, and load policy
## </summary>
## <param name="domain">

##      <summary>
##      Domain to make unconfined.
##      </summary>

## </param>
## <param name="entrypoint">
## <summary>
## File entry
## </summary>
## </param>
## <param name="attribute">
## <summary>
## Attribute needed to get access to socket
## </summary>
## </param>

#
interface(fireflier_unconfined',

        gen_require(`
            role system_r;
			attribute fireflier_unconfined_domain;
			type security_t;
			bool secure_mode;
			bool secure_mode_insmod;
			bool dac_override_audit;
        ')

        domain_type($1)
        domain_entry_file($1,$2)


        role system_r types $1;
		role user_r	  types $1;
		
		allow $1 self:capability ~{sys_module sys_rawio dac_override 
dac_read_search};
		if(!secure_mode && dac_override_audit) {
				 auditallow $1 self:capability {dac_override dac_read_search};
		}
		if (!secure_mode) {
		   allow $1 self:capability {dac_override dac_read_search};
		}
		
		allow $1 self:fifo_file create_file_perms;
		allow $1 self:process transition;
		allow $1 self:security ~{setenforce load_policy setbool setsecparam 
setcheckreqprot};
	 	allow $1 security_t:security ~{setenforce load_policy setbool setsecparam 
setcheckreqprot};
		
		kernel_unconfined_norelabel($1)
		kernel_load_module_safe($1)
		corenet_unconfined($1)
        dev_unconfined_norawio($1)
        domain_unconfined_norelabel($1)
        domain_dontaudit_read_all_domains_state($1)
        files_unconfined_norelabel($1)
        fs_unconfined_norelabel($1)

		typeattribute $1 $3;

		neverallow $1 domain:{file sock_file} {relabelfrom relabelto};
		neverallow ~$3 domain:{socket_class_set socket key_socket} *;
		
		allow $1 self:process execheap;
		allow $1 self:process execmem;
		allow $1 self:process execstack;
	        allow $1 self:{socket_class_set socket key_socket} *;
		
		allow $1 domain:process getattr;
		allow $1 device_t:{chr_file blk_file} getattr;
		allow $3 $1:{socket_class_set socket key_socket} *;
		typeattribute $1 fireflier_unconfined_domain;

')

########################################
## <summary>

##      Generates an unconfined domain.
##      Except that it does not allow it to change labels, and load policy
##      It will generate: $1_t,$1_exec_t,has_$1_socket_access

## </summary>
## <param name="domain">
## <summary>
## Base name
## </summary>
## </param>

#
interface(fireflier_gen_unconfined_type',
gen_require(`

   		attribute has_restricted_sockets;
		type file_t;
		type fireflier_unconfined_t;

')
type $1_t;
type $1_exec_t;

attribute has_$1_socket_access; files_type($1_exec_t)
typeattribute $1_t has_restricted_sockets; fireflier_unconfined($1_t,$1_exec_t,has_$1_socket_access) domain_auto_trans(fireflier_unconfined_domain,$1_exec_t,$1_t)
# domain_auto_trans($1_t,file_t,fireflier_unconfined_t)
')

########################################
## <summary>
## Allows access for @domain to @restricted's sockets
## </summary>
## <param name="domain">
## <summary>
## The domain that needs access granted
## </summary>
## </param>
## <param name="restricted">
## <summary>
## The domain that has the restricted socket
## </summary>
## </param>

#
interface(allow_access_to_socket',

    gen_require(`
    		 attribute has_$1_socket_access;
		 type $2_t;
    ')
    typeattribute $2_t has_$1_socket_access;

')

########################################
## <summary>
## Unconfined type, that can modify the policy somehow
## Cannot be executed from other unconfined domains
## </summary>
## <param name="base">
## <summary>
## The base name
## </summary>

#
interface(gen_policymanager_type',

    gen_require(`
    		 attribute policymanager;
    ')
    type $1_t;
    type $1_exec_t;
   
    typeattribute $1_t policymanager;
    attribute has_$1_socket_access;
    fireflier_unconfined($1_t,$1_exec_t,has_$1_socket_access)
    neverallow ~policymanager $1_t:process transition;
    neverallow ~policymanager $1_exec_t:file {write unlink relabelfrom 
relabelto};
    domain_auto_trans(policymanager,$1_exec_t,$1_t)

')

---------------
fireflier.fc:
-------------
/etc/selinux/fireflier/modules/semanage.read.LOCK --
gen_context(system_u:object_r:semanage_lock_t,s0)
/etc/selinux/fireflier/modules/semanage.trans.LOCK --
gen_context(system_u:object_r:semanage_lock_t,s0)
/etc/selinux(/.*)? gen_context(system_u:object_r:selinux_config_t,s0)
/etc/selinux/([^/]*/)?contexts(/.*)? gen_context(system_u:object_r:policy_config_t,s0) /etc/selinux/([^/]*/)?policy(/.*)? gen_context(system_u:object_r:policy_config_t,s15:c0.c255)
/etc/selinux/([^/]*/)?seusers --
gen_context(system_u:object_r:selinux_config_t,s15:c0.c255)
/etc/selinux([^/]*/)?modules/(active|tmp|previous)(/.*)? --
gen_context(system_u:object_r:policy_config_t,s0)
/etc/selinux/([^/]*/)?users(/.*)? --
gen_context(system_u:object_r:policy_config_t,s15:c0.c255)
/sbin/load_policy -- gen_context(system_u:object_r:load_policy_exec_t,s0)
/usr/sbin/load_policy -- gen_context(system_u:object_r:load_policy_exec_t,s0)
/sbin/restorecon -- gen_context(system_u:object_r:restorecon_exec_t,s0)
/usr/sbin/semodule -- gen_context(system_u:object_r:semanage_exec_t,s0)
/usr/sbin/setsebool -- gen_context(system_u:object_r:boolset_exec_t,s0)
/usr/sbin/setenforce -- gen_context(system_u:object_r:load_policy_exec_t,s0)

/usr/sbin/policymanager --
gen_context(system_u:object_r:policy_manager_exec_t,s0)

unconfined_norelabel.if
----------
## <summary>fireflier policy generation</summary>
########################################
## <summary>
## Unconfined access to devices, except rawio
## </summary>
## <param name="domain">

##      <summary>
##      Domain allowed access.
##      </summary>
## </param>
#
interface(`dev_unconfined_norawio',`
        gen_require(`
                attribute device_node, memory_raw_write, memory_raw_read;
                type mtrr_device_t;
        ')
	allow $1 device_node:{ dir lnk_file sock_file fifo_file blk_file chr_file} *;
        allow $1 mtrr_device_t:{ dir file } *;

')
########################################
## <summary>
## Unconfined access to domains, except relabeling
## </summary>
## <param name="domain">

##      <summary>
##      The type of the process performing this action.
##      </summary>
## </param>
#
interface(`domain_unconfined_norelabel',`
        gen_require(`
                attribute domain, set_curr_context;
		attribute has_restricted_sockets;
        ')
        # Use/sendto/connectto sockets created by any domain.
        allow $1 {domain - has_restricted_sockets}:{ socket_class_set socket 

key_socket } *;

# Use descriptors and pipes created by any domain. allow $1 domain:fd use;
allow $1 domain:fifo_file rw_file_perms;

# Act upon any other process.
allow $1 domain:process ~{ transition dyntransition execmem execstack
execheap setcurrent};

        # Create/access any System V IPC objects.
        allow $1 domain:{ sem msgq shm } *;
        allow $1 domain:msg { send receive };

        # For /proc/pid
        allow $1 domain:dir r_dir_perms;
        allow $1 {domain}:file r_file_perms;
        allow $1 domain:lnk_file r_file_perms;

')

########################################
## <summary>
## Unconfined access to kernel module resources, except relabeling
## </summary>
## <param name="domain">

##      <summary>
##      Domain allowed access.
##      </summary>
## </param>
#
interface(`kernel_unconfined_norelabel',`
        gen_require(`
                type kernel_t, unlabeled_t, sysctl_t;
                attribute proc_type, sysctl_type;
                attribute kern_unconfined;
                attribute can_load_kernmodule, can_receive_kernel_messages;
        ')

        allow $1 proc_type:{ dir file } ~{relabelfrom relabelto};

        allow $1 sysctl_t:{ dir file } ~{relabelfrom relabelto};

        allow $1 kernel_t:system *;

        allow $1 unlabeled_t:dir_file_class_set ~{relabelfrom relabelto};
        allow $1 unlabeled_t:filesystem *;
        allow $1 unlabeled_t:association *;

        typeattribute $1 can_load_kernmodule, can_receive_kernel_messages;
        typeattribute $1 kern_unconfined;

        kernel_rw_all_sysctls($1)

')
########################################
## <summary>
## Unconfined access to files, except relabeling
## </summary>
## <param name="domain">

##      <summary>
##      Domain allowed access.
##      </summary>
## </param>
#
interface(`files_unconfined_norelabel',`
        gen_require(`
                attribute file_type;
        ')

        # Create/access any file in a labeled filesystem;
        allow $1 file_type:{ file chr_file} ~{ execmod relabelfrom 
relabelto };
        allow $1 file_type:{ dir lnk_file fifo_file blk_file } *;
#	allow $1 {file_type -has_restricted_sockets}:sock_file *;
	allow $1 file_type:sock_file *;

        # Mount/unmount any filesystem with the context= option.
        allow $1 file_type:filesystem *;

        # Bind to any network address.
        # cjp: need to check this, I dont think this has any effect.
        allow $1 file_type:{ unix_stream_socket unix_dgram_socket } name_bind;

        allow $1 file_type:file execmod;

')

########################################
## <summary>
## Unconfined access to filesystems, except relabeling
## </summary>
## <param name="domain">

##      <summary>
##      Domain allowed access.
##      </summary>
## </param>
#
interface(`fs_unconfined_norelabel',`
        gen_require(`
                attribute filesystem_type;
        ')

        allow $1 filesystem_type:filesystem ~{relabelfrom relabelto};

        # Create/access other files.  fs_type is to pick up various
        # pseudo filesystem types that are applied to both the filesystem
        # and its files.
        allow $1 filesystem_type:{ dir file lnk_file sock_file fifo_file } 
~{relabelfrom relabelto};
	allow $1 filesystem_type:{ blk_file chr_file } *;

')

########################################
## <summary>
## Allows caller to load kernel modules, if !secure_mode_insmod
## </summary>
## <param name="domain">
## <summary>
## The process type to allow to load kernel modules.
## </summary>
## </param>
#
interface(kernel_load_module_safe',

	gen_require(`
		attribute can_load_kernmodule;
	')
	if(!secure_mode_insmod) {
				allow $1 self:capability sys_module;
				}
				typeattribute $1 can_load_kernmodule;

')

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

#259 lore raw

PATCH 3/4 Labeling only policy for fireflier (example module)

This is an example module that fireflier would generate for a certain program.

myapp1_t's sockets can only be accesses by myapp2, but not by other unconfined processes, and not by myapp3.
myapp2, and myapp3's sockets can't be accesses except by themselves. fireflier_unconfined_t's sockets can be accessed by anybody.

I included the policy files, and a test program below.
Let's suppose these programs aren't run as root. Can they bypass selinux security context labels?(can they change them?)

test_module.te:
--------------
policy_module(test_module,0.1)
fireflier_gen_unconfined_type(myapp1)
fireflier_gen_unconfined_type(myapp2)
fireflier_gen_unconfined_type(myapp3)

allow_access_to_socket(myapp1,myapp2)

------
test_module.fc
-----
/home/edwin/p2 --
gen_context(system_u:object_r:myapp2_exec_t,s0)
/home/edwin/p3 -- gen_context(system_u:object_r:myapp3_exec_t,s0
/home/edwin/p1 --
gen_context(system_u:object_r:myapp1_exec_t,s0)
/home/edwin/p4 --
gen_context(system_u:object_r:myapp1_exec_t,s0)

--------------p1.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
void die(const char* msg)
{
perror(msg);
exit(1);
}

void showattr(int fd)
{
const char security_name[] = "security.selinux"; ssize_t len = fgetxattr(fd,security_name,NULL,0); if (len==-1)

     return;

size_t i;

   char* list = malloc(len+1);
   if((len = fgetxattr(fd,security_name,list,len))==-1)
     die("error getting xattr");
   list[len]=0;
   for(i=0;i<len;i++)
     if(!list[i]) list[i]='\n';   
   printf("\nsecurity context of %d  is: %s",fd,list);
   free(list);

}

int main(int argc,char* argv[])
{
if(argc<3)

     {
	printf("usage: %s <childname> <port>\n",argv[0]);
	return 1;
     }
   int fd = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
   if(fd<0)
     die("socket() failed");
   struct sockaddr_in servaddr;
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(atoi(argv[2]));
   if(bind(fd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
     die("bind() failed");
   if(listen(fd,3)<0)
     die("listen() failed");
   int newfd2 =  accept(fd,NULL,NULL);
   if(newfd2<0)
     die("accept() failed");

showattr(fd);
showattr(newfd2);
system(argv[1]);
if(fork()==0)

     {   
	execl(argv[1],argv[1],(char*)NULL);
     }

close(newfd2);
close(fd);
return 0;
}

-------------p2.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <attr/xattr.h>
#include <string.h>
#include <netinet/in.h>

void die(const char* msg)
{
perror(msg);
exit(1);
}

char* linkname(int fd)
{
char fmt[] = "/proc/self/fd/%d";
const int namebufsiz = strlen(fmt)+16;
char* namebuf = malloc(namebufsiz);
char* buf = NULL;

snprintf(namebuf,namebufsiz,fmt,fd);
int res = 0,bufsiz=0;

   do{
      bufsiz += 16;
      buf  = realloc(buf,bufsiz);
      res = readlink(namebuf,buf,bufsiz);
      if (res == -1)
	die("readlink error");

} while (res==bufsiz);
free(namebuf);
return buf;
}

void showattr(int fd)
{
const char security_name[] = "security.selinux"; ssize_t len = fgetxattr(fd,security_name,NULL,0); if (len==-1)

     return;
   char* name = linkname(fd);
   size_t i;

   char* list = malloc(len+1);
   if((len = fgetxattr(fd,security_name,list,len))==-1)
     die("error getting xattr");
   list[len]=0;
   for(i=0;i<len;i++)
     if(!list[i]) list[i]='\n';   
   printf("\nsecurity context of %d (%s) is: %s",fd,name,list);
   free(name);
   free(list);

struct stat sbuf;
if(fstat(fd,&sbuf)==-1)

     perror("stat error");
   else 
     {
	if(!S_ISSOCK(sbuf.st_mode)) 
	  {
	     printf("not a socket");
	     if(fd<3)
	       return;
	  }	
     }

//read from it
char x[16];
socklen_t socklen = 16;
struct sockaddr* sa=malloc(socklen);
struct msghdr msg;
if(read(fd,x,sizeof(x))==-1)

     perror("read failed");
   else
     printf("%s\n",x);
   if(recv(fd,&x,1,MSG_DONTWAIT)==-1)
     perror("recv failed");
   if(recvfrom(fd,&x,1,MSG_DONTWAIT,sa,&socklen)==-1)
     perror("recvfrom failed");
   if(recvmsg(fd,&msg,MSG_DONTWAIT)==-1)
     perror("recvmsg failed");
   if(listen(fd,3)<0)
     perror("listen failed");
   if(accept(fd,NULL,NULL))
     perror("accept failed");
   struct sockaddr_in servaddr;
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(5611);
   if(connect(fd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
     perror("connect failed");
   if(bind(fd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0)
     perror("bind failed");
}

int main()
{
int fds,fd;
if((fds = getdtablesize()) == -1) fds=255;
for(fd=0;fd<fds;fd++)

     showattr(fd);

system("ps -Z");
}

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

#260 lore raw

Re: [2/4] Labeling only policy for fireflier (fireflier.pp)

In reply to Török Edwin
Quoted 7 lines · Török Edwin

[this policy (together with the base in mail [1/4]) is intended for systems where there is no selinux by default. for selinux enabled systems i'll create modules to be used with reference policy, i'll send that in a separate mail when it will be ready]

Still I want to provide "some" protection against changing labels (it would be just too easy to escape protection, but only for root, right?)

Even if you can't relabel the file you could just delete it and recreate it with the new label using setfscreatecon, since it has all the other file perms.

Quoted 5 lines

So I implemented something similar to what selinuxutil.te does to protect the module store, and also restricted policy loading to only a few domains. Also restricted policy loading/setbool/setenforce with booleans. Also restricted module loading, and rawio.

Quoted 7 lines

I didn't use the unconfined interfaces from the reference policy, since they allowed too much rights to programs (IMHO). So I modified them to fit my needs, and put them in unconfined_norelabel.if.

So nobody besides a domain with policymanager attribute can load policy, and nobody besides them are allowed to change the module store.
Any bypasses?

It looks like you have raw disk access, so thats at least one. It may not allow you to load the policy, but it allows you to modify the policy on disk, and next time its loaded (e.g., reboot), you get the modified policy.

Quoted 2 lines

Of course if somebody replaces load_policy he can load any policy (but that isn't possible with this policy, right?).

You have to have the load_policy permission or transition to a domain that has the permission. If you have neither of these, then you should be ok. The catch is if you can alter the policy (see above), then you could get someone else to load the policy (e.g., reboot). If you can alter the load_policy binary or its libraries then you could make it do anything within limits of the domain it runs in.

Quoted 5 lines

If load_policy & friends aren't
statically linked, than someone can bypass it by changing libc, and protecting against that brings me very close to strict policy. So let's assume that load_policy would be statically linked, and it would get a sanitized environment.

See above comment.

Quoted 10 lines

The module store is managed via semodule, so it has to have write access. The problem is whom I allow to execute semodule, because anybody doing that will override my policy. So I restricted transition to semanage_t only for policymanager domains.

Last I have a program named policymanager, that will generate the policy (doesn't exist yet). Obviously this will be the weakest link in the chain. So in the end, I am not sure it is worth all this policy store protection, maybe I could do with a simpler policy.

Quoted 5 lines

Maybe just using auditallow&allow for loading policy protected with a boolean would be enough? (audit: so that the sysadmin thas the chance to know somebody changed the policy, if he uses remote logging, otherwise all is lost if somebody changes policy.) But then somebody could just replace the binary policy, and have it loaded automatically on next reboot?

Right.

Quoted 4 lines

(why i don't want too much protection against root:
- if somebody didn't have selinux, with fireflier 1.1.x somebody could just
have deleted the iptables rules to bypass fireflier's protection. You can't get real protection against this, unless you use a strict policy,right?

So off the top of my head, it sounds like the policy should at least restrict net_admin capability, protect all the files that iptables_t accesses and its libraries, protect the policy, protect policy loading, protect load_policy and its libraries. That affects a lot of files since it includes some generic types like etc_t, lib_t, and shlib_t.

Quoted 3 lines

Also I don't intend to make fireflier an selinux rule management tool,besides there are some nice tools from tresys that do that ;)
)

You should try out apol from setools to help analyze your policy.

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
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.
#261 lore raw

PATCH 4/4 Labeling only policy for fireflier (install)

In reply to Török Edwin

This is an install script I would use to install this policy.
I put those mkdir/touch there, because otherwise semodule failed on a system with no policy installed.
Is anything I should watch out for when installing policy on a system that doesn't yet have selinux policy? (but it has the required libs, and binaries from policycoreutils).

This install script is to be used before selinux is enabled (i.e. selinux=0 on boot), and then doing a reboot with selinux=1 should "just work" (i.e. without any avc denied messages on boot).

I tested this on a virtual machine, and will test it on different distributions on real machines soon, but in the meantime has anybody encountered any problems when setting up selinux?
(I encountered a segfault with semodule, but it got fixed with an upgrade of libs+tools, not sure which package/version fixed it)

base contains fireflier_base.pp generated from fireflier_base.conf (see [1/4]) generator contains fireflier.pp generated from fireflier.te, fireflier.fc, fireflier.if, unconfined_norelabel.if (see [2/4])

------install.sh
#!/bin/sh
AWK=awk
SEMODULE=/usr/sbin/semodule

SELINUX_ROOT=/etc/selinux
SELINUX_CONFIG=$SELINUX_ROOT/config
SELINUX_CONFIG_OLD=$SELINUX_ROOT/config.old
SELINUX_SEMANAGE_CONF=$SELINUX_ROOT/semanage.conf

FIREFLIER_POLICY_NAME=fireflier FIREFLIER_POLICY_ROOT=$SELINUX_ROOT/$FIREFLIER_POLICY_NAME FIREFLIER_POLICY_BASE=base/fireflier_base.pp FIREFLIER_POLICY_BASE_MOD=generator/fireflier.pp

if [ ! -e $SELINUX_SEMANAGE_CONF ]; then
echo "You don't have an semanage.conf file, creating one"; cat >$SELINUX_SEMANAGE_CONF <<EOF
# Specify how libsemanage will interact with a SELinux policy manager. # The four options are:
#

#  "source"     - libsemanage manipulates a source SELinux policy
#  "direct"     - libsemanage will write directly to a module store.
#  /foo/bar     - Write by way of a policy management server, whose
#                 named socket is at /foo/bar.  The path must begin
#                 with a '/'.
#  foo.com:4242 - Establish a TCP connection to a remote policy
#                 management server at foo.com.  If there is a colon
#                 then the remainder is interpreted as a port number;
#                 otherwise default to port 4242.

module-store = direct

# When generating the final linked and expanded policy, by default

# semanage will set the policy version to POLICYDB_VERSION_MAX, as
# given in <sepol/policydb.h>.  Change this setting if a different
# version is necessary.
#policy-version = 19     
EOF
fi

mkdir -p $FIREFLIER_POLICY_ROOT
mkdir -p $FIREFLIER_POLICY_ROOT/policy
mkdir -p $FIREFLIER_POLICY_ROOT/modules
mkdir -p $FIREFLIER_POLICY_ROOT/modules/active mkdir -p $FIREFLIER_POLICY_ROOT/contexts
mkdir -p $FIREFLIER_POLICY_ROOT/contexts/files touch $FIREFLIER_POLICY_ROOT/modules/active/policy.kern touch $FIREFLIER_POLICY_ROOT/modules/active/homedir_template touch $FIREFLIER_POLICY_ROOT/modules/active/file_contexts touch $FIREFLIER_POLICY_ROOT/modules/active/seusers.final

$SEMODULE -v -b $FIREFLIER_POLICY_BASE -s $FIREFLIER_POLICY_NAME $SEMODULE -v -i $FIREFLIER_POLICY_BASE_MOD -s $FIREFLIER_POLICY_NAME

if [ -e $SELINUX_CONFIG_OLD ]; then
echo "";
echo " $SELINUX_CONFIG_OLD already exists, please move it to a safe
place, and then delete it";

    echo "  Aborting script!";

exit;
fi

if [ -e $SELINUX_CONFIG ]; then
echo "Backing up SELinux configuration $SELINUX_CONFIG to
$SELINUX_CONFIG_OLD"
cp $SELINUX_CONFIG $SELINUX_CONFIG_OLD
echo "Switching to $FIREFLIER_POLICY_NAME policy" CURRENT_TYPE=$AWK -F= '/^SELINUXTYPE/{ print $2 }' $SELINUX_CONFIG sed -s s/$CURRENT_TYPE/$FIREFLIER_POLICY_NAME/ $SELINUX_CONFIG_OLD >
$SELINUX_CONFIG
echo "Switching to enforcing mode"
CURRENT_MODE=$AWK -F= '/^SELINUX=/{ print $2 }' $SELINUX_CONFIG sed -s s/$CURRENT_MODE/enforcing/ $SELINUX_CONFIG_OLD > $SELINUX_CONFIG
else
echo "Generating initial policy config"
mkdir -p $SELINUX_ROOT
cat >$SELINUX_CONFIG <<EOF

# used by init
SELINUX=enforcing
# active policy
SELINUXTYPE=fireflier
EOF
fi

echo "Setting up initial labels on critical locations"
setfiles $FIREFLIER_POLICY_ROOT/contexts/files/file_contexts $FIREFLIER_POLICY_ROOT /sbin /usr/sbin /etc/selinux/config
chcon system_u:object_r:semanage_lock_t $FIREFLIER_POLICY_ROOT/modules/*.LOCK

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

#262 lore raw

Re: [1/4] Labeling only policy for fireflier

In reply to Török Edwin
Quoted 6 lines · Török Edwin

Hi,
[I have split this mail in several parts for easier reading.]

I have create a stripped down policy for use with fireflier.
(for those who didn't read the entire thread: the purpose of this policy is to provide labels for sockets, to be used with skfilter/secmark)

It would be better if you could give the source files and/or a diff from reference policy, rather than expanded base.conf, etc. It'll be much simpler to understand.

Quoted 5 lines

This policy doesn't intend to protect from the actions of root (since as Stephen Smalley suggested that would eventually lead me closer to the strict policy).

So I made many types aliases, but I left the flask classess,

Just so you know, you definitely wouldn't want to change the classes; they need to match up with the kernel.

Quoted 2 lines

initial sids,
genfs intact.

I think this can answer your remaining questions: SELinux checks are in addition to the regular linux DAC; thus, users can, at most, do the same things they can do on a regular linux system. If something is denied by linux DAC it won't even get to the SELinux checks.

Quoted 14 lines

If a user is not root is he able to override the security context of a process/file/socket? (relabel, or otherwise change context)

Furthermore, if a user is not root, load_policy/restorecon/setfiles won't function, am I right? Even if the user recompiles them (to remove any uid==0 checks)?

I've also seen a capability named dac_override, it is needed when root needs to override dac (creating a file in the user's home directory, for example), but a user can't gain that capability, right? (IOW if DAC denies something, selinux won't allow it either)

So if I intend to provide no protection from root, I could use an even simpler base policy?

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
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.
#263 lore raw

Re: [1/4] Labeling only policy for fireflier

Quoted 11 lines · Christopher J. PeBenito
Quoted 6 lines · Török Edwin

Hi,
[I have split this mail in several parts for easier reading.]

I have create a stripped down policy for use with fireflier. (for those who didn't read the entire thread: the purpose of this policy is to provide labels for sockets, to be used with skfilter/secmark)

It would be better if you could give the source files and/or a diff from reference policy, rather than expanded base.conf, etc. It'll be much simpler to understand.

I have sent the diff inline in my previous mail, unfortunately it was too large (exceeded this mailing list's maximum).Sorry about this.

I uploaded the policy diffs here:
http://edwintorok.googlepages.com/policy.diff
http://edwintorok.googlepages.com/conf.diff

Policy.diff is the diff of my modifications to reference policy. I used the reference policy, with these modules in base:
selinux,files,filesystem,kernel,domain,corenetwork. I then hand-edited the generated conf file, making certain types aliases, and removed the portcon statements.
Conf.diff is the diff of base.conf generated by a reference policy build, and my fireflier_base.conf.

Edwin

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

#264 lore raw

RFC PATCH 3/7 sidtab - hashtable to store SIDs

In reply to Török Edwin

This is the sidtab.c from SELinux, adapted to use the context structure specific to fireflier.

This patch is not meant to modify sidtab.c from SELinux!
It is meant to copy sidtab.c from SELinux, make the required changes, and put it into the fireflier_lsm directory.

How can I prevent this code duplication? I'd prefer not to duplicate files like this.

---
 sidtab.c |   42 ++++++++++++++++++++----------------------
 sidtab.h |   34 ++++++++++++++++------------------
 2 files changed, 36 insertions(+), 40 deletions(-)

--- /home/edwin/kernel/linux-2.6.16/security/selinux/ss/sidtab.c 2006-02-10
09:22:48.000000000 +0200
+++ fireflier_lsm/sidtab.c 2006-04-07 15:06:00.000000000 +0300
@@ -1,16 +1,19 @@
/*
* Implementation of the SID table type.
*
- * Author : Stephen Smalley, <[email protected]>
+ * Heavily based on selinux/ss/sidtab.c
+ * Original author : Stephen Smalley, <[email protected]>
+ *
+ * Modified for fireflier by: Török Edwin <[email protected]> */
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/sched.h>
-#include "flask.h"
-#include "security.h"
#include "sidtab.h"
+#include "constants.h"

#define SIDTAB_HASH(sid) \
(sid & SIDTAB_HASH_MASK)
@@ -29,13 +32,13 @@ int sidtab_init(struct sidtab *s)
for (i = 0; i < SIDTAB_SIZE; i++)
s->htable[i] = NULL;
s->nel = 0;
- s->next_sid = 1;
+ s->next_sid = FIREFLIER_SECINITSID_KERNEL+1;
s->shutdown = 0;
INIT_SIDTAB_LOCK(s);
return 0;
}

-int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) +int sidtab_insert(struct sidtab *s, u32 sid, const struct context *context)
{
int hvalue, rc = 0;
struct sidtab_node *prev, *cur, *newnode;
@@ -64,12 +67,7 @@ int sidtab_insert(struct sidtab *s, u32
goto out;
}
newnode->sid = sid;
- if (context_cpy(&newnode->context, context)) {
- kfree(newnode);
- rc = -ENOMEM;
- goto out;
- }
-
+ context_cpy(&newnode->context,context);
if (prev) {
newnode->next = prev->next;
wmb();
@@ -83,10 +81,10 @@ int sidtab_insert(struct sidtab *s, u32
s->nel++;
if (sid >= s->next_sid)
s->next_sid = sid + 1;
return rc;
}

-struct context *sidtab_search(struct sidtab *s, u32 sid) +const struct context *sidtab_search(struct sidtab *s, u32 sid)
{
int hvalue;
struct sidtab_node *cur;
@@ -102,7 +100,7 @@ struct context *sidtab_search(struct sid

if (cur == NULL || sid != cur->sid) {
/* Remap invalid SIDs to the unlabeled SID. */
- sid = SECINITSID_UNLABELED;
+ sid = FIREFLIER_SID_UNLABELED;
hvalue = SIDTAB_HASH(sid);
cur = s->htable[hvalue];
while (cur != NULL && sid > cur->sid)
@@ -111,6 +109,6 @@ struct context *sidtab_search(struct sid
return NULL;
}

- return &cur->context;
+ return cur->context;
}

void sidtab_map_remove_on_error(struct sidtab *s,
int (*apply) (u32 sid,
- struct context *context,
+ const struct context *context,
void *args),
void *args)
{
@@ -155,7 +129,7 @@ void sidtab_map_remove_on_error(struct s
last = NULL;
cur = s->htable[i];
while (cur != NULL) {
- ret = apply(cur->sid, &cur->context, args);
+ ret = apply(cur->sid, cur->context, args);
if (ret) {
if (last) {
last->next = cur->next;
@@ -165,7 +139,7 @@ void sidtab_map_remove_on_error(struct s

temp = cur;
cur = cur->next;
- context_destroy(&temp->context);
+ kfree(temp->context);
kfree(temp); s->nel--;
} else {
@@ -179,7 +153,7 @@ void sidtab_map_remove_on_error(struct s
}

static inline u32 sidtab_search_context(struct sidtab *s,
- struct context *context)
+ const struct context *context)
{
int i;
struct sidtab_node *cur;
@@ -187,7 +161,7 @@ static inline u32 sidtab_search_context(
for (i = 0; i < SIDTAB_SIZE; i++) {
cur = s->htable[i];
while (cur != NULL) {
- if (context_cmp(&cur->context, context))
+ if (context_cmp(cur->context, context))
return cur->sid;
cur = cur->next;
}
@@ -196,14 +170,14 @@ static inline u32 sidtab_search_context(
}

int sidtab_context_to_sid(struct sidtab *s,
- struct context *context,
+ const struct context *context,
u32 *out_sid)
{
u32 sid;
int ret = 0;
unsigned long flags;

- *out_sid = SECSID_NULL;
+ *out_sid = FIREFLIER_SID_UNLABELED;

sid = sidtab_search_context(s, context); if (!sid) {
@@ -221,7 +195,7 @@ int sidtab_context_to_sid(struct sidtab
ret = sidtab_insert(s, sid, context); if (ret)
s->next_sid--;
SIDTAB_UNLOCK(s, flags);
}

@@ -272,7 +246,7 @@ void sidtab_destroy(struct sidtab *s)
while (cur != NULL) {
temp = cur;
cur = cur->next;
- context_destroy(&temp->context);
+ kfree(temp->context);
kfree(temp);
}
s->htable[i] = NULL;
@@ -283,18 +257,6 @@ void sidtab_destroy(struct sidtab *s)
s->next_sid = 1;
}

--- /home/edwin/kernel/linux-2.6.16/security/selinux/ss/sidtab.h 2006-02-10
09:22:48.000000000 +0200
+++ fireflier_lsm/sidtab.h 2006-03-29 23:23:57.000000000 +0300
@@ -1,20 +1,24 @@
/*
* A security identifier table (sidtab) is a hash table
- * of security context structures indexed by SID value.
+ * of (executable) file structures indexed by SID value. *
- * Author : Stephen Smalley, <[email protected]>
+ * Heavily based on selinux/ss/sidtab.h
+ * Original author : Stephen Smalley, <[email protected]>
+ *
+ * Modified for fireflier by: Török Edwin <[email protected]> */
-#ifndef _SS_SIDTAB_H_
-#define _SS_SIDTAB_H_
+#ifndef _FF_SIDTAB_H_
+#define _FF_SIDTAB_H_

#include "context.h"
-
-struct sidtab_node {
- u32 sid; /* security identifier */
- struct context context; /* security context structure */
+struct sidtab_node
+{
+ u32 sid;
+ struct context* context;
struct sidtab_node *next;
};

+
#define SIDTAB_HASH_BITS 7
#define SIDTAB_HASH_BUCKETS (1 << SIDTAB_HASH_BITS) #define SIDTAB_HASH_MASK (SIDTAB_HASH_BUCKETS-1)
@@ -30,28 +34,22 @@ struct sidtab {
};

int sidtab_init(struct sidtab *s);
-int sidtab_insert(struct sidtab *s, u32 sid, struct context *context); -struct context *sidtab_search(struct sidtab *s, u32 sid);
+int sidtab_insert(struct sidtab *s, u32 sid,const struct context* context); +const struct context* sidtab_search(struct sidtab *s, u32 sid);

-int sidtab_map(struct sidtab *s,

-	       int (*apply) (u32 sid,
-			     struct context *context,
-			     void *args),
-	       void *args);

void sidtab_map_remove_on_error(struct sidtab *s,
int (*apply) (u32 sid,
- struct context *context,
+ const struct context *context,
void *args),
void *args);

int sidtab_context_to_sid(struct sidtab *s,
- struct context *context,
+ const struct context *context,
u32 *sid);

void sidtab_hash_eval(struct sidtab *h, char *tag); void sidtab_destroy(struct sidtab *s);
-void sidtab_set(struct sidtab *dst, struct sidtab *src);
void sidtab_shutdown(struct sidtab *s);

#endif /* _SS_SIDTAB_H_ */

#265 lore raw

RFC PATCH 4/7 exports

In reply to Török Edwin

These symbols are exported, to be used by an iptables module.

---
 exports.c   |   33 +++++++++++++++++++++++++++++++++
 fireflier.h |    9 +++++++++
 2 files changed, 42 insertions(+)
exports.c +33 -0
diff -uprN null/exports.c fireflier_lsm/exports.c
@@ -0,0 +1,33 @@
+#include "fireflier.h"
+#include "structures.h"
+#include "autolabel.h"
+#include <linux/socket.h>
+#include <net/sock.h>
+void fireflier_sk_ctxid(struct sock *sk,u32 *sid) 
+{
+	struct socket *sock;
+	sock = sk->sk_socket;
+	if (sock)
+	{
+		struct inode *inode;
+		inode = SOCK_INODE(sock);
+		if (inode)
+		{
+			struct fireflier_inode_security_struct *isec;
+			isec = inode->i_security;
+			if (sid && isec)
+				*sid = isec->sid;
+			//	     if (class)
+			//	       *class = isec->sclass;
+		}
+	}
+}
+
+int fireflier_available(void)
+{
+	return 1;
+}
+
+EXPORT_SYMBOL_GPL(fireflier_sk_ctxid);
+EXPORT_SYMBOL_GPL(fireflier_available);
+
fireflier.h +9 -0
diff -uprN null/fireflier.h fireflier_lsm/fireflier.h
@@ -0,0 +1,9 @@
+#ifndef _FIREFLIER_H
+#define _FIREFLIER_H
+#include <linux/types.h>
+#include <linux/module.h>
+struct sock;
+void fireflier_sk_ctxid(struct sock *sk,u32 *ctxid);
+int fireflier_available(void);
+int fireflier_ctx_to_id(const char* dev,unsigned long inode,u32 *ctxid);
+#endif
#266 lore raw

RFC PATCH 5/7 debugging/testing support

In reply to Török Edwin

This dumps sid/pid maps to debugfs.
It is to be used for debugging/testing only.

---
 fireflier_debug.c |  134 
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fireflier_debug.h |   18 +++++++
 2 files changed, 152 insertions(+)
fireflier_debug.c +32 -0
diff -uprN null/fireflier_debug.c fireflier_lsm/fireflier_debug.c
@@ -0,0 +1,134 @@
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+
+#include "fireflier_debug.h"
+static struct dentry* fireflier_debugfs=0;
+static struct dentry* sidmap_debugfs=0;
+static struct dentry* pidmap_debugfs=0;
+
+extern int ff_debug;
+
+static int debug_show(struct seq_file *s, void *_)
+{
+	seq_printf(s,"%s\n",(char*)s->private);
+	return 0;
+}
+
+static int debug_string_open(struct inode* inode, struct file* file)
+{
+	return single_open(file,debug_show,inode->u.generic_ip);
+}
+
+
+static struct file_operations fops_string = {
+	.open           = debug_string_open,
+	.read           = seq_read,
+	.llseek         = seq_lseek,
+	.release        = single_release,
+};
+
+
+
+static inline struct dentry* debugfs_create_readonly_string(const char* 

name,mode_t mode,struct dentry* parent,char* value)
+{
+ return debugfs_create_file(name,mode,parent,value,&fops_string);
+}
+
+void ff_debug_map_pidsid(u32 sid)
+{
+ u32* sid_d = kmalloc(sizeof(u32),GFP_ATOMIC);
+ char pid_s[16];
+
+ if(unlikely(!ff_debug))
+ return;
+
+ if(unlikely(!sid_d)) {
+ printk(KERN_DEBUG "fireflier::ff_debug_map_pidsid: OOM\n");
+ return;
+ }
+ *sid_d = sid;
+ snprintf(pid_s,16,"%d",current->pid);
+
+ debugfs_create_u32(pid_s,0,pidmap_debugfs,sid_d);
+}
+
+void ff_debug_dump_sid(const struct context* context,u32 sid)
+{
+ struct
+ {
+
+ u32 inode;
+ u8 unsafe;
+ char mntpoint[];
+
+ }
+ * sid_debug = kmalloc( sizeof(*sid_debug)+strlen(context->mnt_devname)+1,
GFP_ATOMIC);
+ // u32* inode_d = kmalloc(sizeof(u32),GFP_ATOMIC);
+ char sid_s[16];
+ struct dentry* sid_dentry=NULL;
+ // char* mntpoint_d = kmalloc(strlen(mntpoint)+1,GFP_ATOMIC);
+ // strncpy(mntpoint_d,mntpoint,strlen(mntpoint)+1);
+
+ if(unlikely(!ff_debug))
+ return;
+
+ strncpy(sid_debug->mntpoint,context->mnt_devname,strlen(context->mnt_devname)+1);
+ sid_debug->inode=context->inode;
+ sid_debug->unsafe=context->unsafe;
+
+ /* if(unlikely(!inode_d)) {
+ printk(KERN_DEBUG "fireflier::ff_debug_dump_sid: OOM\n");
+ return;
+ }
+ *inode_d=inode;*/
+ snprintf(sid_s,16,"%d",sid);
+
+ sid_dentry = debugfs_create_dir(sid_s,sidmap_debugfs);
+ if(!sid_dentry) {
+ //already created
+ return;
+ }
+
+
+ debugfs_create_u32("inode",0,sid_dentry,&sid_debug->inode);
+ debugfs_create_u8("unsafe",0,sid_dentry,&sid_debug->unsafe);
+ debugfs_create_readonly_string("mountpoint",0,sid_dentry,sid_debug->mntpoint);
+ if(context->groupmembers>0)
+ {
+ int i;
+ for(i=0;i<context->groupmembers;i++)
+ {
+ snprintf(sid_s,16,"%d",context->sids[i]);
+ debugfs_create_u8(sid_s,0,sid_dentry,&sid_debug->unsafe);
+ }
+ }
+}
+
+
+
+void ff_debug_startup(void)
+{
+ if(!ff_debug)
+ return;
+ ff_debug=0;
+ fireflier_debugfs = debugfs_create_dir("fireflier",NULL);
+ if(!fireflier_debugfs) {
+ printk(KERN_DEBUG "fireflier: failed to create debug root fs!\n");
+ return;
+ }
+
+ sidmap_debugfs = debugfs_create_dir("sidmap",fireflier_debugfs);
+ if(!sidmap_debugfs) {
+ printk(KERN_DEBUG "fireflier: failed to create debug sidmap fs!\n");
+ return;
+ }
+
+ pidmap_debugfs = debugfs_create_dir("pidmap",fireflier_debugfs);
+ if(!pidmap_debugfs) {
+ printk(KERN_DEBUG "fireflier: failed to create debug sidmap fs!\n");
+ return;
+ }
+
+ ff_debug=1;
+ printk(KERN_DEBUG "fireflier: debugging enabled\n");
+}

fireflier_debug.h +9 -0
diff -uprN null/fireflier_debug.h fireflier_lsm/fireflier_debug.h
@@ -0,0 +1,18 @@
+#ifndef _FIREFLIER_DEBUG_H
+#define _FIREFLIER_DEBUG_H
+
+#define FIREFLIER_DEBUG 1
+#include "context.h"
+//extern struct dentry* fireflier_debugfs;
+
+#ifndef FIREFLIER_DEBUG
+static inline void ff_debug_dump_sid(const struct context* context,u32 sid) 

{}
+static inline void ff_debug_startup(void) {}
+static inline void ff_debug_map_pidsid(u32 sid) {} +#else
+void ff_debug_dump_sid(const struct context* context,u32 sid); +void ff_debug_startup(void);
+void ff_debug_map_pidsid(u32 sid);
+#endif
+
+#endif

#267 lore raw

RFC PATCH 6/7 userspace

In reply to Török Edwin

The makefile for the lsm module, and a test app I used to verify that getxattr() works properly with my lsm.

---
 Makefile         |   10 ++++++++++
 xattr_helper.cpp |   54 
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
Makefile +10 -0
diff -uprN null/Makefile fireflier_lsm/Makefile
@@ -0,0 +1,10 @@
+obj-m += fireflier.o
+fireflier-objs := hooks.o autolabel.o sidtab.o fireflier_debug.o
+KERN = $(shell uname -r)
+#KERN = 2.6.16.1
+all: 
+	make -C /lib/modules/$(KERN)/build M=$(PWD) modules
+
+clean:
+	make -C /lib/modules/$(KERN)/build M=$(PWD) clean
+      
xattr_helper.cpp +54 -0

54 lines not on this page · raw message

#268 lore raw

RFC PATCH 7/7 stacking support for capability module

In reply to Török Edwin

Adds stacking support to capability module. Without this patch, I have to boot with capability.disable=1 to get fireflier registered as security module.

What is current status of stacking support, how should LSM's handle stacking with the capability module?

---
 capability.c |  114 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 commoncap.c  |   10 ++++-
 2 files changed, 123 insertions(+), 1 deletion(-)

diff -uprN -X vanilla/linux-2.6.16/Documentation/dontdiff vanilla/linux-2.6.16/security/capability.c linux-2.6.16/security/capability.c
--- vanilla/linux-2.6.16/security/capability.c 2006-03-20 18:29:57.000000000
+0200
+++ linux-2.6.16/security/capability.c 2006-04-07 16:32:43.000000000 +0300
@@ -24,6 +24,104 @@
#include <linux/ptrace.h>
#include <linux/moduleparam.h>

+/* stacking support */
+struct security_operations *cap_original_ops = NULL;
+extern struct security_operations *cap_secondary_ops;
+
+int cap_stack_bprm_alloc_security(struct linux_binprm *bprm)
+{
+ return cap_secondary_ops->bprm_alloc_security(bprm);
+}
+
+void cap_stack_bprm_free_security(struct linux_binprm *bprm)
+{
+ return cap_secondary_ops->bprm_free_security(bprm);
+}
+
+void cap_stack_bprm_post_apply_creds(struct linux_binprm *bprm) +{
+ return cap_secondary_ops->bprm_post_apply_creds(bprm);
+}
+void cap_stack_inode_free_security(struct inode *inode)
+{
+ return cap_secondary_ops->inode_free_security(inode);
+}
+
+int cap_stack_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size, int err)
+{
+ return cap_secondary_ops->inode_getsecurity(inode,name,buffer,size,err); +}
+
+int cap_stack_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
+{
+ return cap_secondary_ops->inode_listsecurity(inode,buffer,buffer_size); +}
+
+
+int cap_stack_file_receive(struct file* file)
+{
+ return cap_secondary_ops->file_receive(file);
+}
+
+int cap_stack_task_alloc_security(struct task_struct *task)
+{
+ if(cap_secondary_ops)
+ return cap_secondary_ops->task_alloc_security(task);
+ else return 0;
+}
+
+void cap_stack_task_free_security(struct task_struct *task)
+{
+ return cap_secondary_ops->task_free_security(task);
+}
+
+void cap_stack_socket_post_create(struct socket *sock, int family,
+ int type, int protocol, int kern)
+{
+ return cap_secondary_ops->socket_post_create(sock,family,type,protocol,kern); +}
+
+int cap_stack_socket_accept(struct socket *sock, struct socket *newsock) +{
+ return cap_secondary_ops->socket_accept(sock,newsock);
+}
+
+
+
+int cap_stack_register_security (const char *name, struct security_operations *ops)
+{
+ if (cap_secondary_ops != cap_original_ops)
+ {
+ printk(KERN_INFO "%s: There is already a secondary security "
+ "module registered.\n", __FUNCTION__);
+ return -EINVAL;
+ }
+
+ cap_secondary_ops = ops;
+
+ printk(KERN_INFO "%s: Registering secondary module %s\n",
+ __FUNCTION__,
+ name);
+
+ return 0;
+}
+
+static int cap_stack_unregister_security (const char *name, struct security_operations *ops)
+{
+ if (ops != cap_secondary_ops)
+ {
+ printk (KERN_INFO "%s: trying to unregister a security
module "
+ "that is not registered.\n", __FUNCTION__);
+ return -EINVAL;
+ }
+
+ cap_secondary_ops = cap_original_ops;
+
+ return 0;
+}
+
+
+
static struct security_operations capability_ops = {
.ptrace = cap_ptrace,
.capget = cap_capget,
@@ -47,6 +145,20 @@ static struct security_operations capabi
.syslog = cap_syslog,

.vm_enough_memory = cap_vm_enough_memory,
+ /* for stacking */
+ .bprm_alloc_security = cap_stack_bprm_alloc_security,
+ .bprm_free_security = cap_stack_bprm_free_security,
+ .bprm_post_apply_creds = cap_stack_bprm_post_apply_creds,
+ .inode_free_security = cap_stack_inode_free_security,
+ .inode_getsecurity = cap_stack_inode_getsecurity,
+ .inode_listsecurity = cap_stack_inode_listsecurity,
+ .file_receive = cap_stack_file_receive,
+ .task_alloc_security = cap_stack_task_alloc_security,
+ .task_free_security = cap_stack_task_free_security,
+ .socket_post_create = cap_stack_socket_post_create,
+ .socket_accept = cap_stack_socket_accept,
+ .register_security = cap_stack_register_security,
+ .unregister_security = cap_stack_unregister_security,
};

/* flag to keep track of how we were registered */
@@ -58,6 +170,7 @@ MODULE_PARM_DESC(disable, "To disable ca

static int __init capability_init (void)
{
+ cap_original_ops = cap_secondary_ops = security_ops;
if (capability_disable) {
printk(KERN_INFO "Capabilities disabled at initialization\n"); return 0;
@@ -100,3 +213,4 @@ module_exit (capability_exit);

MODULE_DESCRIPTION("Standard Linux Capabilities Security Module"); MODULE_LICENSE("GPL");
+
diff -uprN -X vanilla/linux-2.6.16/Documentation/dontdiff vanilla/linux-2.6.16/security/commoncap.c linux-2.6.16/security/commoncap.c
--- vanilla/linux-2.6.16/security/commoncap.c 2006-03-20 18:29:57.000000000
+0200
+++ linux-2.6.16/security/commoncap.c 2006-04-07 15:48:21.000000000 +0300
@@ -25,6 +25,9 @@
#include <linux/xattr.h>
#include <linux/hugetlb.h>

+
+struct security_operations *cap_secondary_ops = NULL; +
int cap_netlink_send(struct sock *sk, struct sk_buff *skb) {
NETLINK_CB(skb).eff_cap = current->cap_effective;
@@ -135,7 +138,9 @@ int cap_bprm_set_security (struct linux_
if (bprm->e_uid == 0)
cap_set_full (bprm->cap_effective);
}
- return 0;
+ if(cap_secondary_ops)
+ return cap_secondary_ops->bprm_set_security(bprm);
+ else return 0;
}

void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
@@ -179,6 +184,8 @@ void cap_bprm_apply_creds (struct linux_
/* AUD: Audit candidate if current->cap_effective is set */

current->keep_capabilities = 0;
+ if(cap_secondary_ops)
+ cap_secondary_ops->bprm_apply_creds(bprm,unsafe);
}

int cap_bprm_secureexec (struct linux_binprm *bprm)
@@ -341,6 +349,7 @@ EXPORT_SYMBOL(cap_task_post_setuid);
EXPORT_SYMBOL(cap_task_reparent_to_init); EXPORT_SYMBOL(cap_syslog); EXPORT_SYMBOL(cap_vm_enough_memory);
+EXPORT_SYMBOL(cap_secondary_ops);

MODULE_DESCRIPTION("Standard Linux Common Capabilities Security Module"); MODULE_LICENSE("GPL");

#269 lore raw

Re: [RFC][PATCH 7/7] stacking support for capability module

Quoted 5 lines · T??r??k Edwin

Adds stacking support to capability module. Without this patch, I have to boot with capability.disable=1 to get fireflier registered as security module.

What is current status of stacking support, how should LSM's handle stacking with the capability module?

For now, pretty much like this.

The lsm stacker is still being kept up to date at
www.sf.net/projects/lsm-stacker.

-serge

#270 lore raw

Re: [RFC][PATCH 0/7] fireflier LSM for labeling sockets based on its creator (owner)

In reply to Török Edwin
Quoted 6 lines · * Török Edwin ([email protected]) wrote:

The purpose of the fireflier LSM is to "label" each socket with a context, where the context is a (list of) the program(s) that has/have access to it.

I've written fireflier LSM to allow filtering packets "per application". It is meant to be used only when SELinux is not available (not available/disabled at boot). For more details, see the initial discussion [1]

There is so much SELinux code in here, it's really not making sense to do this as separate work.

Quoted 3 lines

Summary of how fireflier LSM works:
- each program is associated a sid, depending on its mountpoint+inode, i.e. 2 processes launched from the same program have the same sid

That sounds like a problem. Ptrace can undermine that really easily. Also bind mounts will give you a different sid for same exectuable, with a possible way to get into interesting 'group' situation.

Quoted 4 lines

- each socket created by a processis labeled with the process's sid
- if 2 or more programs have access to the socket, it is labeled with a "group sid". A group sid contains a list of the sids of programs having access
- userspace, or iptables module can match packets on this "fireflier context"

How do you keep from joining the group?

Quoted 7 lines

As I stated in my previous mail, I intend to write a userspace policy module generator, that is to be used when selinux is enabled.
When it is disabled, then only would the fireflier lsm be used.

I am asking for your comments/suggestions on the following issues:
- security/correctness of the LSM (is there a way for a program to have access to a socket, and escaping the labeling?)

what do you do about ptrace, /proc/[pid]/mem, fd passing, bind mounts, /proc/self/mem, etc.

Quoted 1 line

- how do I generate an SELinux policy, that does what this LSM module does?

Sounds like the best solution.

thanks,
-chris

#271 lore raw

Re: [RFC][PATCH 0/7] fireflier LSM for labeling sockets based on its creator (owner)

Quoted 6 lines · Chris Wright
Quoted 4 lines

Summary of how fireflier LSM works:
- each program is associated a sid, depending on its mountpoint+inode, i.e. 2 processes launched from the same program have the same sid

That sounds like a problem. Ptrace can undermine that really easily.

I forgot to mention, if a process gets ptraced, it is getting a different sid.

Quoted 2 lines

Also bind mounts will give you a different sid for same exectuable, with a possible way to get into interesting 'group' situation.

I should use something else instead of the mountpoint to make sure inodes are unique. Maybe I should use the device, instead of the mountpoint.

Quoted 7 lines
Quoted 5 lines

- each socket created by a processis labeled with the process's sid
- if 2 or more programs have access to the socket, it is labeled with a "group sid". A group sid contains a list of the sids of programs having access
- userspace, or iptables module can match packets on this "fireflier context"

How do you keep from joining the group?

New processes aren't added to a group, instead a new group is created.
So if A, and B are in group 1; and C would have to be added, then a new group (2) is created, that contains all what the previous contained (A,B), and the newly added sid (C)
When you create rules for group A, and B; any socket labeled with that group sid will be accessed only by A and B.

Quoted 1 line

what do you do about ptrace,

As stated above, ptracing means a new sid (I used the unsafe flag passed to certain function by the kernel, maybe I should also implement the ptrace hook)
/proc/[pid]/mem,
Restricting access to /proc/[pid]/mem can be done properly by SELinux.
Is it worth to implement access restriction to /proc/self/mem in fireflier lsm?
If so, should I restrict access to it for all programs except the process itself?

Quoted 1 line

fd passing,

I implemented the file_receive hook. Is there any other way to pass a fd? (besides fork+execve which is covered)

Quoted 1 line

bind mounts,

using the device instead of mountpoint? But are devices named consistently between boots? what if somebody adds/removes a harddisk/usb stick? will that change the device naming?

Quoted 1 line

/proc/self/mem,

Why is this a security risk? Can a child process access the parent's data through /proc/self/mem?

Quoted 1 line

etc.

You made me curious, what other ways are there to gain access to the "data" and open files held by another process? (Of course if somebody wants "full" security, he should use SELinux.)

Quoted 4 lines
Quoted 2 lines

- how do I generate an SELinux policy, that does what this LSM module does?

Sounds like the best solution.

Yes, but writing such a policy will take time, that is why it is planned for version 2.1, or 2.2. I will try to write a policy module generator userspace program, but I don't know how to create "group labels". How do I label a socket, in such a way, that I'll be able to determine all the programs having access to it? Can an inode have multiple labels (contexts)?

Having a fireflier lsm in 2.0 (although with reduced security compared to SELinux) is better than having no lsm at all. FYI fireflier 1.x, and 1.99beta accepted a packet if the first (!) program found to have access to a socket was
in its list of rules. (finding this was done searching /proc for an open socket having the proper inode, determined from /proc/net/tcp|udp|tcp6|udp6)

Thanks in advance,
Edwin

#273 lore raw
Quoted 3 lines · Mikado

Does your module get into below problem?

http://lkml.org/lkml/2006/4/20/132

Nope.

A short test:
On host:
sudo iptables -A INPUT -p tcp --dport 81 -j DROP
In qemu:
#iptables -t skfilter -A OUTPUT -m fireflier_match --inode-owner 24392 --dev-owner /dev/root -j LOG --log-prefix test_out2 #netcat 172.20.0.1 81

[4295327.547000] test_out2:IN= OUT=eth0 SRC=172.20.0.10 DST=172.20.0.1 LEN=60 
TOS=0x00 PREC=0x00 TTL=64 ID=11865 DF PROTO=TCP SPT=34945 DPT=81 WINDOW=5840 
RES=0x00 SYN URGP=0
[4295327.549000] test_out2:IN= OUT=eth0 SRC=172.20.0.10 DST=172.20.0.1 LEN=60 
TOS=0x00 PREC=0x00 TTL=64 ID=11865 DF PROTO=TCP SPT=34945 DPT=81 WINDOW=5840 
RES=0x00 SYN URGP=0
[4295330.550000] test_out2:IN= OUT=eth0 SRC=172.20.0.10 DST=172.20.0.1 LEN=60 

TOS=0x00 PREC=0x00 TTL=64 ID=11866 DF PROTO=TCP SPT=34945 DPT=81 WINDOW=5840 RES=0x00 SYN URGP=0

As you can see several packets are sent out, and each one is matched (24392 is the inode of netcat here).

Please note that using fireflier LSM is not recomended, as I am working on writing SELinux policies that do the same (fireflier LSM is itself using code from hooks.c from selinux).
See: http://lkml.org/lkml/2006/4/17/81

Also take a look at James Morris's skfilter patches (which are used in fireflier too), they allow you to match at socket level, and also allow to match based on selinux context.

Cheers,
Edwin