---
name: "selabel_x"
section: "5"
platform: "linux"
package: "selinux-utils"
version: "3.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/selabel_x"
---

# selabel\_x(5)

userspace SELinux labeling interface and configuration file format for the X Window System contexts backend. This backend is also used to determine the default context for labeling remotely connected X clients

## NAME

selabel\_x - userspace SELinux labeling interface and configuration file format for the X Window System contexts backend. This backend is also used to determine the default context for labeling remotely connected X clients

## SYNOPSIS

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

**int selabel\_lookup(struct selabel\_handle \****hnd***,** **char \*\****context***,**\
 **const char \****object\_name***, int** *object\_type***);**

**int selabel\_lookup\_raw(struct selabel\_handle \****hnd***,** **char \*\****context***,**\
 **const char \****object\_name***, int** *object\_type***);**

## DESCRIPTION

The X contexts backend maps from X Window System object names into security contexts. It is used to find the appropriate context for X Window System objects whose significance and/or usage semantics are determined primarily by name. The returned *context* must be freed using [**freecon**(3)](/freecon/3.md).\
 [**selabel\_lookup**(3)](/selabel_lookup/3.md) describes the function with its return and error codes.

This backend is also used to determine the default context for labeling remotely connected X clients.

The *object\_type* argument should be set to one of the following values:

- **SELABEL\_X\_PROP**

  The *object\_name* argument specifies the name of a window property, such as "WM\_NAME".

- **SELABEL\_X\_SELN**

  The *object\_name* argument specifies the name of a selection, such as "PRIMARY".

- **SELABEL\_X\_EXT**

  The *object\_name* argument specifies the name of a protocol extension, such as "RENDER".

- **SELABEL\_X\_EVENT**

  The *object\_name* argument specifies the name of an event type, such as "X11:ButtonPress".

- **SELABEL\_X\_CLIENT**

  The *object\_name* argument is ignored, however it should be set to either *\** (an asterisk or 'wildcard' that will select the default entry) or a specific entry such as "remote" in the X contexts file as shown in the **EXAMPLE** section. The default context for labeling remote X clients is then returned.

- **SELABEL\_X\_POLYPROP**

  Like **SELABEL\_X\_PROP**, but checks if the property was marked as being polyinstantiated. See **NOTES** below.

- **SELABEL\_X\_POLYSELN**

  Like **SELABEL\_X\_SELN**, but checks if the selection was marked as being polyinstantiated. See **NOTES** below.

Any messages generated by [**selabel\_lookup**(3)](/selabel_lookup/3.md) are sent to *stderr* by default, although this can be changed by [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md).

**selabel\_lookup\_raw** behaves identically to **selabel\_lookup** but does not perform context translation.

The **FILES** section details the configuration files used to determine the X object context.

## OPTIONS

In addition to the global options described in [**selabel\_open**(3)](/selabel_open/3.md), this backend recognizes the following options:

- **SELABEL\_OPT\_PATH**

  A non-null value for this option specifies a path to a file that will be opened in lieu of the standard X contexts file (see the **FILES** section for details).

## FILES

The X context file used to retrieve a default context depends on the **SELABEL\_OPT\_PATH** parameter passed to [**selabel\_open**(3)](/selabel_open/3.md). If *NULL*, then the **SELABEL\_OPT\_PATH** value will default to the active policy X contexts location (as returned by [**selinux\_x\_context\_path**(3)](/selinux_x_context_path/3.md)), otherwise the actual **SELABEL\_OPT\_PATH** value specified is used.

The default X object contexts file is:

*/etc/selinux/{SELINUXTYPE}/contexts/x\_contexts*

Where *{SELINUXTYPE}* is the entry from the selinux configuration file *config* (see [**selinux\_config**(5)](/selinux_config/5.md)).

The entries within the X contexts file are shown in the **Object Name String Values** and **FILE FORMAT** sections.

## Object Name String Values

The string name assigned to each *object\_type* argument that can be present in the X contexts file are:

| | |
| --- | --- |
| *object\_type* | **Text Name** |
| **SELABEL\_X\_PROP** | property |
| **SELABEL\_X\_SELN** | selection |
| **SELABEL\_X\_EXT** | extension |
| **SELABEL\_X\_EVENT** | event |
| **SELABEL\_X\_CLIENT** | client |
| **SELABEL\_X\_POLYPROP** | poly\_property |
| **SELABEL\_X\_POLYSELN** | poly\_selection |

## FILE FORMAT

Each line within the X contexts file is as follows:

*object\_type object\_name context*

Where:

*object\_type*

This is the string representation of the object type shown in the **Object Name String Values** section. There can be multiple lines with the same *object\_type* string that will form a block of entries (each with a different *object\_name* entry).

*object\_name*

These are the object names of the specific X-server resource such as **PRIMARY**, **CUT\_BUFFER0** etc. They are generally defined in the X-server source code (*protocol.txt* and *BuiltInAtoms* in the dix directory of the xorg-server source package). The entry can contain '\*' for wildcard matching or '?' for substitution. Note that if the '\*' is used, then be aware that the order of entries in the file is important. The '\*' on its own is used to ensure a default fallback context is assigned and should be the last entry in the *object\_type* block.

*context*

The security context that will be applied to the object.

Example 1:

```
# object_type  object_name  context
selection      PRIMARY      system_u:object_r:clipboard_xselection_t:s0
selection      *            system_u:object_r:xselection_t:s0
```

Example 2 - This example shows how a client entry can be configured to ensure an entry is always found:

```
# object_type  object_name  context
client         *            system_u:object_r:remote_t:s0
```

## NOTES

- 1\.

  Properties and selections are marked as either polyinstantiated or not. For these name types, the "POLY" option searches only the names marked as being polyinstantiated, while the other option searches only the names marked as not being polyinstantiated. Users of the interface should check both mappings, optionally taking action based on the result (e.g. polyinstantiating the object).

- 2\.

  If contexts are to be validated, then the global option **SELABEL\_OPT\_VALIDATE** must be set before calling [**selabel\_open**(3)](/selabel_open/3.md). If this is not set, then it is possible for an invalid context to be returned.

## SEE ALSO

[**selinux**(8)](/selinux/8.md), [**selabel\_open**(3)](/selabel_open/3.md), [**selabel\_lookup**(3)](/selabel_lookup/3.md), [**selabel\_stats**(3)](/selabel_stats/3.md), [**selabel\_close**(3)](/selabel_close/3.md), [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md), [**selinux\_x\_context\_path**(3)](/selinux_x_context_path/3.md), [**freecon**(3)](/freecon/3.md), [**selinux\_config**(5)](/selinux_config/5.md)
