Skip to contentSkip to conversation

refpolicy: loadable_module.spt improvement?

PATCH Václav Ovsík 2 participants 2 messages Apr 18, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,
while looking into the policy/support/loadable_module.spt I could not catch handling of the policy_call_depth in the template and the interface macro.

define(interface', dnl

        ifdef(`$1',`refpolicyerr(`duplicate definition of $1(). Original definition on '$1.) define(`__if_error')',`define(`$1',__line__)') dnl
        `define(`$1',` dnl
        define(`policy_temp',incr(policy_call_depth)) dnl
        pushdef(`policy_call_depth',policy_temp) dnl
        undefine(`policy_temp') dnl
        policy_m4_comment(policy_call_depth,begin `$1'(dollarsstar)) dnl
        $2
        define(`policy_temp',decr(policy_call_depth)) dnl
        pushdef(`policy_call_depth',policy_temp) dnl
        undefine(`policy_temp') dnl
        policy_m4_comment(policy_call_depth,end `$1'(dollarsstar)) dnl
        '')

')

The policy_call_depth is incremented using temporal policy_temp
- I don't know why. The new definition is pushed into the m4 stack, ok. On the leaving side of macro is the original value not popped from the stack, but new decremented value is pushed into the stack. So stack of the policy_call_depth definitions is growing up.

I prepared fix for this - it is attached. The policy is generated faster by at least 5% with this (intermediate files are smaller and less work for m4 and less memory footprint of m4 I hope).

Best Regards

Signature · 1 line
Zito
policy/support/loadable_module.spt +4 -12
Index: refpolicy-svn/policy/support/loadable_module.spt
===================================================================
@@ -62,14 +62,10 @@
 define(`template',` dnl
 	ifdef(`$1',`refpolicyerr(`duplicate definition of $1(). Original definition on '$1.) define(`__if_error')',`define(`$1',__line__)') dnl
 	`define(`$1',` dnl
-	define(`policy_temp',incr(policy_call_depth)) dnl
-	pushdef(`policy_call_depth',policy_temp) dnl
-	undefine(`policy_temp') dnl
+	pushdef(`policy_call_depth',incr(policy_call_depth)) dnl
 	policy_m4_comment(policy_call_depth,begin `$1'(dollarsstar)) dnl
 	$2 dnl
-	define(`policy_temp',decr(policy_call_depth)) dnl
-	pushdef(`policy_call_depth',policy_temp) dnl
-	undefine(`policy_temp') dnl
+	popdef(`policy_call_depth') dnl
 	policy_m4_comment(policy_call_depth,end `$1'(dollarsstar)) dnl
 	'')
 ')
@@ -83,14 +79,10 @@
 define(`interface',` dnl
 	ifdef(`$1',`refpolicyerr(`duplicate definition of $1(). Original definition on '$1.) define(`__if_error')',`define(`$1',__line__)') dnl
 	`define(`$1',` dnl
-	define(`policy_temp',incr(policy_call_depth)) dnl
-	pushdef(`policy_call_depth',policy_temp) dnl
-	undefine(`policy_temp') dnl
+	pushdef(`policy_call_depth',incr(policy_call_depth)) dnl
 	policy_m4_comment(policy_call_depth,begin `$1'(dollarsstar)) dnl
 	$2
-	define(`policy_temp',decr(policy_call_depth)) dnl
-	pushdef(`policy_call_depth',policy_temp) dnl
-	undefine(`policy_temp') dnl
+	popdef(`policy_call_depth') dnl
 	policy_m4_comment(policy_call_depth,end `$1'(dollarsstar)) dnl
 	'')
 ')
#1 lore raw
Quoted 4 lines · Václav Ovsík

Hi,
while looking into the policy/support/loadable_module.spt I could not catch handling of the policy_call_depth in the template and the interface macro.

[...]

Quoted 9 lines

The policy_call_depth is incremented using temporal policy_temp
- I don't know why. The new definition is pushed into the m4 stack, ok. On the leaving side of macro is the original value not popped from the stack, but new decremented value is pushed into the stack. So stack of the policy_call_depth definitions is growing up.

I prepared fix for this - it is attached. The policy is generated faster by at least 5% with this (intermediate files are smaller and less work for m4 and less memory footprint of m4 I hope).

Good catch. Merged.

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.