seccomp_attr_set(3)
π seccomp_attr_set(3) β libseccomp Documentation π
okay bestie, pull up a chair because we're talking about seccomp_attr_set and seccomp_attr_get from libseccomp, and honestly? they're the little knobs that control how your whole seccomp filter behaves. no cap.
β¨ NAME β¨
seccomp_attr_set, seccomp_attr_get β manage the seccomp filter attributes π
β¨ SYNOPSIS β¨
#include <seccomp.h>
typedef void * scmp_filter_ctx;
enum scmp_filter_attr;
int seccomp_attr_set(scmp_filter_ctx ctx,
enum scmp_filter_attr attr, uint32_t value);
int seccomp_attr_get(scmp_filter_ctx ctx,
enum scmp_filter_attr attr, uint32_t *value);
Link with -lseccomp.
β¨ DESCRIPTION β¨
so basically, seccomp_attr_set() sets the different seccomp filter attributes, and seccomp_attr_get() fetches them. these attributes are tunable values that affect how the library behaves when it's generating and loading the seccomp filter into the kernel. π
and here's the thing β the attributes get reset to their default values whenever the filter is initialized or reset via seccomp_init(3) or seccomp_reset(3). so don't come crying to me when your settings vanish, bestie, that's just the vibe. π
the filter context ctx is the value returned by the call to seccomp_init(3).
valid attr values are as follows, and yes we're going through all of them:
SCMP_FLTATR_ACT_DEFAULTβ the default filter action as specified in the call toseccomp_init(3)orseccomp_reset(3). this attribute is read-only. πSCMP_FLTATR_ACT_BADARCHβ the filter action taken when the loaded filter does not match the architecture of the executing application. defaults to theSCMP_ACT_KILLaction. πSCMP_FLTATR_CTL_NNPβ a flag to specify if theNO_NEW_PRIVSfunctionality should be enabled before loading the seccomp filter into the kernel. setting this to off (value == 0) results in no action, meaning that loading the seccomp filter into the kernel will fail ifCAP_SYS_ADMINis missing andNO_NEW_PRIVShas not been externally set. defaults to on (value == 1).SCMP_FLTATR_CTL_TSYNCβ a flag to specify if the kernel should attempt to synchronize the filters across all threads onseccomp_load(3). if the kernel is unable to synchronize all of the thread then the load operation will fail. this flag is only available on Linux Kernel 3.17 or greater; attempting to enable this flag on earlier kernels will result in an error being returned. defaults to off (value == 0).SCMP_FLTATR_API_TSKIPβ a flag to specify if libseccomp should allow filter rules to be created for the-1syscall. the-1syscall value can be used by tracer programs to skip specific syscall invocations, seeseccomp(2)for more information. defaults to off (value == 0).SCMP_FLTATR_CTL_LOGβ a flag to specify if the kernel should log all filter actions taken except for theSCMP_ACT_ALLOWaction. defaults to off (value == 0).SCMP_FLTATR_CTL_SSBβ a flag to disable Speculative Store Bypass mitigations for this filter. defaults to off (value == 0).SCMP_FLTATR_CTL_OPTIMIZEβ a flag to specify the optimization level of the seccomp filter. by default libseccomp generates a set of sequentialifstatements for each rule in the filter.seccomp_syscall_priority(3)can be used to prioritize the order for the default cause. the binary tree optimization sorts by syscall numbers and generates consistentO(log n)filter traversal for every rule in the filter. the binary tree may be advantageous for large filters. note thatseccomp_syscall_priority(3)is ignored whenSCMP_FLTATR_CTL_OPTIMIZE == 2. π
the different optimization levels are described below:
0β Reserved value, not currently used.1β Rules sorted by priority and complexity (DEFAULT).2β Binary tree sorted by syscall number.
SCMP_FLTATR_API_SYSRAWRCβ a flag to specify if libseccomp should pass system error codes back to the caller instead of the default-ECANCELED. defaults to off (value == 0).SCMP_FLTATR_CTL_WAITKILLβ a flag to specify if libseccomp should request wait killable semantics when possible. defaults to off (value == 0).
β¨ RETURN VALUE β¨
returns zero on success, or one of the following error codes on failure:
-EACCESβ Setting the attribute with the given value is not allowed.-EEXISTβ The attribute does not exist.-EINVALβ Invalid input, either the context or architecture token is invalid.-EOPNOTSUPPβ The library doesn't support the particular operation.
β¨ EXAMPLES β¨
here's the moment you've been waiting for, a whole little program:
#include <seccomp.h>
int main(int argc, char *argv[])
{
int rc = -1;
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_ALLOW);
if (ctx == NULL)
goto out;
/* ... */
rc = seccomp_attr_set(ctx, SCMP_FLTATR_ACT_BADARCH, SCMP_ACT_TRAP);
if (rc < 0)
goto out;
/* ... */
out:
seccomp_release(ctx);
return -rc;
}
β¨ NOTES β¨
while the seccomp filter can be generated independent of the kernel, kernel support is required to load and enforce the seccomp filter generated by libseccomp. so like, you can build the thing all you want, but the kernel has to be in on the plan. π«Ά
the libseccomp project site, with more information and the source code repository, can be found at https://github.com/seccomp/libseccomp. this tool, as well as the libseccomp library, is currently under development, please report any bugs at the project site or directly to the author. π
β¨ AUTHOR β¨
Paul Moore <paul@paul-moore.com>
β¨ SEE ALSO β¨
seccomp_init(3), seccomp_reset(3), seccomp_load(3), seccomp(2)
and that's the whole page, bestie π β brought to you by Paul Moore <paul@paul-moore.com>, dated 21 September 2022, and living in the libseccomp Documentation for seccomp_attr_set(3). now go set some attributes and slay β¨π
πΈ
π¦ where this page comes from
- alpine 3.22: libseccomp-doc 2.6.1-r0 Β· LGPL-2.1-or-later
- alpine 3.23: libseccomp-doc 2.6.1-r0 Β· LGPL-2.1-or-later
- alpine 3.24: libseccomp-doc 2.6.1-r0 Β· LGPL-2.1-or-later
- arch rolling: libseccomp 2.6.0-1 Β· LGPL-2.1-only
- debian trixie: libseccomp-dev 2.6.0-2 Β· LGPL-2.1-only
- fedora 43: libseccomp-devel 2.6.0-2.fc43 Β· LGPL-2.1-only
- fedora 43: libseccomp-devel 2.6.0-2.fc43 Β· LGPL-2.1-only
- fedora 43: libseccomp-devel 2.6.1-2.fc43 Β· LGPL-2.1-only
- fedora 43: libseccomp-devel 2.6.1-2.fc43 Β· LGPL-2.1-only
- fedora 44: libseccomp-devel 2.6.0-3.fc44 Β· LGPL-2.1-only
- fedora 44: libseccomp-devel 2.6.0-3.fc44 Β· LGPL-2.1-only
- fedora 44: libseccomp-devel 2.6.1-2.fc44 Β· LGPL-2.1-only
- fedora 44: libseccomp-devel 2.6.1-2.fc44 Β· LGPL-2.1-only
- nixpkgs unstable: libseccomp 2.6.1
- opensuse-leap 16.0: libseccomp-devel 2.6.0-160000.2.2 Β· LGPL-2.1-only
- opensuse-leap 16.0: libseccomp-devel 2.6.0-160000.2.2 Β· LGPL-2.1-only
- opensuse-leap 16.0: libseccomp-devel 2.6.0-160000.2.2 Β· LGPL-2.1-only
- opensuse-leap 16.0: libseccomp-devel 2.6.0-160000.2.2 Β· LGPL-2.1-only
- ubuntu questing: libseccomp-dev 2.6.0-2ubuntu2
- ubuntu resolute: libseccomp-dev 2.6.0-2ubuntu5 Β· LGPL-2.1-only
- ubuntu stonking: libseccomp-dev 2.6.1-1ubuntu1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms