Two data structures, however, are worth mentioning explicitly as they take direct part in the enforcement of LinSec mandatory security policy and will, therefore, be referred to frequently in this Chapter. These structures and their main roles are:
Both of the structures are referenced from the Linux per process structure struct task_struct as illustrated in Figure 5.5 (cardinality is indicated on the arrows).
Mapping of struct task_struct to linsec_task is many to one as the reference to linsec_task is copied (shared) on process forking5.1. To be able to free memory occupied by a linsec_task once it is no longer needed, the structure contains, among other elements, a reference count denoting the number of struct task_struct structures that are referencing it at any particular moment. The reference count is increased on a call to do_fork (kernel/fork.c) and it is decreased on a call to release_task (kernel/exit.c), when a process dies or on call to do_execve (fs/exec.c) i.e. when linsec_task for a process is replaced to reflect privileges of the newly executed binary, respectively. Once the reference count reaches 0 memory occupied by linsec_task is released by linsec_cleanup_task (kernel/linsec_misc.c).
linsec_usr structure is, as depicted in Figure 5.5, referenced from struct task_struct indirectly via the reference to struct user_struct. struct user_struct is used in Linux for user accounting and is shared5.2 among struct task_struct structures describing processes owned by a same user. Consequently, linsec_usr is shared in the same manner among struct task_struct structures. Unlike linsec_task, linsec_usr does not contain any reference counts as it is safe to release memory it occupies once the referencing struct user_struct is dismissed.
When a process changes its ownership, eg. by calling the sys_setuid function, the struct user_struct referenced by it is replaced with the struct user_struct corresponding to the new owner (uid) which in turn references linsec_usr for the new owner (uid).