Difference between revisions of "Adding New Permissions"

From SELinux Wiki
Jump to: navigation, search
Line 1: Line 1:
(from [http://marc.info/?l=selinux&m=120491447421303&w=2 this mailing list post])
+
<p>To develop patches for the kernel security subsystem, use git to clone the security-testing-2.6 tree, as described at: http://security.wiki.kernel.org/index.php/Kernel_Repository</p>
  
<br />
+
<p>To develop patches for the SELinux reference policy, use git to clone the refpolicy tree via git clone http://oss.tresys.com/git/refpolicy.git</p>
<br />
+
  
 
<p>
 
<p>
 +
To add a new class and/or permission to the SELinux kernel code:
 +
<br>
 +
New way (with dynamic class/perm discovery, scheduled for kernels >= 2.6.33):
 +
<ol>
 +
<li>Edit security/selinux/include/classmap.h in the kernel tree and add your definition.
 +
This will define the class and/or permission for use in the kernel; the corresponding symbol
 +
definitions will be automatically generated during the kernel build.  If not defined in the policy, then
 +
the class and/or permission will be handled in accordance with your policy's handle_unknown definition,
 +
which can be reject (refuse to load the policy), deny (deny the undefined class/permission), or allow (allow the undefined class/permission).
 +
<li>Edit refpolicy/policy/flask/security_classes and/or access_vectors in the refpolicy tree and add your definition.  This will define the class and permission for use in the policy.  You generally need to add the class and/or permission at the end of the existing list of classes or permissions for that class for backward compatibility with older kernels.  The class and/or permission definition in policy need not line up with the definition in the kernel's classmap, as the values will be dynamically mapped by the kernel.  Then add allow rules as appropriate to the policy for the new permissions.
 +
</ol>
  
 
+
Old way (for kernel < 2.6.33):
<pre>
+
<ol>
To add a new permission to SELinux:
+
<li>Edit refpolicy/policy/flask/security_classes and/or access_vectors and add your definitions, typically at the end of the existing lists.
1) checkout a copy of the refpolicy from oss.tresys.com or build prep the rawhide selinux policy src rpm
+
<li>make LINUX_D=/path/to/linux-2.6 tokern<br>
2) cd refpolicy/policy/flask/
+
This will generate header files containing the symbolic definitions for the classes and/or permissions and copy them into the kernel tree located at /path/to/linux-2.6.  The class and/or permission definition in the policy must line up with the definitions used in the kernel.
3) edit access_vectors and add your definition
+
</ol>
4) run make
+
5) run make LINUX_D=/path/to/linux-2.6 tokern to push the kernel headers
+
to your kernel tree
+
6) run make LIBSELINUX_D=/path/to/libselinux tolib to push the
+
libselinux headers to your libselinux tree.
+
 
+
Then you can generate patches against policy, kernel, and libselinux.
+
  
 
There is also the backward compatibility issue - we must not break
 
There is also the backward compatibility issue - we must not break
 
akpm's system if he boots a new kernel on an existing distro that lacks
 
akpm's system if he boots a new kernel on an existing distro that lacks
new policy.
+
new policy.  This is generally handled via handle_unknown==allow or via policy capabilities.
  
</pre>
 
 
</p>
 
</p>

Revision as of 14:58, 5 October 2009

To develop patches for the kernel security subsystem, use git to clone the security-testing-2.6 tree, as described at: http://security.wiki.kernel.org/index.php/Kernel_Repository

To develop patches for the SELinux reference policy, use git to clone the refpolicy tree via git clone http://oss.tresys.com/git/refpolicy.git

To add a new class and/or permission to the SELinux kernel code:
New way (with dynamic class/perm discovery, scheduled for kernels >= 2.6.33):

  1. Edit security/selinux/include/classmap.h in the kernel tree and add your definition. This will define the class and/or permission for use in the kernel; the corresponding symbol definitions will be automatically generated during the kernel build. If not defined in the policy, then the class and/or permission will be handled in accordance with your policy's handle_unknown definition, which can be reject (refuse to load the policy), deny (deny the undefined class/permission), or allow (allow the undefined class/permission).
  2. Edit refpolicy/policy/flask/security_classes and/or access_vectors in the refpolicy tree and add your definition. This will define the class and permission for use in the policy. You generally need to add the class and/or permission at the end of the existing list of classes or permissions for that class for backward compatibility with older kernels. The class and/or permission definition in policy need not line up with the definition in the kernel's classmap, as the values will be dynamically mapped by the kernel. Then add allow rules as appropriate to the policy for the new permissions.

Old way (for kernel < 2.6.33):

  1. Edit refpolicy/policy/flask/security_classes and/or access_vectors and add your definitions, typically at the end of the existing lists.
  2. make LINUX_D=/path/to/linux-2.6 tokern
    This will generate header files containing the symbolic definitions for the classes and/or permissions and copy them into the kernel tree located at /path/to/linux-2.6. The class and/or permission definition in the policy must line up with the definitions used in the kernel.

There is also the backward compatibility issue - we must not break akpm's system if he boots a new kernel on an existing distro that lacks new policy. This is generally handled via handle_unknown==allow or via policy capabilities.