All of lore.kernel.org
 help / color / mirror / Atom feed
* How can modular policy ever have worked? [patch]
@ 2006-03-18 14:20 Erich Schubert
  2006-03-20 14:39 ` Stephen Smalley
  2006-03-20 15:25 ` Christopher J. PeBenito
  0 siblings, 2 replies; 11+ messages in thread
From: Erich Schubert @ 2006-03-18 14:20 UTC (permalink / raw)
  To: SE Linux; +Cc: Christopher J. PeBenito

[-- Attachment #1: Type: text/plain, Size: 3215 bytes --]

Hi,
After investigating the M4 macros a bit closer (and after being pointed
in the right direction by Method), I wonder how modular policy ever can
have worked.

<Method> right now while building base the optional_policy is turned
into an m4 ifdef, if the module that activates the optional_policy isn't
also in base it essentially disappears

Fact (look at the source):
optional(`whatever',`...')
gets reduced to nothing when building base.pp and whatever as module.
That way base.pp doesn't contain any optional statements, because the
compiler used to not support that yet. (Method says he added this
support)
When building a module, it is expanded to a proper optional {}
statement.

I discovered this after investigating why building mta into base and
policy as module didn't work right - the optional(`postfix',`...') part
gets lost, so /usr/lib/sendmail can't transition into postdrop_t, so it
can't write mails to the postfix queues.
When I build mta as module this worked just fine.

However, this is a chain, and the only "stable" solution is to build a
monolithic policy. Some examples:

policy/modules/kernel/kernel.te:
optional_policy(`init',`

So if you have kernel in base (which is required) you should also put
init, logging, selinuxutil, rpc, portmap, nis, library, hotplug
into base, in order not to lose the optional statements in kernel.
Other modules in base have similar "optional dependencies", of course.

Now let's look at init... you'll find just about any service package
having an optional statement in init.te (which I consider ugly,
actually, having to have
something in the init.te module for a service!)

So basically, unless you build a monolithic policy, certain rules will
be missing from your linked policy that were "optional" in the policy
source. Ouch.

Attached patch will write appropriate optional {} statements to the base
policy.
In my module configuration (I've lots of stuff in base), diffstat for
the base.conf file gives: 36558 insertions(+), no deletions.
(I have filtered any "#line 123" and whitespace-only lines from this
stat)

So (as the attached diff should suggest anyway), this will only generate
additional statement for the policy.

The resulting base.pp file is almost twice as big, however the
"expanded" policy is only half the size and missing like 19k lines...
most of them pretty essential :-( So linking is not yet working
correctly; it doesn't throw any errors but the resulting files are badly
shreddered.

This also seems to turn up a problem in the linux kernel (2.6.15, not
the latest patches yet, sorry):
Even the _working_ (well, except for the missing rules) policy generated
without this patch, will link, but not load any more:
[...]
Committing changes:
/usr/sbin/load_policy:  Can't load policy:  Invalid argument

So it seems the kernel is now rejecting any policy loads, albeit it
still in permissive mode.

best regards,
Erich Schubert
-- 
   erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C    (o_
       The best things in life are free: Friendship and Love.       //\
     Glück ist, wenn man dafür geliebt wird, wie man eben ist.      V_/_

[-- Attachment #2: refpolicy-module-optionals.diff --]
[-- Type: text/x-patch, Size: 1797 bytes --]

Index: policy/support/loadable_module.spt
===================================================================
--- policy/support/loadable_module.spt	(Revision 63)
+++ policy/support/loadable_module.spt	(Revision 64)
@@ -24,7 +24,14 @@
 # For use in interfaces, to optionally insert a require block
 #
 define(`gen_require',`
-	ifdef(`self_contained_policy',`',`
+	ifdef(`self_contained_policy',`
+		ifdef(`modular_base_policy',`
+			ifdef(`in_optional_statement',`
+				require {
+					$1
+				}
+			')
+		')',`
 		require {
 			$1
 		}
@@ -87,10 +94,26 @@
 #
 define(`optional_policy',`
 	ifdef(`self_contained_policy',`
-		ifdef(`$1.te',`$2',`$3')
+		ifdef(`$1.te',`$2',`
+			ifdef(`modular_base_policy',`
+				optional {
+					pushdef(`in_optional_statement') dnl
+					$2
+					popdef(`in_optional_statement') dnl
+				ifelse(`$3',`',`',`
+				} else {
+					$3
+				')
+				}
+			',`
+				$3
+			')
+		')
 	',`
 		optional {
+			pushdef(`in_optional_statement') dnl
 			$2
+			popdef(`in_optional_statement') dnl
 		ifelse(`$3',`',`',`
 		} else {
 			$3
Index: Rules.modular
===================================================================
--- Rules.modular	(Revision 63)
+++ Rules.modular	(Revision 64)
@@ -111,7 +111,7 @@
 	@test -d $(TMPDIR) || mkdir -p $(TMPDIR)
 	@test -d $(dir $(BASE_CONF)) || mkdir -p $(dir $(BASE_CONF))
 # checkpolicy can use the #line directives provided by -s for error reporting:
-	$(verbose) m4 -D self_contained_policy $(M4PARAM) -s $^ > $(TMPDIR)/$(@F).tmp
+	$(verbose) m4 -D self_contained_policy -D modular_base_policy $(M4PARAM) -s $^ > $(TMPDIR)/$(@F).tmp
 	$(verbose) sed -e /^portcon/d -e /^nodecon/d -e /^netifcon/d < $(TMPDIR)/$(@F).tmp > $@
 # the ordering of these ocontexts matters:
 	$(verbose) grep ^portcon $(TMPDIR)/$(@F).tmp >> $@ || true

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-03-27 15:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-18 14:20 How can modular policy ever have worked? [patch] Erich Schubert
2006-03-20 14:39 ` Stephen Smalley
2006-03-20 15:16   ` Erich Schubert
2006-03-20 16:00     ` Stephen Smalley
2006-03-25 23:57       ` Erich Schubert
2006-03-26  3:27         ` Joshua Brindle
2006-03-27 15:48         ` Christopher J. PeBenito
2006-03-20 16:57     ` Christopher J. PeBenito
2006-03-21 16:21       ` Christopher J. PeBenito
2006-03-23 20:12         ` Stephen Smalley
2006-03-20 15:25 ` Christopher J. PeBenito

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.