AA_GETCON(2)

πŸ’… AA_GETCON(2) β€” the AppArmor family πŸ’…

okay so bestie, this is the whole AppArmor "get confinement" squad, all in one page. it's AA_GETCON(2) from the AppArmor manual, and it's lowkey the most useful thing ever if you want to know what profile a task is living under. let's go 🫢


✨ NAME ✨

aa_getprocattr_raw, aa_getprocattr β€” read and parse procattr data πŸ“–

aa_getcon, aa_gettaskcon β€” get task confinement information πŸ•΅οΈβ€β™€οΈ

aa_getpeercon β€” get the confinement of a socket's other end (peer) πŸ”Œ


🌸 SYNOPSIS 🌸

#include <sys/apparmor.h>

int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
char **mode);

int aa_getprocattr(pid_t tid, const char *attr, char **label, char
**mode);

int aa_gettaskcon(pid_t target, char **label, char **mode);

int aa_getcon(char **label, char **mode);

int aa_getpeercon_raw(int fd, char *buf, int *len, char **mode);

int aa_getpeercon(int fd, char **label, char **mode);

and when you compile, you gotta link with -lapparmor β€” no cap, don't forget her πŸ”—


πŸ¦‹ DESCRIPTION πŸ¦‹

so aa_getcon gets the current AppArmor confinement context for the current task. it's giving main character energy: it just looks at itself. ✨

the confinement context is two things: a label and a mode.

  • the label is usually just the name of the AppArmor profile restricting the task β€” but bestie, it can also include the profile namespace, or in some cases a whole set of profile names (that's called a stack of profiles πŸ‘‘).
  • the mode is a string describing how the kernel is enforcing the policy defined in the profile.

how do the modes work? glad you asked πŸ’…

  • profiles loaded in "enforce" mode will result in enforcement of the policy defined in the profile, and they report policy violation attempts.
  • profiles in "complain" mode will not enforce policy β€” they just report policy violation attempts. it's the "I'm just gonna tell you about it" era.

some examples of possible returned *label strings are "unconfined", "/sbin/dhclient", and "Firefox". the string can consist of any non-NUL characters, but it will be NUL-terminated. the *label string must be freed using free(). 🧹

the possible *mode strings are "enforce" and "complain". additionally, *mode may be NULL when *label is "unconfined". the *mode string must not be freed β€” hands off, she's not yours πŸ™ˆ. the *label and *mode strings come from a single buffer allocation and are separated by a NUL character.

aa_gettaskcon is like aa_getcon, except it will work for any arbitrary task in the system. so you can peek at literally anyone. respect. 🌈
aa_getpeercon is similar to aa_gettaskcon, except that it returns the confinement information for the task on the other end of a socket connection. it's giving "who even are you" energy. πŸ”Œ
aa_getpeercon_raw is the backend for aa_getpeercon and does not handle buffer allocation. you're on your own for the buffer, bestie πŸ’€
aa_getprocattr is the backend for aa_getcon and aa_gettaskcon. it handles the reading and parsing of the confinement data from different arbitrary attr files, and returns the processed results in an allocated buffer. she does all the work fr fr πŸŽ€
aa_getprocattr_raw() is the backend for aa_getprocattr and does not handle buffer allocation. again: your buffer, your problem. πŸ™ˆ

⭐ RETURN VALUE ⭐

on success, the size of data placed in the buffer is returned β€” and yes, that includes the mode if present, plus any terminating characters. πŸŽ‰

on error, -1 is returned, and errno(3) is set appropriately. it's giving "something went wrong and here's the receipt." 😭


πŸ”₯ ERRORS πŸ”₯

  • EINVAL β€” the apparmor kernel module is not loaded, or the communication via the /proc/*/attr/file did not conform to protocol. 🚫
  • ENOMEM β€” insufficient kernel memory was available. she's out of room πŸ’€
  • EACCES β€” access to the specified file/task was denied. no entry, bestie πŸšͺ
  • ENOENT β€” the specified file/task does not exist or is not visible. she's not even there πŸ‘»
  • ERANGE β€” the confinement data is too large to fit in the supplied buffer. your buffer is too small, it's giving snack-size πŸ“
  • ENOPROTOOPT β€” the kernel doesn't support the SO_PEERLABEL option in sockets. this happens mainly when the kernel lacks 'fine grained unix mediation' support. it also can happen on LSM stacking kernels where another LSM has claimed this interface and decides to return this error β€” although this is really a corner case. 🫠

🧚 NOTES 🧚

if aa_getpeercon_raw returns -1 and errno is ERANGE, the value of *len can be used to reallocate buf so that it is sufficiently large enough to store the confinement data. so like… she told you how big she needs to be. use that info. πŸ’‘


πŸ’œ BUGS πŸ’œ

none known. if you find any, please report them at <https://gitlab.com/apparmor/apparmor/-/issues>. do it for the girls 🫢 (ngl, if you find one, you're kinda iconic for it πŸ‘‘)


πŸŽ€ SEE ALSO πŸŽ€

apparmor(7), apparmor.d(5), apparmor_parser(8), aa_change_profile(2), aa_splitcon(3) and <https://wiki.apparmor.net>. go read them, iykyk πŸ“šβœ¨


and that's the whole vibe, bestie β€” this page is from AppArmor 4.1.8, dated 2026-10-18. slay, go get yourself some confinement info πŸ’…πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: apparmor 4.1.8-2 Β· GPL-2.0-only AND LGPL-2.0-only AND LGPL-2.1-only
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms