Skip to contentSkip to conversation

fork rules

DISCUSSION Arpan Darivemula 3 participants 5 messages Jun 5, 2005 – Jun 6, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi

Could I please get some help with the following rule:
Here is what I'm trying to do: I want to have a rule that toggles a process fork. Here is what I have

----fork.c----

# include <stdio.h>
# include <unistd.h>

int main( int argc, char **argv )

{
        int pid;

        pid = getpid();
        printf( "Parent PID: %i\n", pid );

        if ( fork() == 0 )
        {
                pid = getpid();
                printf( "Child PID: %i\n", pid );
        }
}

---------------
----fc file----
/home/dsi/fork -- user_u:object_r:dsifork_exec_t
---------------
----te file----
type dsifork_exec_t, file_type, sysadmfile;
allow user_t dsifork_exec_t:file {execute execute_no_trans read}; neverallow dsifork_exec_t self:process{fork};
----------------
Now the process forks nonetheless. The rule does not make any difference in stopping the fork. How can I control a fork in this ? I want to be able to have a line that can allow or block the fork.

Thankyou
Arpan

--
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 13 lines · Arpan Darivemula

int main( int argc, char **argv )

{
        int pid;

        pid = getpid();
        printf( "Parent PID: %i\n", pid );

        if ( fork() == 0 )
        {
                pid = getpid();
                printf( "Child PID: %i\n", pid );
        }
}

I'd stick a 'sleep(120);' in there just before the fork() call, and then start using 'pa axZ' or similar to find out what you're actually running as.

Quoted 1 line

neverallow dsifork_exec_t self:process{fork};

You're probably not actually in dsifork_exec_t. Probably because:

Quoted 1 line

allow user_t dsifork_exec_t:file {execute execute_no_trans read};

Did you really want execute_*NO*_trans there? That means that a user_t can exec a dsifork_exec_t and *remain* a user_t. I think you wanted something like:

domain_auto_trans(user_t, dsi_fork_t, dsi_fork_exec_t); neverallow dsi_fork_t self:process(fork);

and then label the file as dsi_fork_exec_t, and apply the restriction to dsi_fork_t

#2 lore raw

Thank you for the reply. It gave me a clearer understanding of the process.
Arpan

Quoted 29 lines · On Sun, 2005-06-05 at 21:48 -0400, [email protected] wrote:
Quoted 13 lines · Arpan Darivemula

int main( int argc, char **argv )

{
        int pid;

        pid = getpid();
        printf( "Parent PID: %i\n", pid );

        if ( fork() == 0 )
        {
                pid = getpid();
                printf( "Child PID: %i\n", pid );
        }
}

I'd stick a 'sleep(120);' in there just before the fork() call, and then start using 'pa axZ' or similar to find out what you're actually running as.

Quoted 1 line

neverallow dsifork_exec_t self:process{fork};

You're probably not actually in dsifork_exec_t. Probably because:

Quoted 1 line

allow user_t dsifork_exec_t:file {execute execute_no_trans read};

Did you really want execute_*NO*_trans there? That means that a user_t can exec a dsifork_exec_t and *remain* a user_t. I think you wanted something like:

Quoted 6 lines

domain_auto_trans(user_t, dsi_fork_t, dsi_fork_exec_t); neverallow dsi_fork_t self:process(fork);

and then label the file as dsi_fork_exec_t, and apply the restriction to dsi_fork_t

--
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
In reply to Arpan Darivemula
Quoted 11 lines · Arpan Darivemula

----fc file----
/home/dsi/fork -- user_u:object_r:dsifork_exec_t
---------------
----te file----
type dsifork_exec_t, file_type, sysadmfile;
allow user_t dsifork_exec_t:file {execute execute_no_trans read}; neverallow dsifork_exec_t self:process{fork};
----------------
Now the process forks nonetheless. The rule does not make any difference in stopping the fork. How can I control a fork in this ? I want to be able to have a line that can allow or block the fork.

1) dsifork_exec_t is the type of an executable file, not a process domain. You need a type dsifork_t, domain; statement to declare the process domain and a domain_auto_trans(user_t, dsifork_exec_t, dsifork_t) macro call to set up the transition from user_t to dsifork_t upon executing the executable file.
2) A domain can only do what is explicitly allowed by allow rules, nothing more. neverallow is a compile-time assertion on the policy (i.e. verify that there are no allow rules in the policy that give this permission), not a runtime policy rule.

Naturally, looking at existing policy for examples is always a good idea. Also, see
http://selinux.sourceforge.net/resources.php3
for some documentation resources that are available.

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

Thank you for clearing up the use of neverallow.
Arpan

Quoted 23 lines · Stephen Smalley
Quoted 11 lines · Arpan Darivemula

----fc file----
/home/dsi/fork -- user_u:object_r:dsifork_exec_t
---------------
----te file----
type dsifork_exec_t, file_type, sysadmfile;
allow user_t dsifork_exec_t:file {execute execute_no_trans read}; neverallow dsifork_exec_t self:process{fork};
----------------
Now the process forks nonetheless. The rule does not make any difference in stopping the fork. How can I control a fork in this ? I want to be able to have a line that can allow or block the fork.

1) dsifork_exec_t is the type of an executable file, not a process domain. You need a type dsifork_t, domain; statement to declare the process domain and a domain_auto_trans(user_t, dsifork_exec_t, dsifork_t) macro call to set up the transition from user_t to dsifork_t upon executing the executable file.
2) A domain can only do what is explicitly allowed by allow rules, nothing more. neverallow is a compile-time assertion on the policy (i.e. verify that there are no allow rules in the policy that give this permission), not a runtime policy rule.

Quoted 5 lines

Naturally, looking at existing policy for examples is always a good idea. Also, see
http://selinux.sourceforge.net/resources.php3
for some documentation resources that are available.

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