seccomp_export_bpf(3)
π seccomp_export_bpf β export the seccomp filter π
okay bestie, welcome to the libseccomp Documentation page for seccomp_export_bpf(3) β¨ this is the one where we take your filter and actually ship it out the door πͺπ¨
πΈ NAME πΈ
seccomp_export_bpf, seccomp_export_pfc β Export the seccomp filter π«Ά
β¨ SYNOPSIS β¨
#include <seccomp.h>
typedef void * scmp_filter_ctx;
int seccomp_export_bpf(const scmp_filter_ctx ctx, int fd);
int seccomp_export_pfc(const scmp_filter_ctx ctx, int fd);
int seccomp_export_bpf_mem(const scmp_filter_ctx ctx, void *buf, size_t *len);
and don't forget to link it up, queen: -lseccomp π
π¦ DESCRIPTION π¦
so seccomp_export_bpf() and seccomp_export_pfc() are the duo that generates and outputs your current seccomp filter, and they do it in either BPF (Berkeley Packet Filter) or PFC (Pseudo Filter Code) π
- the output of
seccomp_export_bpf()is the one you can actually load into the kernel π like it's built for the real thing - the output of
seccomp_export_pfc()is human readable and is intended primarily as a debugging tool for developers using libseccomp π it's giving "let me read my own vibes back"
both of them write the filter to the fd file descriptor, no cap π―
the filter context ctx is the value returned by the call to seccomp_init(3) β that's where you got it from, that's the source, periodt π
while the two output formats are guaranteed to be functionally equivalent for the given seccomp filter configuration, the filter instructions, and their ordering, are not guaranteed to be the same in both the BPF and PFC formats. same energy, different font, iykyk π
now for the memory one β seccomp_export_bpf_mem() is largely the same as seccomp_export_bpf(), but instead of writing to a file descriptor, the program gets written to the buf pointer provided by the caller π
- the
lenargument must be initialized with the size of thebufbuffer - if the program was valid,
lenwill be updated with its size in bytes π - if
bufwas too small to hold the program,lencan be consulted to determine the required size - passing a
NULLbufmay also be used to query the required size ahead of time π very "let me measure first bestie"
π₯ RETURN VALUE π₯
return zero on success π or one of these error codes on failure:
-ECANCELEDβ there was a system failure beyond the control of the library π΅ like, not our fault, not your fault, just vibes being bad-EFAULTβ internal libseccomp failure π-EINVALβ invalid input, either the context or architecture token is invalid π«-ENOMEMβ the library was unable to allocate enough memory, she's broke π-ERANGEβ the provided buffer was too small π
if the SCMP_FLTATR_API_SYSRAWRC filter attribute is non-zero then additional error codes may be returned to the caller; these additional error codes are the negative errno values returned by the system. Unfortunately libseccomp can make no guarantees about these return values. so like... you're on your own for those ones bestie π
π EXAMPLES π
here's the whole moment, verbatim, slay:
#include <seccomp.h>
int main(int argc, char *argv[])
{
int rc = -1;
scmp_filter_ctx ctx;
int filter_fd;
ctx = seccomp_init(SCMP_ACT_KILL);
if (ctx == NULL)
goto out;
/* ... */
filter_fd = open("/tmp/seccomp_filter.bpf", O_WRONLY);
if (filter_fd == -1) {
rc = -errno;
goto out;
}
rc = seccomp_export_bpf(ctx, filter_fd);
if (rc < 0) {
close(filter_fd);
goto out;
}
close(filter_fd);
/* ... */
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 β οΈ like you can write the letter but you still need someone to deliver it, fr fr
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_release(3) β go read those next bestie, they're the prequel π«Ά
okay that's the whole page!! π big thanks to paul@paul-moore.com for writing it, and this version is from the 30 May 2020 era of libseccomp Documentation πΈ stay safe out there, keep your filters tight, and remember: functionally equivalent does NOT mean identical. mwah π
π¦ 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