Skip to contentSkip to conversation

Making libselinux depend on libsepol

DISCUSSION Ivan Gyurdiev 2 participants 7 messages Jun 16, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

I plan to add a function with this signature:

int security_map_policy(void** newdata, size_t* newlen) or security_create_policy
or security_construct_policy if you prefer..

It will go into a file called policy.c in libselinux, and security_load_policy will go in that file too.

The function would basically do what policycoreutils/load_policy.c does right now - put the policy, users, and booleans together in one simple function in a library form, as opposed to calling a tool to do it.

However, that makes libselinux depend on libsepol.... Is that a bad thing?

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

#1 lore raw
Quoted 9 lines · Ivan Gyurdiev

I plan to add a function with this signature:

int security_map_policy(void** newdata, size_t* newlen) or security_create_policy
or security_construct_policy if you prefer..

It will go into a file called policy.c in libselinux, and security_load_policy will go in that file too.

Quoted 7 lines

The function would basically do what policycoreutils/load_policy.c does right now - put the policy, users, and booleans together in one simple function in a library form, as opposed to calling a tool to do it.

However, that makes libselinux depend on libsepol.... Is that a bad thing?

No, it seems fine, and it is already the case that /sbin/init is depending on libsepol (for the same reason). This should simplify the SELinux patch for /sbin/init and avoid the need to keep customizing it whenever we add another form of runtime policy manipulation (e.g. in addition to booleans and local users, there have also been requests to allow local customizations of network contexts).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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
Quoted 7 lines

No, it seems fine, and it is already the case that /sbin/init is depending on libsepol (for the same reason). This should simplify the SELinux patch for /sbin/init and avoid the need to keep customizing it whenever we add another form of runtime policy manipulation (e.g. in addition to booleans and local users, there have also been requests to allow local customizations of network contexts).

Right, this is all part of Dan's grand plan :)
He has me working on integrating useradd utilities with libselinux and libsepol, but net contexts are next on the list.

I'm changing the signature to this:

int security_map_policy(void** newdata, size_t newlen, int setbools)

Do you think it would be necessary/desirable to specify path locations in the caller also? This seems rather unnecessary to me - not sure.. especially in a function designed to hide the details of the loading process.

--
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
Quoted 4 lines · Ivan Gyurdiev

Right, this is all part of Dan's grand plan :)
He has me working on integrating useradd utilities with libselinux and libsepol, but net contexts are next on the list.

Quoted 8 lines

I'm changing the signature to this:

int security_map_policy(void** newdata, size_t newlen, int setbools)

Do you think it would be necessary/desirable to specify path locations in the caller also? This seems rather unnecessary to me - not sure.. especially in a function designed to hide the details of the loading process.

In the common case, no. For /sbin/init and most existing usage of load_policy, it seems fine to have the library function internally handle the path determination, the open and mmap of the binary policy file, the runtime manipulation of the binary policy image for booleans, users, and whatever, and the call to security_load_policy; thus, it wouldn't even be necessary to return the final binary policy image to the caller. However, that would be a usage change for load_policy(8), as it presently requires the caller to supply a path to the binary policy file (and optionally allows a boolean file path to be specified via -b, but I never bothered adding a similar option for the users directory path).

But even if you do allow the caller to specify the paths (binary policy file, booleans file, users directory), I'm not sure why you need to return the final binary policy image to the caller and require them to separately call security_load_policy.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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 6 lines

In the common case, no. For /sbin/init and most existing usage of load_policy, it seems fine to have the library function internally handle the path determination, the open and mmap of the binary policy file, the runtime manipulation of the binary policy image for booleans, users, and whatever,

Ok..

Quoted 1 line

and the call to security_load_policy;

That part I want to leave out. I'm thinking of the useradd case, where useradd will construct the map, using this new function, and then invoke sepol functions to add users to it (and the file), and then load it separately.

--
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 4 lines · Ivan Gyurdiev

That part I want to leave out. I'm thinking of the useradd case, where useradd will construct the map, using this new function, and then invoke sepol functions to add users to it (and the file), and then load it separately.

Hmmm...ok, keeping in mind that eventually we want to migrate to funnelling all policy changes through the policy daemon/server being developed by Tresys, and only needing to authorize it to load policy into the kernel. Also using the binary/loadable module support for such policy changes.

In any event, how do you intend to deal with the user-specified path to load_policy(8)? If you don't want to pass it to your new function, then load_policy needs to check whether it matches the expected value (i.e. prefix match against selinux_binary_policy_path()) and abort in that case. It actually doesn't make much sense to pass just that path to your function, as you'd really want the policy root in order to use a consistent prefix for the binary policy file, the booleans file, and the users directory.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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
Quoted 3 lines

In any event, how do you intend to deal with the user-specified path to load_policy(8)?

Not sure...

Adding inline:
int security_unmap_policy(void*data, size_t len)

Adding:
__attribute__ ((format (printf, 1, 2)))
void __selinux_debug_printf(const char *fmt, ...)

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