Skip to contentSkip to conversation

Been looking at further shrinkage of the SELinux footprint on Linux.

PATCH Daniel J Walsh 8 participants 21 messages Oct 30, 2013 – Nov 6, 2013 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

xz compression does around a 90% compression on the policy file, and does not slow the load in any meaningfull way.

I also have done a patch to try out gzip.

gzip and xz are already used in systemd, which means we would not need to add a new requirement to the minimal system.

xz seems quicker and smaller then gzip.

Have not started playing with libsemanage yet.

What do you think? Is xz availabel on Android? -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJxXnUACgkQrlYvE4MpobNR9QCgx4AMRM+0TR0mqwvPikvj6mGH O1UAn0OIwFNTmQ2zIBwtB65IwfqfsEq2
=dBjb
-----END PGP SIGNATURE-----

libselinux/src/Makefile +1 -1
index 02dd829..6dfdb46 100644
@@ -114,7 +114,7 @@ $(LIBA): $(OBJS)
 	$(RANLIB) $@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+	$(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -llzma -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET) 
 
 $(LIBPC): $(LIBPC).in ../VERSION
libselinux/src/load_policy.c +104 -20

168 lines not on this page · raw message

Information gathered from Fedora 21/Rawhide.

Current Load_policy

real 0m0.848s
user 0m0.047s
sys 0m0.283s

real 0m0.846s
user 0m0.094s
sys 0m0.625s

real 0m0.850s
user 0m0.114s
sys 0m0.717s

xz Load_policy
real 0m0.885s
user 0m0.084s
sys 0m0.382s

real 0m0.878s
user 0m0.090s
sys 0m0.453s

real 0m0.886s
user 0m0.128s
sys 0m0.572s

du -s *
2584 policy.29
384 policy.29.xz

valgrind shows
mmap load_policy
total heap usage: 443,521 allocs, 443,519 frees, 34,795,153 bytes allocated Versus
xz load_policy
total heap usage: 443,509 allocs, 443,507 frees, 18,115,873 bytes allocated

#1 lore raw
Quoted 14 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

xz compression does around a 90% compression on the policy file, and does not slow the load in any meaningfull way.

I also have done a patch to try out gzip.

Quoted 8 lines

gzip and xz are already used in systemd, which means we would not need to add a new requirement to the minimal system.

xz seems quicker and smaller then gzip.

Have not started playing with libsemanage yet.

What do you think? Is xz availabel on Android?

No.

Is there a reason you wouldn't just have systemd decompress it before loading it? I guess if you want all the existing tools/libraries to work without any changes it would need to be build in to libselinux rather done outside of the library.

Android's libselinux is forked anyway so this probably wouldn't flow to Android.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
In reply to Daniel J Walsh
Quoted 11 lines · Daniel J Walsh

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

xz compression does around a 90% compression on the policy file, and does not slow the load in any meaningfull way.

I also have done a patch to try out gzip.

Quoted 8 lines

gzip and xz are already used in systemd, which means we would not need to add a new requirement to the minimal system.

xz seems quicker and smaller then gzip.

Have not started playing with libsemanage yet.

What do you think? Is xz availabel on Android?

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

On the former, I wrote a little tool for Android called sepolicy-analyze that identifies all equivalent types in the policy. It works nicely on the Android policy but unfortunately I gave up waiting on it running on Fedora policy because it is so large. We're also looking at extending that tool to identify isomorphic types, not just equivalent ones. I know apol has a similar feature under the Analysis tab (Types relationship summary) but it only does it on a pairwise basis; there doesn't seem to be any way to apply it systematically.

Anyway, with regard to impact on Android of your patch, it won't affect it as libselinux is forked (and significantly modified) there as Joshua noted and we don't bring over any of libsemanage or policycoreutils either (we reimplemented the pieces of policycoreutils that we wanted in the Android init and toolbox programs, just as people previously did in busybox). And we only build/use libsepol and checkpolicy on the build host, not the device. So I think the only real concern is whether this is an acceptable dependency on conventional Linux distros.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 53 lines · Stephen Smalley
Quoted 11 lines · Daniel J Walsh

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

xz compression does around a 90% compression on the policy file, and does not slow the load in any meaningfull way.

I also have done a patch to try out gzip.

Quoted 8 lines

gzip and xz are already used in systemd, which means we would not need to add a new requirement to the minimal system.

xz seems quicker and smaller then gzip.

Have not started playing with libsemanage yet.

What do you think? Is xz availabel on Android?

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

On the former, I wrote a little tool for Android called sepolicy-analyze that identifies all equivalent types in the policy. It works nicely on the Android policy but unfortunately I gave up waiting on it running on Fedora policy because it is so large. We're also looking at extending that tool to identify isomorphic types, not just equivalent ones. I know apol has a similar feature under the Analysis tab (Types relationship summary) but it only does it on a pairwise basis; there doesn't seem to be any way to apply it systematically.

Anyway, with regard to impact on Android of your patch, it won't affect it as libselinux is forked (and significantly modified) there as Joshua noted and we don't bring over any of libsemanage or policycoreutils either (we reimplemented the pieces of policycoreutils that we wanted in the Android init and toolbox programs, just as people previously did in busybox). And we only build/use libsepol and checkpolicy on the build host, not the device. So I think the only real concern is whether this is an acceptable dependency on conventional Linux distros.

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

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.
2. Cordination between domains, we put a fix into an interface and we need to trigger 10 packages to update.

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

3. Uninstall of types leaves unlabeled_t content on disk.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJxbeYACgkQrlYvE4MpobOrgwCgqurQA/VYLedbOs4nKzysnsIy Q8AAoOd7jQXImOyRbhDDoMHWhzZ1d/h4
=V0Rp
-----END PGP SIGNATURE-----

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 8 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Quoted 8 lines

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

Quoted 5 lines

2. Cordination between domains, we put a fix into an interface and we need to trigger 10 packages to update.

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

That's also fixed if we go with source modules, right, since interface change would get applied by the m4 + checkpolicy cycle. Or CIL.

Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 18 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Quoted 8 lines

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.

Quoted 6 lines

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

However, on this note, I'm pretty sure that the rpm work allows you to just collect up all of the policy modules and run semodule once at the end (collections or whatever). So that particular problem should be solved already even for the binary modules.

Quoted 10 lines
Quoted 6 lines

2. Cordination between domains, we put a fix into an interface and we need to trigger 10 packages to update.

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

That's also fixed if we go with source modules, right, since interface change would get applied by the m4 + checkpolicy cycle. Or CIL.

Quoted 10 lines
Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

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

#17 lore raw
In reply to Daniel J Walsh
Quoted 8 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

Given that security_load_policy() just copies the data from userspace, rather than taking advantage of mmap in any way, it makes total sense to me to ship it compressed.

xz is usually a better choice for new compression deployments since very often you want its asymmetric tradeoff of good but expensive compression and fast decompression, unlike the more symmetric gzip.

Since policy is only loaded occasionally, xz also makes sense to me.

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

#19 lore raw
In reply to Daniel J Walsh
Quoted 2 lines · Daniel J Walsh

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

Hm, it's kind of ugly to attempt to open the policy with LZMA and only if that returns (any kind of error) fails fall back to the old code. Wouldn't it be better to say check whether or not it starts with a new magic number, like the kernel policydb_read() function does?

In other words have:

[New 32 bit magic number] [Compressed policy]

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

#18 lore raw
In reply to Colin Walters
Quoted 7 lines · Colin Walters
Quoted 6 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

Quoted 6 lines
Quoted 2 lines

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

Given that security_load_policy() just copies the data from userspace, rather than taking advantage of mmap in any way, it makes total sense to me to ship it compressed.

Maybe I misunderstood you, but the callers of security_load_policy() (e.g. selinux_mkload_policy, selinux_init_load_policy) work by mmap'ing the policy file and then passing that region to security_load_policy().
They only currently have to copy it if they need to modify the policy
at load time (e.g. if the userspace policy version is newer than that supported by the kernel and it needs to downgrade to the kernel version).

Quoted 7 lines

xz is usually a better choice for new compression deployments since very often you want its asymmetric tradeoff of good but expensive compression and fast decompression, unlike the more symmetric gzip.

Since policy is only loaded occasionally, xz also makes sense to me.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
In reply to Stephen Smalley
Quoted 26 lines · Stephen Smalley
Quoted 18 lines · Stephen Smalley
Quoted 8 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Quoted 8 lines

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.

Quoted 6 lines

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

Quoted 5 lines

However, on this note, I'm pretty sure that the rpm work allows you to just collect up all of the policy modules and run semodule once at the end (collections or whatever). So that particular problem should be solved already even for the binary modules.

This is correct. the collection feature of RPM gathers up all selinux policies from all the rpms in the yum/rpm transaction and installs them all in a single semanage transaction. Note that although the work was upstreamed, last I checked, the building of the selinux plugin that performs the work to aggregate and install the policy modules is currently disabled on fedora.

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

2. Cordination between domains, we put a fix into an interface and we need to trigger 10 packages to update.

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

That's also fixed if we go with source modules, right, since interface change would get applied by the m4 + checkpolicy cycle. Or CIL.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

The way this is handled in the RPM collection feature is modules are never uninstalled, even if the package that installed that module is. Not ideal, but it solves this problem.

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

#7 lore raw
Quoted 40 lines · Steve Lawrence
Quoted 33 lines · Stephen Smalley
Quoted 24 lines · Stephen Smalley
Quoted 17 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and
spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other
domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat)
are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them
updating quicker then RHEL.

Quoted 5 lines

1. semanage is slowwwwwwwww. If we ran all pp files without combining them
into a single transaction the installation and yum updates would take a long
time.

Quoted 7 lines

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

Quoted 5 lines

However, on this note, I'm pretty sure that the rpm work allows you to just collect up all of the policy modules and run semodule once at the end (collections or whatever). So that particular problem should be solved already even for the binary modules.

Quoted 6 lines

This is correct. the collection feature of RPM gathers up all selinux policies from all the rpms in the yum/rpm transaction and installs them all in a single semanage transaction. Note that although the work was upstreamed, last I checked, the building of the selinux plugin that performs the work to aggregate and install the policy modules is currently disabled on fedora.

That seems surprising given that it was developed for Fedora originally.
Can someone ping Panu or whoever is maintaining rpm these days and ask
why it is disabled or whether it can be enabled?

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

Quoted 3 lines

The way this is handled in the RPM collection feature is modules are never uninstalled, even if the package that installed that module is. Not ideal, but it solves this problem.

I guess the question is what behavior is desired here. If you remove the type itself, then these days it will get treated as unlabeled (so it becomes inaccessible to anything that doesn't have permissions to unlabeled, but that shouldn't be an issue for unconfined users) and if someone later re-installs the package/policy, then it should get remapped to its original context due to the deferred context mapping support. Is that sufficient? If not, then my proposed approach above of pushing all of the file type declarations into a single module (probably the base module) and never removing them would allow the types to always remain valid but they'd still be inaccessible except to domains that are allowed access to file_type (e.g. unconfined) when you remove the modules defining the allow rules. Is that sufficient? If not, then your approach of never removing modules will work but seems the least optimal to me.

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

#20 lore raw
In reply to Colin Walters

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 5 lines · Colin Walters
Quoted 2 lines · Daniel J Walsh

Here is a patch I have been fooling around with which would read a policy.29 file if it was compressed with xz.

Quoted 10 lines

Hm, it's kind of ugly to attempt to open the policy with LZMA and only if that returns (any kind of error) fails fall back to the old code. Wouldn't it be better to say check whether or not it starts with a new magic number, like the kernel policydb_read() function does?

In other words have:

[New 32 bit magic number] [Compressed policy]

Yes I was first considering doing this, but went with the easy hack to get the discussion going, and give me some numbers on speed of loading policy. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJyoSYACgkQrlYvE4MpobOK0wCgo0ybL6GQgf6e1JpoXRDwWdlh JWkAn2UXnk55QusMCSmvU7t7/VhSVxF+
=jzi8
-----END PGP SIGNATURE-----

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

#10 lore raw
In reply to Steve Lawrence

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 66 lines · Steve Lawrence
Quoted 28 lines · Stephen Smalley
Quoted 19 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Quoted 8 lines

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.

Quoted 7 lines

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

Quoted 5 lines

However, on this note, I'm pretty sure that the rpm work allows you to just collect up all of the policy modules and run semodule once at the end (collections or whatever). So that particular problem should be solved already even for the binary modules.

This is correct. the collection feature of RPM gathers up all selinux policies from all the rpms in the yum/rpm transaction and installs them all in a single semanage transaction. Note that although the work was upstreamed, last I checked, the building of the selinux plugin that performs the work to aggregate and install the policy modules is currently disabled on fedora.

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

2. Cordination between domains, we put a fix into an interface and we need to trigger 10 packages to update.

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

That's also fixed if we go with source modules, right, since interface change would get applied by the m4 + checkpolicy cycle. Or CIL.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

The way this is handled in the RPM collection feature is modules are never uninstalled, even if the package that installed that module is. Not ideal, but it solves this problem.

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.

Can you open a bugzilla on this, and show me point me at documentation on how to use this.

In current Fedora we are attempting to ship a binary policy precompiled so we do not take a long time/memory in initial install. But it would be nice to tell people to use the new feature to run their policy load in a transaction.

It would also be nice if we could do semanage commands within this transaction. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJypfQACgkQrlYvE4MpobOYvgCeKNApBdzF79GRlgxylcyacwGp siQAoKdnXhyIa/x1ezXb0bMKCA0ZoOjq
=oReg
-----END PGP SIGNATURE-----

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

#8 lore raw
In reply to Stephen Smalley

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 62 lines · Stephen Smalley
Quoted 37 lines · Steve Lawrence
Quoted 30 lines · Stephen Smalley
Quoted 21 lines · Stephen Smalley
Quoted 16 lines · Daniel J Walsh

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

Quoted 3 lines

1. semanage is slowwwwwwwww. If we ran all pp files without combining them into a single transaction the installation and yum updates would take a long time.

Quoted 7 lines

Yes, I have to wonder if we don't need a complete overhaul/replacement of libsemanage (+ module portions of libsepol). It seems like semodule/semanage transactions are far slower than running the entire policy through checkpolicy again (i.e. just using source modules and running them through m4 + checkpolicy on each transaction, ala the source policy module work that sadly has yet to reach maturity/completion).

Quoted 5 lines

However, on this note, I'm pretty sure that the rpm work allows you to just collect up all of the policy modules and run semodule once at the end (collections or whatever). So that particular problem should be solved already even for the binary modules.

Quoted 6 lines

This is correct. the collection feature of RPM gathers up all selinux policies from all the rpms in the yum/rpm transaction and installs them all in a single semanage transaction. Note that although the work was upstreamed, last I checked, the building of the selinux plugin that performs the work to aggregate and install the policy modules is currently disabled on fedora.

That seems surprising given that it was developed for Fedora originally. Can someone ping Panu or whoever is maintaining rpm these days and ask why it is disabled or whether it can be enabled?

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line

3. Uninstall of types leaves unlabeled_t content on disk.

That's the only one that seems fundamental. What if we pushed all file type declarations into their own module linked to the base filesystem package and just always installed that? That won't affect policy size substantially; it is the allow rules that are the issue IIUC, not just the type decls.

Quoted 3 lines

The way this is handled in the RPM collection feature is modules are never uninstalled, even if the package that installed that module is. Not ideal, but it solves this problem.

Quoted 14 lines

I guess the question is what behavior is desired here. If you remove the type itself, then these days it will get treated as unlabeled (so it becomes inaccessible to anything that doesn't have permissions to unlabeled, but that shouldn't be an issue for unconfined users) and if someone later re-installs the package/policy, then it should get remapped to its original context due to the deferred context mapping support. Is that sufficient? If not, then my proposed approach above of pushing all of the file type declarations into a single module (probably the base module) and never removing them would allow the types to always remain valid but they'd still be inaccessible except to domains that are allowed access to file_type (e.g. unconfined) when you remove the modules defining the allow rules. Is that sufficient? If not, then your approach of never removing modules will work but seems the least optimal to me.

Well I like the idea of defining alias for modules when they are not installed. The biggest problem I see is around executables and potentially readable content. If I install a package that labels something as foobar_exec_t and leaves the content on uninstall, a confined domain that was able to execute foobar_exec_t will now not be able to execute unlabeled_t.

If we could alias foobar_exec_t to bin_t when foobar.pp is not installed, then we get a little closer to the default, and I don;t have restorecon -R -v fixing unlabeled_t files.

similarly foobar_usr content to -> usr_t, and foobar_etc_t to etc_t foobar_var_t -> var_t ...

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJypu0ACgkQrlYvE4MpobPR7QCfbNb+dv1mBHrBXsXNK/v97t36 7lMAoODN4Uk/JtjsEVw3ksDNF2u+HpvT
=YwCv
-----END PGP SIGNATURE-----

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

#11 lore raw
In reply to Daniel J Walsh

On Wed, Oct 30, 2013 at 9:36 PM, Daniel J Walsh <[email protected]> wrote:
[...]

Quoted 3 lines
Quoted 3 lines · Daniel J Walsh
Quoted 2 lines

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

[...]

Quoted 5 lines
Quoted 5 lines

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

[...]

Quoted 5 lines

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

Quoted 7 lines

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded. This works pretty well. My workstation (which is where I do all my SELinux policy development on) has 100 policy modules loaded; my servers usually have around 50 to 60 modules loaded. That makes running things like "semodule -B" rather smooth. Not really fast, but one doesn't need to switch to another thing to do while waiting (4 seconds on a VM I'm currently playing with).

When updates occur only on a module's .te file, it could even be distributed towards the users easily (no need to do a full policy refresh), although I usually wait and make a full policy release.

It probably doesn't take long for Fedora/RedHat to find out which packages need which SELinux policy modules. A quick way to find them is to parse the RPM file list and check the file contexts of the SELinux policy tree for matches.

Quoted 2 lines

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

I'd go for the latter. Put the policies in their own RPMs.

Wkr,
Sven Vermeulen

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

#12 lore raw
Quoted 24 lines · Sven Vermeulen

On Wed, Oct 30, 2013 at 9:36 PM, Daniel J Walsh <[email protected]> wrote:
[...]

Quoted 3 lines
Quoted 3 lines · Daniel J Walsh
Quoted 2 lines

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

[...]

Quoted 5 lines
Quoted 5 lines

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

[...]

Quoted 5 lines

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

Quoted 7 lines

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

Quoted 8 lines

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded. This works pretty well. My workstation (which is where I do all my SELinux policy development on) has 100 policy modules loaded; my servers usually have around 50 to 60 modules loaded. That makes running things like "semodule -B" rather smooth. Not really fast, but one doesn't need to switch to another thing to do while waiting (4 seconds on a VM I'm currently playing with).

A lot of work is being done to improve the start-up time of consumer (e.g. phones) devices and "disposable" VMs. We're talking about people getting their knickers in a twist over security adding 20 milliseconds to the boot process. Your 4 second semodule run is not going to fly.

Quoted 13 lines

When updates occur only on a module's .te file, it could even be distributed towards the users easily (no need to do a full policy refresh), although I usually wait and make a full policy release.

It probably doesn't take long for Fedora/RedHat to find out which packages need which SELinux policy modules. A quick way to find them is to parse the RPM file list and check the file contexts of the SELinux policy tree for matches.

Quoted 2 lines

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

I'd go for the latter. Put the policies in their own RPMs.

Quoted 8 lines

Wkr,
Sven Vermeulen

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

#13 lore raw
Quoted 34 lines · Casey Schaufler
Quoted 24 lines · Sven Vermeulen

On Wed, Oct 30, 2013 at 9:36 PM, Daniel J Walsh<[email protected]> wrote:
[...]

Quoted 3 lines
Quoted 3 lines · Daniel J Walsh
Quoted 2 lines

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

[...]

Quoted 5 lines
Quoted 5 lines

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

[...]

Quoted 5 lines

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

Quoted 7 lines

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

Quoted 8 lines

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded. This works pretty well. My workstation (which is where I do all my SELinux policy development on) has 100 policy modules loaded; my servers usually have around 50 to 60 modules loaded. That makes running things like "semodule -B" rather smooth. Not really fast, but one doesn't need to switch to another thing to do while waiting (4 seconds on a VM I'm currently playing with).

Quoted 5 lines

A lot of work is being done to improve the start-up time of consumer (e.g. phones) devices and "disposable" VMs. We're talking about people getting their knickers in a twist over security adding 20 milliseconds to the boot process. Your 4 second semodule run is not going to fly.

semodule has nothing to do with the boot process. It is used to rebuild policies when something changes, e.g., a module is added or removed from the policy.

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

#14 lore raw
In reply to Sven Vermeulen

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 48 lines · Sven Vermeulen

On Wed, Oct 30, 2013 at 9:36 PM, Daniel J Walsh <[email protected]> wrote:
[...]

Quoted 4 lines
Quoted 4 lines · Daniel J Walsh
Quoted 3 lines

We are trying to shrink out cloud image as small as possible. One idea was to shrink SELinux Policy footprint by adding compression to it.

[...]

Quoted 6 lines
Quoted 6 lines

Personally, I'd much rather see work done on shrinking the actual policy size in Fedora rather than just compressing it. Both by reducing the overall size of refpolicy through coalescing similar domains/types and by making better use of the work that has already been done to support putting policy modules into rpms and only installing what actually get used.

[...]

Quoted 5 lines

Well we have done some work on combining like domains, see antivirus and spamassassin, but this is a lot of work which no one has time for.

I would love to see the mailserver and mailclients domains combined.

Quoted 7 lines

If people want to suggest or more importantly submit patches to combine other domains, I am all for it.

Problems with shipping policy within rpm still exists. although we (Red Hat) are at least moving toward layered products shipping their own policy. openstack-selinux, openshift-selinux, gluster-selinux. This is more for them updating quicker then RHEL.

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded. This works pretty well. My workstation (which is where I do all my SELinux policy development on) has 100 policy modules loaded; my servers usually have around 50 to 60 modules loaded. That makes running things like "semodule -B" rather smooth. Not really fast, but one doesn't need to switch to another thing to do while waiting (4 seconds on a VM I'm currently playing with).

When updates occur only on a module's .te file, it could even be distributed towards the users easily (no need to do a full policy refresh), although I usually wait and make a full policy release.

It probably doesn't take long for Fedora/RedHat to find out which packages need which SELinux policy modules. A quick way to find them is to parse the RPM file list and check the file contexts of the SELinux policy tree for matches.

Quoted 2 lines

For every apache bug in policy, do we want to wait for an update apache package, or do we ship lots more packages.

Quoted 9 lines

I'd go for the latter. Put the policies in their own RPMs.

Wkr, Sven Vermeulen

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

And how do you handle the problem of removing policy when packages get removed? What happens to the programs content?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJ3sloACgkQrlYvE4MpobN2vQCg5mjJMYrd+AlXec2uTlxIAPuq bwIAoIOq4f6eU59dwtjO2s+aXZEmbqC8
=zEME
-----END PGP SIGNATURE-----

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

#15 lore raw
Quoted 3 lines · Daniel J Walsh
Quoted 3 lines

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded.

[...]

Quoted 2 lines

And how do you handle the problem of removing policy when packages get removed? What happens to the programs content?

Good point. We don't handle that - if the package is removed and no other package exists that has a dependency on the SELinux policy, then the SELinux policy is also removed. Which invalidates the contexts of the files. I reckon that users who hit issues with that would relabel the files, which usually labels them to the "parent" type (such as var_t for things in /var/www then). But I have not received such case(s) for review yet.

Wkr,
Sven Vermeulen

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

#16 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 16 lines · Sven Vermeulen
Quoted 3 lines · Daniel J Walsh
Quoted 3 lines

In Gentoo, we try to only install the SELinux policies related to the package that is installed. So if a system does not have a web server, no httpd policies are loaded.

[...]

Quoted 2 lines

And how do you handle the problem of removing policy when packages get removed? What happens to the programs content?

Good point. We don't handle that - if the package is removed and no other package exists that has a dependency on the SELinux policy, then the SELinux policy is also removed. Which invalidates the contexts of the files. I reckon that users who hit issues with that would relabel the files, which usually labels them to the "parent" type (such as var_t for things in /var/www then). But I have not received such case(s) for review yet.

Quoted 2 lines

Wkr, Sven Vermeulen

These are the types of things that I have to worry about with a Huge installed base. Just removing the apache.pp would instantaneously would invalidate all content in /var/www, but also types in any other policy that was installed that uses apache_content_template.

# grep apache_content_template *.te
apache.te:apache_content_template(httpd_sys)
apache.te:apache_content_template(httpd_user)
apcupsd.te:	apache_content_template(apcupsd_cgi)
awstats.te:apache_content_template(awstats)
bugzilla.te:apache_content_template(bugzilla)
collectd.te:apache_content_template(collectd)
cvs.te:	apache_content_template(cvs)
dirsrv-admin.te:	apache_content_template(dirsrvadmin)
dspam.te:	apache_content_template(dspam)
git.te:apache_content_template(git)
lightsquid.te:	apache_content_template(lightsquid)
man2html.te:	apache_content_template(man2html)
mediawiki.te:	apache_content_template(mediawiki)
mojomojo.te:	apache_content_template(mojomojo)
munin.te:apache_content_template(munin)
mythtv.te:apache_content_template(mythtv)
nagios.te:	apache_content_template(nagios)
nut.te:	apache_content_template(nutups_cgi)
openshift.te:	apache_content_template(openshift)
prelude.te:	apache_content_template(prewikka)
smokeping.te:	apache_content_template(smokeping_cgi)
squid.te:	apache_content_template(squid)
w3c.te:apache_content_template(w3c_validator)
webalizer.te:	apache_content_template(webalizer)
zoneminder.te:	apache_content_template(zoneminder)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJ6YtoACgkQrlYvE4MpobPKGQCgkSWaIi99d8HtcxPV6M0DF/Wb qwoAmwYmiREd5koNXu1RYI7TJDDnvPsG
=ZeKi
-----END PGP SIGNATURE-----

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

#9 lore raw
In reply to Daniel J Walsh
Quoted 21 lines · Daniel J Walsh
Quoted 5 lines · Stephen Smalley

I guess the question is what behavior is desired here. If you remove the type itself, then these days it will get treated as unlabeled (so it becomes inaccessible to anything that doesn't have permissions to unlabeled, but that shouldn't be an issue for unconfined users) and if someone later re-installs the package/policy, then it should get remapped

Quoted 8 lines

to its original context due to the deferred context mapping support. Is that sufficient? If not, then my proposed approach above of pushing all of the file type declarations into a single module (probably the base module) and never removing them would allow the types to always remain valid but they'd still be inaccessible except to domains that are allowed access to file_type (e.g. unconfined) when you remove the modules defining the allow rules. Is that sufficient? If not, then your approach of never removing modules will work but seems the least optimal to me.

Well I like the idea of defining alias for modules when they are not installed. The biggest problem I see is around executables and potentially readable content. If I install a package that labels something as foobar_exec_t and leaves the content on uninstall, a confined domain that was able to execute foobar_exec_t will now not be able to execute unlabeled_t.

Quoted 6 lines

If we could alias foobar_exec_t to bin_t when foobar.pp is not installed, then we get a little closer to the default, and I don;t have restorecon -R -v fixing unlabeled_t files.

similarly foobar_usr content to -> usr_t, and foobar_etc_t to etc_t foobar_var_t -> var_t ...

Hi,

I'm afraid this would cause undesired and unexpected "un-confining" of programs / content that used to be confined which could lead to information leaks for example.

Are programs needing access to data from an uninstalled packages something that does effectively happen ? Requiring a custom policy to allow such corner cases does not feel excessive here.

Moreover, changing the labels to some other valid ones may confuse the admin/user more than if files were to be kept with their original labels (if all the types are kept available at all times) or if the labels are set to unlabeled_t which is explicitly telling what happened.

Cheers,

Tim

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