Skip to contentSkip to conversation

Getting Security Identifier (SID) for newly created process

DISCUSSION Pravin 2 participants 5 messages Mar 13, 2007 – Mar 15, 2007 SELinux security module

lore
Share & tools
lore

Pravin

author
#0 lore raw

Hi,
I have some doubts in how the security context of newly created process is decided.
I think that there are some policies written by user, which will decides the security context of new process depending on the security context of the parent process and the executable from which process has been created.

If this is the case, Can I know which is the interface function provided by selinux, that will tell the SID of new process created.

This also raises the question that How first process is getting its security context?
is it from selinux policy or is it being constant?

Thanx,

Signature · 6 lines
Pravin Shinde

--
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 8 lines · Pravin

Hi,
I have some doubts in how the security context of newly created process is decided.
I think that there are some policies written by user, which will decides the security context of new process depending on the security context of the parent process and the executable from which process has been created.

Quoted 6 lines

If this is the case, Can I know which is the interface function provided by selinux, that will tell the SID of new process created.

This also raises the question that How first process is getting its security context?
is it from selinux policy or is it being constant?

There are a set of initial SIDs, and the initial task is assigned one of those initial SIDs, SECINITSID_KERNEL, by selinux_init(). The initial SIDs are later mapped to security contexts defined in the policy configuration when policy is first loaded. When a task forks, the child inherits the SID of the parent. When a task execs a program, a SID for the transformed process is computed by selinux_bprm_set_security and set by selinux_bprm_apply_creds if all checks pass. The SID for the transformed process may be specified by the calling process via setexeccon(3) if allowed by policy, or it will default to calling the security server's security_transition_sid() interface. That interface will check the policy for rules in the policy and use them if present, or default to staying in the same context in their absence.

But this is all internal to SELinux; you should not be calling any of those functions from outside of SELinux directly. Some SELinux functions are exported to the rest of the kernel via include/linux/selinux.h. Some SELinux functions are exported to userspace via selinuxfs.

Why do you ask?

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.
author
#2 lore raw

Hi Stephen,

Quoted 8 lines

But this is all internal to SELinux; you should not be calling any of those functions from outside of SELinux directly. Some SELinux functions are exported to the rest of the kernel via include/linux/selinux.h. Some SELinux functions are exported to userspace via selinuxfs.

Why do you ask?

I dont know if u remember, But I was working on CKRM and SELinux integration. I also sent u a mail regarding my plans of adding hooks inside configfs, so that
we can get better access control by using SELinux ACL's.

Please refer that mail with "SELinux and CKRM integration" for details of my plan about where in CKRM i am planning to add these hooks. If u want, I can resend it again.

As part of those hooks, I also need to add security context to "res_group" data structure (struct res_group) used by CKRM. This is required because SELinux need's to take decision like "Can process A create resource group B" and for that SELinux should be able to addrss "resource group B". This is why I need that security context in "struct res_group".

Here I am stuck about how to give initial SID's to these initial "res_group", and how to give SID's to any newly created res_group.

It will be great, If I can get some help here.

Quoted 5 lines

--
Stephen Smalley
National Security Agency

Thanx for reply.

Signature · 6 lines
Pravin Shinde

--
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 8 lines · Pravin

I dont know if u remember, But I was working on CKRM and SELinux integration. I also sent u a mail regarding my plans of adding hooks inside configfs, so that
we can get better access control by using SELinux ACL's.

Please refer that mail with "SELinux and CKRM integration" for details of my plan about where in CKRM i am planning to add these hooks. If u want, I can resend it again.

I remember, but I wasn't clear on the connection here, as I wouldn't expect you to have to compute the SID for a newly created process in that code. I can see you defining and implementing new LSM/SELinux hooks called by CKRM to allocate, set up, and free security structures for your resource group objects, just as already exist for tasks, inodes, sockets, etc, and those hooks might call security_transition_sid() to compute a SID for the resource group objects.

Quoted 6 lines

As part of those hooks, I also need to add security context to "res_group" data structure (struct res_group) used by CKRM. This is required because SELinux need's to take decision like "Can process A create resource group B" and for that SELinux should be able to addrss "resource group B". This is why I need that security context in "struct res_group".

You wouldn't put it directly there, just like we didn't directly put a security context on task_struct or inode. LSM provides a layer of indirection via the void* security fields, and you make hook calls from your code to allocate, set up, and free the actual security structures.

Quoted 4 lines

Here I am stuck about how to give initial SID's to these initial "res_group", and how to give SID's to any newly created res_group.

It will be great, If I can get some help here.

In the CKRM code, you would just make appropriate calls to LSM hooks and then define SELinux hook function implementations that would handle the actual setting of SIDs. For initial objects, you can do it from selinux_init(), just as we do for the initial task and keyrings, or you can hook your initializer function to call a LSM hook for that purpose (as is done e.g. for kernel sockets).

However, in terms of making sure that your approach is correct, I think you also need to engage the CKRM developers to see if they think you are controlling the right objects and operations based on their knowledge of CKRM internals. I can give general guidance, but I'm no expert on CKRM internals.

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.
author
#4 lore raw

Thanx for reply,

Quoted 5 lines

You wouldn't put it directly there, just like we didn't directly put a security context on task_struct or inode. LSM provides a layer of indirection via the void* security fields, and you make hook calls from your code to allocate, set up, and free the actual security structures.

Yes, we are added a security struct in security/seliux/include/objsec.h named "res_group_security_struct". and void * security field is res_group structure points to it. We have also written the hooks to allot and free memory for this security field in "hooks.c"
We are trying to follow the same structure which is used in task and other kernel object.

Quoted 7 lines

In the CKRM code, you would just make appropriate calls to LSM hooks and then define SELinux hook function implementations that would handle the actual setting of SIDs. For initial objects, you can do it from selinux_init(), just as we do for the initial task and keyrings, or you can hook your initializer function to call a LSM hook for that purpose (as is done e.g. for kernel sockets).

Quoted 5 lines

However, in terms of making sure that your approach is correct, I think you also need to engage the CKRM developers to see if they think you are controlling the right objects and operations based on their knowledge of CKRM internals. I can give general guidance, but I'm no expert on CKRM internals.

I have mailed CKRM mailing list also with all details of the hooks that I am planning to add.
But there was no response from them.
I am planning to mail them again once there is some more progress in work.

Quoted 2 lines

Stephen Smalley
National Security Agency

I am moving ahead with this work. I will come back to u after some progress. Thanx.

Signature · 6 lines
Pravin Shinde

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