seccomp_sy...solve_name(3)

✨ seccomp_syscall_resolve_name β€” resolve a syscall name πŸ’…

okay bestie, this is the seccomp_syscall_resolve_name(3) page from the libseccomp Documentation and it's literally the "what number is this syscall actually called" translator. no cap. πŸ¦‹


πŸŽ€ NAME πŸŽ€

seccomp_syscall_resolve_name β€” resolve a syscall name ✨


🌸 SYNOPSIS 🌸

#include <seccomp.h>

int seccomp_syscall_resolve_name(const char *name);
int seccomp_syscall_resolve_name_arch(uint32_t arch_token,
                                      const char *name);
int seccomp_syscall_resolve_name_rewrite(uint32_t arch_token,
                                         const char *name);
char *seccomp_syscall_resolve_num_arch(uint32_t arch_token, int num);

Link with -lseccomp.

and yes, that's a whole little friend group of functions. we'll get to each one, don't worry 🫢

πŸ’– DESCRIPTION πŸ’–

so seccomp_syscall_resolve_name(), seccomp_syscall_resolve_name_arch(), and seccomp_syscall_resolve_name_rewrite() all take the cute little syscall name you actually use and hand you back the syscall number the kernel (and the rest of the libseccomp API) actually speaks. it's giving translator energy fr fr. 🌈

and seccomp_syscall_resolve_name_rewrite()? she goes one step further and rewrites the syscall number for architectures that modify the syscall. this rewriting thing typically happens when you're dealing with a multiplexed syscall, like socketcall(2) or ipc(2) on x86. iykyk. πŸ‘‘

meanwhile seccomp_syscall_resolve_num_arch() does the reverse glow-up: it takes the syscall number the kernel uses and gives you back the commonly used syscall name. πŸ’«

⚠️ heads up bestie: the caller is responsible for freeing the returned string from seccomp_syscall_resolve_num_arch(). that string is yours now. free it or it's a leak. not me forgetting to free 😭

⭐ RETURN VALUE ⭐

for seccomp_syscall_resolve_name(), seccomp_syscall_resolve_name_arch(), and seccomp_syscall_resolve_name_rewrite() you get the associated syscall number back. πŸŽ€

  • if the given syscall doesn't exist for the architecture, you get the negative pseudo syscall number returned. it's a real thing, it's valid, don't panic.
  • if something's actually wrong, you get __NR_SCMP_ERROR returned. that's the error vibe. πŸ’€

and in all cases, the return value is suitable for use in any libseccomp API function that requires the syscall number β€” examples include seccomp_rule_add() and seccomp_rule_add_exact(). so you can just pass it straight through, no conversion needed. slay. ✨

for seccomp_syscall_resolve_num_arch() you get the associated syscall name back, and it remains the caller's responsibility to free the returned string via free(3). free it!! πŸ™ˆ


πŸ¦‹ EXAMPLES πŸ¦‹

here's the whole thing in action, bestie:

#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_rule_add(ctx, SCMP_ACT_ALLOW,
                           seccomp_syscall_resolve_name("open"), 0);
     if (rc < 0)
          goto out;

     /* ... */

     rc = seccomp_load(ctx);
     if (rc < 0)
          goto out;

     /* ... */

out:
     seccomp_release(ctx);
     return -rc;
}

see how seccomp_syscall_resolve_name("open") just slots right into seccomp_rule_add()? that's the whole point. iconic. πŸ‘‘


🌟 NOTES 🌟

okay so here's the tea on bare syscalls implemented on top of a multiplexed syscall β˜• β€” in that case, seccomp_syscall_resolve_name() and seccomp_syscall_resolve_name_arch() can be used to verify if a bare syscall is implemented for a specific architecture, while seccomp_syscall_resolve_name_rewrite() can be used to determine the underlying multiplexed syscall. different tools, different jobs. πŸ’…

and lowkey important: 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, generating is free, enforcing needs the kernel to be on board. 🀝

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 πŸ”₯


and that's the page bestie!! 🌸 written by paul@paul-moore.com, dated 8 May 2014, and it's seccomp_syscall_resolve_name(3) from libseccomp. go resolve some syscalls, you absolute main character. πŸ«ΆπŸ’– no cap.

πŸ“¦ where this page comes from