KEYCTL_GET_SECURITY(3)
β¨ KEYCTL_GET_SECURITY(3) β¨
okay bestie, welcome to the Linux Key Management Calls corner of the man pages π this one is KEYCTL_GET_SECURITY and she's here to spill the tea on a key's security context. no cap.
π NAME
keyctl_get_security β pull up a key's security context, fr fr
π SYNOPSIS
#include <keyutils.h>
long keyctl_get_security(key_serial_t key, char *buffer,
size_t buflen);
long keyctl_get_security_alloc(key_serial_t key, char **_buffer);
π¦ DESCRIPTION
so keyctl_get_security() retrieves the security context of a key, and she gives it to you as a NUL-terminated string β¨ it's rendered in whatever form is appropriate to the LSM that's currently in force β like, if you're running SELinux it may look like this:
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
and honestly? iconic. no notes.
heads up though β the caller must have view permission on a key to be able to get its security context. no view permission, no security context. that's the vibe check and you did not pass it π
okay so buffer and buflen specify the buffer into which the string will be placed π«Ά but if that buffer is too small, the full size of the string gets returned anyway, and no copy will take place β so basically she tells you how much room she needs and then just stands there π
then we have keyctl_get_security_alloc(), which is similar to keyctl_get_security() except that it allocates a buffer big enough to hold the string and copies the string into it πΈ she's the main character who handles the logistics for you. if successful, a pointer to the buffer is placed in *_buffer. and bestie, listen β the caller must free the buffer. that's your responsibility, not hers π
π RETURN VALUE
on success, keyctl_get_security() returns the amount of data placed into the buffer β¨ if the buffer was too small, then the size of buffer required will be returned, but no data will be transferred. on error, the value -1 will be returned and errno will have been set to an appropriate error π
on success, keyctl_get_security_alloc() returns the amount of data in the buffer, less the NUL terminator (she's not counting that little guy). on error, the value -1 will be returned and errno will have been set to an appropriate error π
π ERRORS
ENOKEYβ the key specified is invalid. not a real key, not invited to the function π«EKEYEXPIREDβ the key specified has expired. she had her moment, it's over now β°EKEYREVOKEDβ the key specified had been revoked. the key said "we're done here" πEACCESβ the key exists, but is not viewable by the calling process. she's real, you just can't look at her π
π LINKING
this is a library function that can be found in libkeyutils π§ when linking, -lkeyutils should be specified to the linker. don't forget it or she will simply not show up, periodt.
π SEE ALSO
keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3), keyrings(7), keyutils(7)
and that's the whole page, bestie π this one's from the Linux crew, dated 26 Feb 2010 β old but she ate, and honestly? still serving. go get your security contexts, iykyk πβ¨
π¦ where this page comes from
- alpine 3.22: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.23: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.24: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- arch rolling: keyutils 1.6.3-4 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 10: keyutils-libs-devel 1.6.3-5.el10 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- debian bookworm: libkeyutils-dev 1.6.3-2 Β· GPL-2.0-or-later
- debian trixie: libkeyutils-dev 1.6.3-6 Β· GPL-2.0-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- nixpkgs unstable: keyutils 1.6.3
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- ubuntu jammy: libkeyutils-dev 1.6.1-2ubuntu3 Β· GPL-2.0-or-later
- ubuntu noble: libkeyutils-dev 1.6.3-3build1 Β· GPL-2.0-or-later
- ubuntu questing: libkeyutils-dev 1.6.3-6ubuntu2
- ubuntu resolute: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- ubuntu stonking: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- Copyright (C) 2010 Red Hat, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms