Skip to contentSkip to conversation

Debugging sepolgen-ifgen?

DISCUSSION Sven Vermeulen 5 participants 7 messages Aug 2, 2014 – Aug 27, 2014 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Wkr,
Sven Vermeulen

#1 lore raw
Quoted 28 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

Quoted 8 lines

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some syntax errors during parsing, sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have above.

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

#2 lore raw
Quoted 62 lines · Stephen Smalley
Quoted 28 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

Quoted 8 lines

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some syntax errors during parsing, sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have above.

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

Quoted 7 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

I don't see anything obviously wrong with that patch?

#3 lore raw
Quoted 64 lines · Daniel J Walsh
Quoted 62 lines · Stephen Smalley
Quoted 28 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

Quoted 8 lines

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some syntax errors during parsing, sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have above.

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

Quoted 8 lines
Quoted 7 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

I don't see anything obviously wrong with that patch?

If I revert that one patch, it works. I don't know offhand what the underlying issue is, but I'd guess you are introducing an ambiguity into the grammar. I do notice that the definitions of IDENTIFIER and FILENAME do not match the ones in checkpolicy policy_scan.l; I do not know why that is. I also notice that whereas bison reports no warnings on the checkpolicy policy_parse.y grammar, sepolgen-ifgen -d reports 669 shift/reduce conflicts before your patch and 671 shift/reduce conflicts afterward; neither seems very good...

#4 lore raw
Quoted 74 lines · Stephen Smalley
Quoted 64 lines · Daniel J Walsh
Quoted 62 lines · Stephen Smalley
Quoted 28 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

Quoted 8 lines

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some syntax errors during parsing, sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have above.

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

Quoted 8 lines
Quoted 7 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

I don't see anything obviously wrong with that patch?

Quoted 8 lines

If I revert that one patch, it works. I don't know offhand what the underlying issue is, but I'd guess you are introducing an ambiguity into the grammar. I do notice that the definitions of IDENTIFIER and FILENAME do not match the ones in checkpolicy policy_scan.l; I do not know why that is. I also notice that whereas bison reports no warnings on the checkpolicy policy_parse.y grammar, sepolgen-ifgen -d reports 669 shift/reduce conflicts before your patch and 671 shift/reduce conflicts afterward; neither seems very good...

Looking at the patch that seems to have caused the problem, it makes the following change:

@@ -461,6 +469,7 @@ def p_interface_call_param(p):
def p_interface_call_param_list(p):
'''interface_call_param_list : interface_call_param
| interface_call_param_list COMMA
interface_call_param
+ | interface_call_param_list COMMA
interface_call_param COMMA interface_call_param_list

     '''
     if len(p) == 2:
         p[0] = [p[1]]

For some reason, it adds a new pattern to the interface_call_param_list pattern, which is "list, param, list". To me, this doesn't seem necessary. The first two patterns should cover all combinations of interface call parameters. And reverting this hunk gives the same InterfaceVector as with the patch reverted. So it seems like the right fix.

Dan, any idea why this hunk was added?

Thanks,
- Steve

#5 lore raw
Quoted 101 lines · Steve Lawrence
Quoted 72 lines · Stephen Smalley
Quoted 63 lines · Daniel J Walsh
Quoted 62 lines · Stephen Smalley
Quoted 28 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which is coded as follows:

interface(kernel_rw_kernel_sysctl',
gen_require(`
type proc_t, sysctl_t, sysctl_kernel_t;
')

rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t }, sysctl_kernel_t)

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about this interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Shouldn't this at least contain something like this?

Quoted 8 lines

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen, but rerunning doesn't add in any file-related metadata and I'm totally oblivious on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some syntax errors during parsing, sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have above.

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

Quoted 8 lines
Quoted 7 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

I don't see anything obviously wrong with that patch?

Quoted 8 lines

If I revert that one patch, it works. I don't know offhand what the underlying issue is, but I'd guess you are introducing an ambiguity into the grammar. I do notice that the definitions of IDENTIFIER and FILENAME do not match the ones in checkpolicy policy_scan.l; I do not know why that is. I also notice that whereas bison reports no warnings on the checkpolicy policy_parse.y grammar, sepolgen-ifgen -d reports 669 shift/reduce conflicts before your patch and 671 shift/reduce conflicts afterward; neither seems very good...

Looking at the patch that seems to have caused the problem, it makes the following change:

(quoted diff) +0 -0
@@ -461,6 +469,7 @@ def p_interface_call_param(p):
 def p_interface_call_param_list(p):
     '''interface_call_param_list : interface_call_param
                                  | interface_call_param_list COMMA

interface_call_param
+ | interface_call_param_list COMMA
interface_call_param COMMA interface_call_param_list

     '''
     if len(p) == 2:
         p[0] = [p[1]]

For some reason, it adds a new pattern to the interface_call_param_list pattern, which is "list, param, list". To me, this doesn't seem necessary. The first two patterns should cover all combinations of interface call parameters. And reverting this hunk gives the same InterfaceVector as with the patch reverted. So it seems like the right fix.

Quoted 4 lines

Dan, any idea why this hunk was added?

Thanks,
- Steve

If you remove it and the command succeeds I am happy. Most of these changes were made to just stop the
application from blowing up. If we get better accuracy on matches and the code does not break, It is a win win.

#6 lore raw
In reply to Stephen Smalley

FWIW, most of the shift / reduce conflicts are because the grammar really is ambiguous (since we are trying to parse both the selinux policy language and the m4 additions on top of that). While in an ideal world those would be cleaned up so that we would at least choose what to do in the ambiguous cases it just never seemed worthwhile to me.

Karl

Quoted 91 lines · Stephen Smalley
Quoted 9 lines · Daniel J Walsh
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Sven Vermeulen

Hi all

I've noticed that on my system, for some interfaces, the results in /var/lib/sepolgen/interface_info are missing file-specific feedback.

For instance, consider the kernel_rw_kernel_sysctl() interface, which

is

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

coded as follows:

interface(kernel_rw_kernel_sysctl',

        gen_require(`
                type proc_t, sysctl_t, sysctl_kernel_t;
        ')

        rw_files_pattern($1, { proc_t sysctl_t sysctl_kernel_t },

sysctl_kernel_t)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

list_dirs_pattern($1, { proc_t sysctl_t }, sysctl_kernel_t)
')

In the interface_info file, I only find the following metadata about

this

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

interface:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,dir,getattr,open,search $1,proc_t,dir,getattr,open,search

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Shouldn't this at least contain something like this?

$1,sysctl_kernel_t,file,write,getattr,lock,open,ioctl,append

Although not critical, it does result in audit2allow -R to not use refpolicy-style interfaces when possible...

How can I debug this? I know the file is generated by sepolgen-ifgen,

but

Quoted 1 line
Quoted 1 line
Quoted 1 line

rerunning doesn't add in any file-related metadata and I'm totally

oblivious

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

on how the parsing is done...

Not sure about that beyond the -d -v options.
However, this appears to be a regression; despite encountering some

syntax errors during parsing,

Quoted 9 lines
Quoted 9 lines

sepolgen-ifgen from 21030423 generates a more accurate vector:

[InterfaceVector kernel_rw_kernel_sysctl $1:source ] $1,sysctl_t,dir,getattr,open,search $1,sysctl_kernel_t,file,write,getattr,read,lock,open,ioctl,append $1,sysctl_kernel_t,dir,search,read,lock,ioctl,getattr,open $1,proc_t,dir,getattr,open,search

while sepolgen-ifgen from 20131030_4 generates the reduced set you have

above.

Quoted 14 lines
Quoted 14 lines

Seems to have been broken by:

commit 17cc87e56b0241688c119f774f103622b002e0ae

Author: Dan Walsh <[email protected]>
Date:   Wed Oct 9 17:01:35 2013 -0400

sepolgen did not work with filename transitions.

This patch adds support for it.

Quoted 5 lines
Quoted 5 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to

[email protected].

Quoted 3 lines
Quoted 2 lines

I don't see anything obviously wrong with that patch?

If I revert that one patch, it works. I don't know offhand what the underlying issue is, but I'd guess you are introducing an ambiguity into the grammar. I do notice that the definitions of IDENTIFIER and FILENAME do not match the ones in checkpolicy policy_scan.l; I do not know why that is. I also notice that whereas bison reports no warnings on the checkpolicy policy_parse.y grammar, sepolgen-ifgen -d reports 669 shift/reduce conflicts before your patch and 671 shift/reduce conflicts afterward; neither seems very good...