| 1 |
.\" Copyright 2016, Michael Kerrisk <[email protected]> |
| 2 |
.\" Copyright 2016, Eugene Syromyatnikov <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH KEYCTL_GET_SECURITY 2const 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
KEYCTL_GET_SECURITY |
| 10 |
\- |
| 11 |
manipulate the kernel's key management facility |
| 12 |
.SH LIBRARY |
| 13 |
Standard C library |
| 14 |
.RI ( libc ,\~ \-lc ) |
| 15 |
.SH SYNOPSIS |
| 16 |
.nf |
| 17 |
.BR "#include <linux/keyctl.h>" " /* Definition of " KEY* " constants */" |
| 18 |
.BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */" |
| 19 |
.B #include <unistd.h> |
| 20 |
.P |
| 21 |
.BR "long syscall(" "size_t n;" |
| 22 |
.BI " SYS_keyctl, KEYCTL_GET_SECURITY, key_serial_t " key , |
| 23 |
.BI " char " buf "[_Nullable " n "], size_t " n ); |
| 24 |
.fi |
| 25 |
.SH DESCRIPTION |
| 26 |
.TP |
| 27 |
.BR KEYCTL_GET_SECURITY " (since Linux 2.6.26)" |
| 28 |
.\" commit 70a5bb72b55e82fbfbf1e22cae6975fac58a1e2d |
| 29 |
Get the LSM (Linux Security Module) security label of the specified key. |
| 30 |
.P |
| 31 |
The ID of the key whose security label is to be fetched is specified in |
| 32 |
.IR key . |
| 33 |
The security label (terminated by a null byte) |
| 34 |
will be placed in the buffer pointed to by |
| 35 |
.I buf |
| 36 |
argument; |
| 37 |
the size of the buffer must be provided in |
| 38 |
.IR n . |
| 39 |
.P |
| 40 |
If |
| 41 |
.I buf |
| 42 |
is specified as NULL or the buffer size specified in |
| 43 |
.I n |
| 44 |
is too small, the full size of the security label string |
| 45 |
(including the terminating null byte) |
| 46 |
is returned as the function result, |
| 47 |
and nothing is copied to the buffer. |
| 48 |
.P |
| 49 |
The caller must have |
| 50 |
.I view |
| 51 |
permission on the specified key. |
| 52 |
.P |
| 53 |
The returned security label string will be rendered in a form appropriate |
| 54 |
to the LSM in force. |
| 55 |
For example, with SELinux, it may look like: |
| 56 |
.P |
| 57 |
.in +4n |
| 58 |
.EX |
| 59 |
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 |
| 60 |
.EE |
| 61 |
.in |
| 62 |
.P |
| 63 |
If no LSM is currently in force, |
| 64 |
then an empty string is placed in the buffer. |
| 65 |
.SH RETURN VALUE |
| 66 |
On success, |
| 67 |
the size of the LSM security label string |
| 68 |
(including the terminating null byte), |
| 69 |
irrespective of the provided buffer size. |
| 70 |
.P |
| 71 |
On error, \-1 is returned, and |
| 72 |
.I errno |
| 73 |
is set to indicate the error. |
| 74 |
.SH VERSIONS |
| 75 |
A wrapper is provided in the |
| 76 |
.I libkeyutils |
| 77 |
library: |
| 78 |
.BR keyctl_get_security (3). |
| 79 |
.SH STANDARDS |
| 80 |
Linux. |
| 81 |
.SH HISTORY |
| 82 |
Linux 2.6.26. |
| 83 |
.SH SEE ALSO |
| 84 |
.BR keyctl (2), |
| 85 |
.BR keyctl_get_security (3), |
| 86 |
.BR keyctl_get_security_alloc (3) |