---
name: "security_compute_av"
section: "3"
platform: "linux"
package: "libselinux1-dev"
version: "3.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/security_compute_av/3"
---

# security\_compute\_av(3)

query the SELinux policy database in the kernel

## NAME

security\_compute\_av, security\_compute\_av\_flags, security\_compute\_create, security\_compute\_create\_name, security\_compute\_relabel, security\_compute\_member, security\_compute\_user, security\_validatetrans, security\_get\_initial\_context - query the SELinux policy database in the kernel

## SYNOPSIS

**#include \<selinux/selinux.h\>**

**int security\_compute\_av(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, access\_vector\_t** *requested***, struct av\_decision \****avd***);**

**int security\_compute\_av\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, access\_vector\_t** *requested***, struct av\_decision \****avd***);**

**int security\_compute\_av\_flags(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, access\_vector\_t** *requested***, struct av\_decision \****avd***);**

**int security\_compute\_av\_flags\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, access\_vector\_t** *requested***, struct av\_decision \****avd***);**

**int security\_compute\_create(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_create\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_create\_name(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, const char \****objname***, char \*\****newcon***);**

**int security\_compute\_create\_name\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, const char \****objname***, char \*\****newcon***);**

**int security\_compute\_relabel(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_relabel\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_member(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_member\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, char \*\****newcon***);**

**int security\_compute\_user(const char \****scon***, const char \****username***, char \*\*\****con***);**

**int security\_compute\_user\_raw(const char \****scon***, const char \****username***, char \*\*\****con***);**

**int security\_validatetrans(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, const char \****newcon***);**

**int security\_validatetrans\_raw(const char \****scon***, const char \****tcon***, security\_class\_t** *tclass***, const char \****newcon***);**

**int security\_get\_initial\_context(const char \****name***, char \*\****con***);**

**int security\_get\_initial\_context\_raw(const char \****name***, char \*\****con***);**

**int selinux\_check\_access(const char \****scon***, const char \****tcon***, const char \****class***, const char \****perm***, void \****auditdata);*

**int selinux\_check\_passwd\_access(access\_vector\_t** *requested***);**

**int checkPasswdAccess(access\_vector\_t** *requested***);**

## DESCRIPTION

This family of functions is used to obtain policy decisions from the SELinux kernel security server (policy engine).  In general, direct use of **security\_compute\_av**() and its variant interfaces is discouraged in favor of using **selinux\_check\_access**() since the latter automatically handles the dynamic mapping of class and permission names to their policy values, initialization and use of the Access Vector Cache (AVC), and proper handling of per-domain and global permissive mode and allow\_unknown.

When using any of the functions that take policy integer values for classes or permissions as inputs, use **[string\_to\_security\_class(3)](/string_to_security_class/3.md)** and **[string\_to\_av\_perm(3)](/string_to_av_perm/3.md)** to map the class and permission names to their policy values. These values may change across a policy reload, so they should be re-acquired on every use or using a **SELINUX\_CB\_POLICYLOAD** callback set via **[selinux\_set\_callback(3)](/selinux_set_callback/3.md).**

An alternative approach is to use **[selinux\_set\_mapping(3)](/selinux_set_mapping/3.md)** to create a mapping from class and permission index values used by the application to the policy values, thereby allowing the application to pass its own fixed constants for the classes and permissions to these functions and internally mapping them on demand. However, this also requires setting up a callback as above to address policy reloads.

**security\_compute\_av**() queries whether the policy permits the source context *scon* to access the target context *tcon* via class *tclass* with the *requested* access vector.  The decision is returned in *avd*.

**security\_compute\_av\_flags**() is identical to **security\_compute\_av** but additionally sets the *flags* field of *avd*. Currently one flag is supported: **SELINUX\_AVD\_FLAGS\_PERMISSIVE**, which indicates the decision is computed on a permissive domain.

**security\_compute\_create**() is used to compute a context to use for labeling a new object in a particular class based on a SID pair.

**security\_compute\_create\_name**() is identical to **security\_compute\_create**() but also takes name of the new object in creation as an argument. When **TYPE\_TRANSITION** rule on the given class and a SID pair has object name extension, we shall be able to obtain a correct *newcon* according to the security policy. Note that this interface is only supported on the linux 2.6.40 or later. In the older kernel, the object name will be simply ignored.

**security\_compute\_relabel**() is used to compute the new context to use when relabeling an object, it is used in the pam\_selinux.so source and the newrole source to determine the correct label for the tty at login time, but can be used for other things.

**security\_compute\_member**() is used to compute the context to use when labeling a polyinstantiated object instance.

**security\_compute\_user**() is used to determine the set of user contexts that can be reached from a source context. This function is deprecated; use [**get\_ordered\_context\_list**(3)](/get_ordered_context_list/3.md) instead.

**security\_validatetrans**() is used to determine if a transition from scon to newcon using tcon as the object is valid for object class tclass. This checks against the mlsvalidatetrans and validatetrans constraints in the loaded policy. Returns 0 if allowed, and -1 if an error occurred with errno set.

**security\_get\_initial\_context**() is used to get the context of a kernel initial security identifier specified by  *name*

**security\_compute\_av\_raw**(), **security\_compute\_av\_flags\_raw**(), **security\_compute\_create\_raw**(), **security\_compute\_create\_name\_raw**(), **security\_compute\_relabel\_raw**(), **security\_compute\_member\_raw**(), **security\_compute\_user\_raw**() **security\_validatetrans\_raw**() and **security\_get\_initial\_context\_raw**() behave identically to their non-raw counterparts but do not perform context translation.

**selinux\_check\_access**() is used to check if the source context has the access permission for the specified class on the target context.

**selinux\_check\_passwd\_access**() is used to check for a permission in the *passwd* class. **selinux\_check\_passwd\_access**() uses **[getprevcon(3)](/getprevcon/3.md)** for the source and target security contexts.

**checkPasswdAccess**() is a deprecated alias of the **selinux\_check\_passwd\_access**() function.

## RETURN VALUE

Returns zero on success or -1 on error.

## SEE ALSO

[**string\_to\_security\_class**(3)](/string_to_security_class/3.md), [**string\_to\_av\_perm**(3)](/string_to_av_perm/3.md), [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md), [**selinux\_set\_mapping**(3)](/selinux_set_mapping/3.md), [**getprevcon**(3)](/getprevcon/3.md), [**get\_ordered\_context\_list**(3)](/get_ordered_context_list/3.md), [**selinux**(8)](/selinux/8.md)
