Skip to contentSkip to conversation

secilc: is anyone able to confirm that type_change ...

DISCUSSION Dominick Grift 5 participants 18 messages Jul 5, 2014 – Jul 9, 2014 SELinux security module

lore
Share & tools
lore
#0 lore raw

... rules are no longer honored using policy compiled with any of the recent secilc revisions?

My login programs no longer relabel my login tts/pts, even though my policy has, what i believe are, proper type_change rules.

#1 lore raw
Quoted 7 lines · Dominick Grift

... rules are no longer honored using policy compiled with any of the recent secilc revisions?

My login programs no longer relabel my login tts/pts, even though my policy has, what i believe are, proper type_change rules.

the compute_relabel command from libselinux-utils does the right thing. Still for some reason the login programs do not relabelto the type. (the identity is relabeled)

How can this be? sesearch shows the type_change rules, compute_relabel shows the expected result, yet some how all login program's i have tried consistently ignore the type (but not the identity)

I have been running SSHD in debug mode in hopes to get some more information but as far as SSHD is concerned all is fine. It almost seems it is just not aware of the type (needless to say the type is there and usable)

#2 lore raw
Quoted 13 lines · Dominick Grift
Quoted 7 lines · Dominick Grift

... rules are no longer honored using policy compiled with any of the recent secilc revisions?

My login programs no longer relabel my login tts/pts, even though my policy has, what i believe are, proper type_change rules.

the compute_relabel command from libselinux-utils does the right thing. Still for some reason the login programs do not relabelto the type. (the identity is relabeled)

Quoted 9 lines

How can this be? sesearch shows the type_change rules, compute_relabel shows the expected result, yet some how all login program's i have tried consistently ignore the type (but not the identity)

I have been running SSHD in debug mode in hopes to get some more information but as far as SSHD is concerned all is fine. It almost seems it is just not aware of the type (needless to say the type is there and usable)

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Is this with your monogam policy?

#3 lore raw
Quoted 6 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

#4 lore raw
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

#5 lore raw
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

#6 lore raw
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

Awesome, thanks for tracking this down. I was starting to doubt myself.

#7 lore raw
In reply to Steve Lawrence
Quoted 34 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Quoted 7 lines

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Quoted 12 lines

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

#8 lore raw
Quoted 39 lines · Stephen Smalley
Quoted 31 lines · Steve Lawrence
Quoted 23 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 8 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Quoted 7 lines

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Quoted 4 lines

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Lets open a bugzilla on this.

Quoted 19 lines
Quoted 7 lines

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 5 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

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

#9 lore raw
Quoted 41 lines · Daniel J Walsh
Quoted 39 lines · Stephen Smalley
Quoted 38 lines · Steve Lawrence
Quoted 23 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 8 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Quoted 5 lines
Quoted 4 lines

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Lets open a bugzilla on this.

Probably need to crawl the fedora source tree and look for any #include <selinux/flask.h> or #include <selinux/av_permissions.h> references to identify all packages that need to be updated. For permission checks, can just switch over to using selinux_check_access() in most cases and then all the string lookups are handled for you as well as all of the ugliness of dealing with the AVC. May want new wrapper functions for security_compute_* that take the class as a string and internally call string_to_security_class() that can be used instead.

#10 lore raw
Quoted 46 lines · Stephen Smalley
Quoted 45 lines · Daniel J Walsh
Quoted 43 lines · Stephen Smalley
Quoted 31 lines · Steve Lawrence
Quoted 23 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 8 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Quoted 7 lines

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Quoted 5 lines
Quoted 1 line

Lets open a bugzilla on this.

Probably need to crawl the fedora source tree and look for any #include <selinux/flask.h> or #include <selinux/av_permissions.h> references to identify all packages that need to be updated.

Or we could be evil and delete those two header files altogether, or be a bit nicer and put #warning or #error in them.

I see we also wrongly use a hardcoded class in libselinux/src/setexecfilecon.c; should fix that one too.

For permission checks,

Quoted 13 lines

can just switch over to using selinux_check_access() in most cases and then all the string lookups are handled for you as well as all of the ugliness of dealing with the AVC. May want new wrapper functions for security_compute_* that take the class as a string and internally call string_to_security_class() that can be used instead.

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

#11 lore raw
Quoted 46 lines · Stephen Smalley
Quoted 45 lines · Stephen Smalley
Quoted 44 lines · Daniel J Walsh
Quoted 43 lines · Stephen Smalley
Quoted 31 lines · Steve Lawrence
Quoted 23 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 8 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Quoted 7 lines

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Lets open a bugzilla on this.

Probably need to crawl the fedora source tree and look for any #include <selinux/flask.h> or #include <selinux/av_permissions.h> references to identify all packages that need to be updated.

Or we could be evil and delete those two header files altogether, or be a bit nicer and put #warning or #error in them.

I like this idea. This would catch places that we have missed. Could be done in Rawhide.

Quoted 24 lines

I see we also wrongly use a hardcoded class in libselinux/src/setexecfilecon.c; should fix that one too.

For permission checks,

Quoted 7 lines

can just switch over to using selinux_check_access() in most cases and then all the string lookups are handled for you as well as all of the ugliness of dealing with the AVC. May want new wrapper functions for security_compute_* that take the class as a string and internally call string_to_security_class() that can be used instead.

Quoted 6 lines

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

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

#12 lore raw
In reply to Stephen Smalley
Quoted 39 lines · Stephen Smalley
Quoted 31 lines · Steve Lawrence
Quoted 23 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 8 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Quoted 7 lines

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

Quoted 4 lines

Kernel and newer userspace code performs dynamic lookup of class/perm values from strings and handles mapping their own internal indices to the policy-defined values. So this points to a need to update pam_selinux and other older code to map via string_to_security_class().

Please open a bug on pam.

Quoted 19 lines
Quoted 7 lines

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 5 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

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

#13 lore raw
In reply to Steve Lawrence
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

That flask.h file in your url seems to be missing the kernel_service class? (is it outdated?)

I suspect that today's cilpolicy commit is also based on that (outdated?) flask.h file, so cilpolicy may fail to build due to missing kernel_service from classorder statement

#14 lore raw
Quoted 59 lines · Dominick Grift
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

Quoted 6 lines

That flask.h file in your url seems to be missing the kernel_service class? (is it outdated?)

I suspect that today's cilpolicy commit is also based on that (outdated?) flask.h file, so cilpolicy may fail to build due to missing kernel_service from classorder statement

We stopped updating flask.h and av_permissions.h in libselinux once the dynamic class/perm mapping support was merged, only leaving the old definitions intact for legacy code.

The kernel no longer cares about fixed values for the classes/perms; it looks them up by name on policy load.

#15 lore raw
Quoted 67 lines · Stephen Smalley
Quoted 59 lines · Dominick Grift
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

Quoted 6 lines

That flask.h file in your url seems to be missing the kernel_service class? (is it outdated?)

I suspect that today's cilpolicy commit is also based on that (outdated?) flask.h file, so cilpolicy may fail to build due to missing kernel_service from classorder statement

Quoted 8 lines

We stopped updating flask.h and av_permissions.h in libselinux once the dynamic class/perm mapping support was merged, only leaving the old definitions intact for legacy code.

The kernel no longer cares about fixed values for the classes/perms; it looks them up by name on policy load.

Yes, Okay thanks. This is basically a heads-up to the cilpolicy maintainer. Just to let him know that cilpolicy *may* fail to build currently due to this issue (there are more AV's missing in that flask.h BTW)

Maybe better to get rid of that file if possible. It is pretty confusing. I did a find /usr/lib -name flask.h and it returned two entries both outdated and also both different with one even older than the other.

#16 lore raw
Quoted 82 lines · Dominick Grift
Quoted 67 lines · Stephen Smalley
Quoted 59 lines · Dominick Grift
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

Quoted 6 lines

That flask.h file in your url seems to be missing the kernel_service class? (is it outdated?)

I suspect that today's cilpolicy commit is also based on that (outdated?) flask.h file, so cilpolicy may fail to build due to missing kernel_service from classorder statement

Quoted 8 lines

We stopped updating flask.h and av_permissions.h in libselinux once the dynamic class/perm mapping support was merged, only leaving the old definitions intact for legacy code.

The kernel no longer cares about fixed values for the classes/perms; it looks them up by name on policy load.

Yes, Okay thanks. This is basically a heads-up to the cilpolicy maintainer. Just to let him know that cilpolicy *may* fail to build currently due to this issue (there are more AV's missing in that flask.h BTW)

Quoted 4 lines

Maybe better to get rid of that file if possible. It is pretty confusing. I did a find /usr/lib -name flask.h and it returned two entries both outdated and also both different with one even older than the other.

Re-posting with the list included.

Quoted 1 line

From b6d73c2d1731e623ce7cb443935973f6a756b84c Mon Sep 17 00:00:00 2001

From: Stephen Smalley <[email protected]>
Date: Wed, 9 Jul 2014 13:25:56 -0400
Subject: [PATCH] Deprecate use of flask.h and av_permissions.h.

Also remove all internal uses by libselinux.
This requires deleting the old class/perm string lookup tables and compatibility code for kernels that predate the /sys/fs/selinux/class tree, i.e. Linux < 2.6.23.

This also fixes a longstanding bug in the stringrep code; it was allocating NVECTORS (number of vectors in the legacy av_perm_to_string table, i.e. the total number of legacy permissions) entries in the per-class perms array rather than MAXVECTORS (the maximum number of permissions in any access vector). Ho hum. I already fixed this in Android but forgot it here.

---
 libselinux/include/selinux/av_permissions.h |   3 +
 libselinux/include/selinux/flask.h          |   3 +
 libselinux/src/av_inherit.h                 |  38 ----
 libselinux/src/av_perm_to_string.h          | 325 ----------------------------
 libselinux/src/checkAccess.c                |   2 -
 libselinux/src/class_to_string.h            |  78 -------
 libselinux/src/common_perm_to_string.h      |  67 ------
 libselinux/src/selinuxswig.i                |   2 -
 libselinux/src/setexecfilecon.c             |   3 +-
 libselinux/src/stringrep.c                  | 292 +------------------------
 libselinux/utils/selinuxexeccon.c           |   3 +-
 policycoreutils/mcstrans/src/mcscolor.c     |   4 +-
 policycoreutils/newrole/newrole.c           |   3 +-
 13 files changed, 15 insertions(+), 808 deletions(-)
 delete mode 100644 libselinux/src/av_inherit.h
 delete mode 100644 libselinux/src/av_perm_to_string.h
 delete mode 100644 libselinux/src/class_to_string.h
 delete mode 100644 libselinux/src/common_perm_to_string.h
libselinux/include/selinux/av_permissions.h +3 -0
index b1e7860..c1269af 100644
@@ -1,3 +1,6 @@
+#warning "Please remove any #include of this header in your source code."
+#warning "Instead, use string_to_av_perm() to map the permission name to a value."
+
 /* This file is automatically generated.  Do not edit. */
 #define COMMON_FILE__IOCTL                               0x00000001UL
 #define COMMON_FILE__READ                                0x00000002UL
libselinux/include/selinux/flask.h +3 -0
index 08e8085..8128223 100644
@@ -2,6 +2,9 @@
 #ifndef _SELINUX_FLASK_H_
 #define _SELINUX_FLASK_H_
 
+#warning "Please remove any #include's of this header in your source code."
+#warning "Instead, use string_to_security_class() to map the class name to a value."
+
 /*
  * Security object class definitions
  */
libselinux/src/av_inherit.h deleted +0 -38
deleted file mode 100644
index 21effa7..0000000
@@ -1,38 +0,0 @@
-/* This file is automatically generated.  Do not edit. */
-   S_(SECCLASS_DIR, file, 0x00020000UL)
-   S_(SECCLASS_FILE, file, 0x00020000UL)
-   S_(SECCLASS_LNK_FILE, file, 0x00020000UL)
-   S_(SECCLASS_CHR_FILE, file, 0x00020000UL)
-   S_(SECCLASS_BLK_FILE, file, 0x00020000UL)
-   S_(SECCLASS_SOCK_FILE, file, 0x00020000UL)
-   S_(SECCLASS_FIFO_FILE, file, 0x00020000UL)
-   S_(SECCLASS_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_TCP_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_UDP_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_RAWIP_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_PACKET_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_KEY_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_UNIX_STREAM_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_UNIX_DGRAM_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_IPC, ipc, 0x00000200UL)
-   S_(SECCLASS_SEM, ipc, 0x00000200UL)
-   S_(SECCLASS_MSGQ, ipc, 0x00000200UL)
-   S_(SECCLASS_SHM, ipc, 0x00000200UL)
-   S_(SECCLASS_NETLINK_ROUTE_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_FIREWALL_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_TCPDIAG_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_NFLOG_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_XFRM_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_SELINUX_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_AUDIT_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_IP6FW_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_DNRT_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_APPLETALK_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_DCCP_SOCKET, socket, 0x00400000UL)
-   S_(SECCLASS_DB_DATABASE, database, 0x00000040UL)
-   S_(SECCLASS_DB_TABLE, database, 0x00000040UL)
-   S_(SECCLASS_DB_PROCEDURE, database, 0x00000040UL)
-   S_(SECCLASS_DB_COLUMN, database, 0x00000040UL)
-   S_(SECCLASS_DB_BLOB, database, 0x00000040UL)
libselinux/src/av_perm_to_string.h deleted +0 -325

325 lines not on this page · raw message

libselinux/src/checkAccess.c +0 -2
index cd2a817..ee85ebc 100644
@@ -4,9 +4,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include "selinux_internal.h"
-#include <selinux/flask.h>
 #include <selinux/avc.h>
-#include <selinux/av_permissions.h>
 #include "avc_internal.h"
 
 static pthread_once_t once = PTHREAD_ONCE_INIT;
libselinux/src/class_to_string.h deleted +0 -78

78 lines not on this page · raw message

libselinux/src/common_perm_to_string.h deleted +0 -67

67 lines not on this page · raw message

libselinux/src/selinuxswig.i +0 -2
index 969863a..c72b818 100644
@@ -5,9 +5,7 @@
 %module selinux
 %{
 	#include "../include/selinux/avc.h"
-	#include "../include/selinux/av_permissions.h"
 	#include "../include/selinux/context.h"
-	#include "../include/selinux/flask.h"
 	#include "../include/selinux/get_context_list.h"
 	#include "../include/selinux/get_default_type.h"
 	#include "../include/selinux/label.h"
libselinux/src/setexecfilecon.c +1 -2
index e574de1..e72ba0d 100644
@@ -1,7 +1,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
-#include <selinux/flask.h>
 #include "selinux_internal.h"
 #include "context_internal.h"
 
@@ -22,7 +21,7 @@ int setexecfilecon(const char *filename, const char *fallback_type)
 	if (rc < 0)
 		goto out;
 
-	rc = security_compute_create(mycon, fcon, SECCLASS_PROCESS, &newcon);
+	rc = security_compute_create(mycon, fcon, string_to_security_class("process"), &newcon);
 	if (rc < 0)
 		goto out;
 
libselinux/src/stringrep.c +5 -287

358 lines not on this page · raw message

libselinux/utils/selinuxexeccon.c +1 -2
index 4ac7e86..e0212e4 100644
@@ -6,7 +6,6 @@
 #include <errno.h>
 #include <string.h>
 #include <ctype.h>
-#include <selinux/flask.h>
 #include <selinux/selinux.h>
 
 static void usage(const char *name, const char *detail, int rc)
@@ -22,7 +21,7 @@ static char * get_selinux_proc_context(const char *command, char * execcon) {
 
 	int ret = getfilecon(command, &fcon);
 	if (ret < 0) goto err;
-	ret = security_compute_create(execcon, fcon, SECCLASS_PROCESS, &newcon);
+	ret = security_compute_create(execcon, fcon, string_to_security_class("process"), &newcon);
 	if (ret < 0) goto err;
 
 err:
policycoreutils/mcstrans/src/mcscolor.c +1 -3
index 90c4321..fdb7048 100644
@@ -9,8 +9,6 @@
 #include <alloca.h>
 #include <fnmatch.h>
 #include <syslog.h>
-#include <selinux/flask.h>
-#include <selinux/av_permissions.h>
 #include <selinux/selinux.h>
 #include <selinux/context.h>
 #include "mcstrans.h"
@@ -110,7 +108,7 @@ static int check_dominance(const char *pattern, const char *raw) {
 	if (!raw)
 		goto out;
 
-	rc = security_compute_av_raw(ctx, (security_context_t)raw, SECCLASS_CONTEXT, bit, &avd);
+	rc = security_compute_av_raw(ctx, (security_context_t)raw, string_to_security_class("context"), bit, &avd);
 	if (rc)
 		goto out;
 
policycoreutils/newrole/newrole.c +1 -2
index dfb8c7f..495cf2e 100644
@@ -66,7 +66,6 @@
 #include <string.h>
 #include <errno.h>
 #include <selinux/selinux.h>	/* for is_selinux_enabled() */
-#include <selinux/flask.h>	/* for SECCLASS_CHR_FILE */
 #include <selinux/context.h>	/* for context-mangling functions */
 #include <selinux/get_default_type.h>
 #include <selinux/get_context_list.h>	/* for SELINUX_DEFAULTUSER */
@@ -711,7 +710,7 @@ static int relabel_tty(const char *ttyn, security_context_t new_context,
 
 	if (tty_con &&
 	    (security_compute_relabel(new_context, tty_con,
-				      SECCLASS_CHR_FILE, &new_tty_con) < 0)) {
+				      string_to_security_class("chr_file"), &new_tty_con) < 0)) {
 		fprintf(stderr, _("%s!  Could not get new context for %s, "
 				  "not relabeling tty.\n"),
 			enforcing ? "Error" : "Warning", ttyn);
Signature · 1 line
1.9.3
#17 lore raw
In reply to Dominick Grift
Quoted 59 lines · Dominick Grift
Quoted 49 lines · Steve Lawrence
Quoted 25 lines · Dominick Grift
Quoted 6 lines · Dominick Grift
Quoted 4 lines · Steve Lawrence

I can't reproduce the problem with my test policies. The typechange statements look like they are correctly inserted into the binary and I am seeing the expected type changes at runtime.

Quoted 9 lines
Quoted 2 lines

Is this with your monogam policy?

No, that one is no longer maintained.

It is this very small base policy:

https://github.com/doverride/e145

Note though, with that version, that there is no type_change rule from devpts_t to device_session_pts_t currently (so if you were to test this with sshd then it would be lacking the type change rule)

Either insert that type_change rule manually or test it with the (local) login program since there is a type_change session_t device_tty_t:chr_file device_session_tty_t rule present.

Quoted 7 lines

There is also a conditional type change rule for console_device_t to device_session_tty_t.

I cannot imagine me having overlooked anything. Since there are only two domains (system_t and session_t), and both are virtually unconfined.

Ok, finally managed to track down this issue. Turns out to be an ordering problem. You have your classes listed in alphabetical order. Order shouldn't matter with CIL and everything should work correctly, and in most cases is does. However, we assign integer values to each class based on the order we see them. So the first one we see gets value 1, second gets 2, etc. If these values don't match up with what userspace and the kernel expect them to be, things break.

So the temporary solution is to reorder your class statements so that they are in the order defined in flask.h [1] so they get the right values.

The long term solution is to add a new statement to CIL (classorder, similar to sidorder) that defines this order, allowing the class definitions to appear in any order.

Quoted 8 lines

Thanks,
- Steve

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/include/selinux/flask.h

Quoted 7 lines

That flask.h file in your url seems to be missing the kernel_service class? (is it outdated?)

I suspect that today's cilpolicy commit is also based on that (outdated?) flask.h file, so cilpolicy may fail to build due to missing kernel_service from classorder statement

It is actually just based on an older version of Refpolicy and I should update it.

Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency