Reader small image

You're reading from  SELinux Cookbook

Product typeBook
Published inSep 2014
Publisher
ISBN-139781783989669
Edition1st Edition
Right arrow
Author (1)
Sven Vermeulen
Sven Vermeulen
author image
Sven Vermeulen

Sven Vermeulen (sjvermeu on Twitter) is a long-term contributor to various free software projects and the author of several online guides and resources, including the Gentoo Handbook. He got his first taste of free software in 1997 and never looked back. Within SELinux, Sven contributed several policies to the Reference Policy project, and actively participated in policy development and user space development projects. In his daily job, Sven is an enterprise architect in a European financial institution as well as a self-employed solution engineer and consultant. Prior to this, he graduated with an MSE in computer engineering from Ghent University and an MSc in ICT enterprise architecture from IC Institute.
Read more about Sven Vermeulen

Right arrow

Interrogating the SELinux subsystem code-wise


In order to query the SELinux policy, we have seen the use of the sesearch command and other SELinux utilities. Code-wise, SELinux policies can be queried using the security_compute_av_flags method.

Getting ready

The curcon and newcon variables can be filled in through methods such as getcon() (for the current context) or get_default_context() as we have seen in the previous recipe.

How to do it…

As an example, we want to query the transition permission between two process domains. To accomplish this, the following method is used:

  1. First of all, call the security_compute_av_flags() method:

    struct av_decision avd;
    rc = security_compute_av_flags(curcon, newcon, SECCLASS_PROCESS, PROCESS__TRANSITION, &avd);
    if (rc) {
      … // Method failed.
      freecon(curcon);
      freecon(newcon);
    };
  2. Now read the response:

    if (!(avd.allowed & PROCESS__TRANSITION)) {
      … // Transition is denied
    };
  3. Check whether the current context is a permissive domain or not:

    if (avd.flags...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
SELinux Cookbook
Published in: Sep 2014Publisher: ISBN-13: 9781783989669

Author (1)

author image
Sven Vermeulen

Sven Vermeulen (sjvermeu on Twitter) is a long-term contributor to various free software projects and the author of several online guides and resources, including the Gentoo Handbook. He got his first taste of free software in 1997 and never looked back. Within SELinux, Sven contributed several policies to the Reference Policy project, and actively participated in policy development and user space development projects. In his daily job, Sven is an enterprise architect in a European financial institution as well as a self-employed solution engineer and consultant. Prior to this, he graduated with an MSE in computer engineering from Ghent University and an MSc in ICT enterprise architecture from IC Institute.
Read more about Sven Vermeulen