seccomp_init(3)
β¨ seccomp_init β¨
okay bestie, welcome to the libseccomp manual, page seccomp_init(3) π this one is literally the start of everything, so pay attention, it's giving origin story π
πΈ NAME πΈ
seccomp_init, seccomp_reset β Initialise the seccomp filter state π§
π SYNOPSIS π
#include <seccomp.h>
typedef void * scmp_filter_ctx;
scmp_filter_ctx seccomp_init(uint32_t def_action);
int seccomp_reset(scmp_filter_ctx ctx, uint32_t def_action);
Link with -lseccomp.
π DESCRIPTION π
so the way that seccomp_init() and seccomp_reset() work is they (re)initialise the internal seccomp filter state, get it all prepped and ready for use, and set the default action based on the def_action parameter. no cap.
seccomp_init() must be called before any other libseccomp functions β like, the rest of the library API will straight up fail if the filter context isn't initialised properly. it's the vibe check everybody else has to pass first π
seccomp_reset() releases the existing filter context state before reinitialising it, and it can only be called after a call to seccomp_init() has succeeded. if you call seccomp_reset() with a NULL filter, it resets the library's global task state, including any notification file descriptors retrieved by seccomp_notify_fd(3). normally you don't need this, but it may be required to keep using the library after a fork() or clone() call, so the API level and user notification state get properly reset. iconic behaviour honestly.
when you're done configuring the seccomp filter and have loaded it into the kernel, you should call seccomp_release(3) to release all of the filter context state. clean up after yourself, bestie π«Ά
valid def_action values are as follows:
SCMP_ACT_KILLβ the thread gets terminated by the kernel withSIGSYSwhen it calls a syscall that doesn't match any of the configured seccomp filter rules. and no, the thread can't catch the signal. it's over πSCMP_ACT_KILL_PROCESSβ the entire process gets terminated by the kernel withSIGSYSwhen it calls a syscall that doesn't match any of the configured seccomp filter rules. whole squad gone.SCMP_ACT_TRAPβ the thread gets sent aSIGSYSsignal when it calls a syscall that doesn't match any of the configured seccomp filter rules. it may catch this and change its behaviour accordingly. when usingSA_SIGINFOwithsigaction(2),si_codewill be set toSYS_SECCOMP,si_syscallwill be set to the syscall that failed the rules, andsi_archwill be set to theAUDIT_ARCHfor the active ABI. so much intel, we love a signal with lore β¨SCMP_ACT_ERRNO(uint16_t errno)β the thread receives a return value oferrnowhen it calls a syscall that doesn't match any of the configured seccomp filter rules.SCMP_ACT_TRACE(uint16_t msg_num)β if the thread is being traced and the tracing process specified thePTRACE_O_TRACESECCOMPoption in the call toptrace(2), the tracing process gets notified, viaPTRACE_EVENT_SECCOMP, and the value provided inmsg_numcan be retrieved using thePTRACE_GETEVENTMSGoption. spy era πSCMP_ACT_LOGβ the seccomp filter will have no effect on the thread calling the syscall if it doesn't match any of the configured seccomp filter rules, but the syscall will be logged. it's just taking notes πSCMP_ACT_ALLOWβ the seccomp filter will have no effect on the thread calling the syscall if it doesn't match any of the configured seccomp filter rules. the chill one. the "we move" option π
β RETURN VALUE β
seccomp_init() returns a filter context on success, and NULL on failure. π
seccomp_reset() returns zero on success, or one of the following error codes on failure:
-EINVALβ invalid input, either the context or action is invalid.-ENOMEMβ the library was unable to allocate enough memory.
π¦ EXAMPLES π¦
#include <seccomp.h>
int main(int argc, char *argv[])
{
int rc = -1;
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_KILL);
if (ctx == NULL)
goto out;
/* ... */
rc = seccomp_reset(ctx, SCMP_ACT_KILL);
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 it without the kernel's blessing but you can't actually run it without it. main character needs a stage π€
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. we're all works in progress fr fr π«Ά
π AUTHOR π
Paul Moore <paul@paul-moore.com>
π₯ SEE ALSO π₯
that's the page, bestie!! π this one comes to you from the libseccomp Documentation, and it's dated 30 May 2020 β and the author's email <paul@paul-moore.com> is right there if you ever wanna say hi. go forth and initialise responsibly β¨ππ¦
π¦ 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
- centos-stream 10: libseccomp-devel 2.5.6-1.el10 Β· LGPL-2.1-only
- centos-stream 9: libseccomp-devel 2.5.6-1.el9 Β· LGPLv2
- centos-stream 9: libseccomp-devel 2.5.6-1.el9 Β· LGPLv2
- debian bookworm: libseccomp-dev 2.5.4-1+deb12u1 Β· 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 jammy: libseccomp-dev 2.5.3-2ubuntu2 Β· LGPL-2.1-only
- ubuntu jammy: libseccomp-dev 2.5.3-2ubuntu3~22.04.1 Β· LGPL-2.1-only
- ubuntu noble: libseccomp-dev 2.5.5-1ubuntu3 Β· LGPL-2.1-only
- ubuntu noble: libseccomp-dev 2.5.5-1ubuntu3.1 Β· 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