seccomp_merge(3)
π seccomp_merge(3) β the libseccomp glow-up π
okay bestie, welcome to the libseccomp Documentation corner of the group chat. today's main character is seccomp_merge, and no cap, it's lowkey one of the most satisfying little functions in the whole library. you got two filters, you want one filter? say less. π«Ά
β¨ NAME β¨
seccomp_merge β merge two seccomp filters together, slay
πΈ SYNOPSIS πΈ
#include <seccomp.h>
typedef void * scmp_filter_ctx;
int seccomp_merge(scmp_filter_ctx dst, scmp_filter_ctx src);
Link with -lseccomp.
π¦ DESCRIPTION π¦
so seccomp_merge() takes the seccomp filter living in src, smooshes it into the filter living in dst, and stores the result in dst. that's it, that's the whole vibe. β¨
and the glow-up? if it works, the src seccomp filter gets released and literally all the internal memory attached to it gets freed. so do not call seccomp_release(3) on src afterwards β that's already handled, bestie. also pls discard any references you were still holding to that filter, because it's gone gone. π
now for the fine print, because there's always fine print: to merge two seccomp filters, both filters must have the same attribute values and no overlapping architectures. that's the compatibility check. no overlap, same attrs, or it's not happening. π
π RETURN VALUE π
returns zero on success, or one of these error codes when it's not giving:
-EDOMβ couldn't merge because of architecture issues, like byte endian mismatches. the vibes were off. π-EEXISTβ that architecture already exists in the filter. it's already in the group chat, bestie.-EINVALβ one of the filters is invalid. π©-ENOMEMβ the library could not allocate enough memory. ran out of room, tragic.
π EXAMPLES π
here's the whole thing in action, copy it, love it, run it:
#include <seccomp.h>
int main(int argc, char *argv[])
{
int rc = -1;
scmp_filter_ctx ctx_32, ctx_64;
ctx_32 = seccomp_init(SCMP_ACT_KILL);
if (ctx_32 == NULL)
goto out_all;
ctx_64 = seccomp_init(SCMP_ACT_KILL);
if (ctx_64 == NULL)
goto out_all;
if (seccomp_arch_exist(ctx_32, SCMP_ARCH_X86) == -EEXIST) {
rc = seccomp_arch_add(ctx_32, SCMP_ARCH_X86);
if (rc != 0)
goto out_all;
rc = seccomp_arch_remove(ctx_32, SCMP_ARCH_NATIVE);
if (rc != 0)
goto out_all;
}
if (seccomp_arch_exist(ctx_64, SCMP_ARCH_X86_64) == -EEXIST) {
rc = seccomp_arch_add(ctx_64, SCMP_ARCH_X86_64);
if (rc != 0)
goto out_all;
rc = seccomp_arch_remove(ctx_64, SCMP_ARCH_NATIVE);
if (rc != 0)
goto out_all;
}
/* ... */
rc = seccomp_merge(ctx_64, ctx_32);
if (rc != 0)
goto out_all;
/* NOTE: the 'ctx_32' filter is no longer valid at this point */
/* ... */
out:
seccomp_release(ctx_64);
return -rc;
out_all:
seccomp_release(ctx_32);
goto out;
}
see that NOTE comment? read it again. once seccomp_merge succeeds, ctx_32 is no longer valid. not "kinda stale", not "use with caution" β invalid. π«
π NOTES π
ngl this part matters: while the seccomp filter can be generated independent of the kernel, kernel support is required to load and enforce the seccomp filter that libseccomp generates. so the filter existing β the filter being enforced. iykyk. π
the libseccomp project site β with more info and the source code repository β lives at https://github.com/seccomp/libseccomp. this tool, as well as the libseccomp library, is currently under development, so pls report any bugs at the project site or directly to the author. be a good citizen about it. π«Ά
π AUTHOR π
Paul Moore <paul@paul-moore.com> β the icon, the legend, the main character energy behind all of this.
π₯ SEE ALSO π₯
seccomp_init(3), seccomp_reset(3), seccomp_arch_add(3), seccomp_arch_remove(3), seccomp_attr_get(3), seccomp_attr_set(3)
and that's a wrap on the libseccomp Documentation, bestie β¨ this page is from 30 May 2020, brought to you by paul@paul-moore.com β go merge something responsibly, and remember: release dst, forget src. periodt. π
πΈ
π¦ 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