/* vim: set ro : */ /* * libsyd: syd /dev/syd interface implementation * Copyright (c) 2023, 2024 Ali Polatel * SPDX-License-Identifier: LGPL-3.0 */ #ifndef LIBSYD_3_SYD_H #define LIBSYD_3_SYD_H /* THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY */ #include #include #include #include #include /** * An enumeration of the possible actions for sandboxing. */ enum action_t { /** * Allow system call. */ ALLOW, /** * Allow system call and warn. */ WARN, /** * Deny system call silently. */ FILTER, /** * Deny system call and warn. */ DENY, /** * Deny system call, warn and panic the current Syd thread. */ PANIC, /** * Deny system call, warn and stop the offending process. */ STOP, /** * Deny system call, warn and kill the offending process. */ KILL, /** * Warn, and exit Syd immediately with deny errno as exit value. */ EXIT, }; typedef uint8_t action_t; /** * An enumeration of the possible states for the sandbox lock. */ enum lock_state_t { /** * The sandbox lock is off, allowing all sandbox commands. */ LOCK_OFF, /** * The sandbox lock is set to on for all processes except the initial * process (syd exec child). */ LOCK_EXEC, /** * The sandbox lock is on, disallowing all sandbox commands. */ LOCK_ON, }; typedef uint8_t lock_state_t; /** * Performs a syd API check * * The caller is advised to perform this check before * calling any other syd API calls. * * Returns API number on success, negated errno on failure. */ int syd_api(void); /** * Adds to the given actionlist of attr sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_attr_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * attr sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_attr_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of attr sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_attr_rem(action_t action, const char *glob); /** * Performs an lstat system call on the file "/dev/syd". * * Returns 0 on success, negated errno on failure. */ int syd_check(void); /** * Adds to the given actionlist of chgrp sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chgrp_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * chgrp sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chgrp_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of chgrp sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chgrp_rem(action_t action, const char *glob); /** * Adds to the given actionlist of chown sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chown_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * chown sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chown_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of chown sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_chown_rem(action_t action, const char *glob); /** * Adds to the given actionlist of create sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_create_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * create sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_create_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of create sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_create_rem(action_t action, const char *glob); /** * Set the default action for Attr Sandboxing. */ int syd_default_attr(action_t action); /** * Set the default action for IP blocklist violations. */ int syd_default_block(action_t action); /** * Set the default action for Chgrp Sandboxing. */ int syd_default_chgrp(action_t action); /** * Set the default action for Chown Sandboxing. */ int syd_default_chown(action_t action); /** * Set the default action for Create Sandboxing. */ int syd_default_create(action_t action); /** * Set the default action for Delete Sandboxing. */ int syd_default_delete(action_t action); /** * Set the default action for Exec Sandboxing. */ int syd_default_exec(action_t action); /** * Set the default action for Force Sandboxing. */ int syd_default_force(action_t action); /** * Set the default action for Ioctl Sandboxing. */ int syd_default_ioctl(action_t action); /** * Set the default action for Memory Sandboxing. */ int syd_default_mem(action_t action); /** * Set the default action for Network Sandboxing. */ int syd_default_net(action_t action); /** * Set the default action for Node Sandboxing. */ int syd_default_node(action_t action); /** * Set the default action for PID Sandboxing. */ int syd_default_pid(action_t action); /** * Set the default action for Read Sandboxing. */ int syd_default_read(action_t action); /** * Set the default action for SegvGuard */ int syd_default_segvguard(action_t action); /** * Set the default action for Stat Sandboxing. */ int syd_default_stat(action_t action); /** * Set the default action for Tmpfile Sandboxing. */ int syd_default_tmpfile(action_t action); /** * Set the default action for TPE Sandboxing. */ int syd_default_tpe(action_t action); /** * Set the default action for Truncate Sandboxing. */ int syd_default_truncate(action_t action); /** * Set the default action for Write Sandboxing. */ int syd_default_write(action_t action); /** * Adds to the given actionlist of delete sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_delete_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * delete sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_delete_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of delete sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_delete_rem(action_t action, const char *glob); /** * Disable attr sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_attr(void); /** * Disable chgrp sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_chgrp(void); /** * Disable chown sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_chown(void); /** * Disable create sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_create(void); /** * Disable delete sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_delete(void); /** * Disable exec sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_exec(void); /** * Disable force sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_force(void); /** * Disable ioctl sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_ioctl(void); /** * Disable memory sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_mem(void); /** * Disable net sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_net(void); /** * Disable node sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_node(void); /** * Disable PID sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_pid(void); /** * Disable read sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_read(void); /** * Disable stat sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_stat(void); /** * Disable tmpfile sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_tmpfile(void); /** * Disable TPE sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_tpe(void); /** * Disable truncate sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_truncate(void); /** * Disable write sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_disable_write(void); /** * Enable attr sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_attr(void); /** * Enable chgrp sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_chgrp(void); /** * Enable chown sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_chown(void); /** * Enable create sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_create(void); /** * Enable delete sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_delete(void); /** * Enable exec sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_exec(void); /** * Enable force sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_force(void); /** * Enable ioctl sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_ioctl(void); /** * Enable memory sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_mem(void); /** * Enable net sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_net(void); /** * Enable node sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_node(void); /** * Enable PID sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_pid(void); /** * Enable read sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_read(void); /** * Enable stat sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_stat(void); /** * Enable tmpfile sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_tmpfile(void); /** * Enable TPE sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_tpe(void); /** * Enable truncate sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_truncate(void); /** * Enable write sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_enable_write(void); /** * Checks if attr sandboxing is enabled. * * Returns true if attr sandboxing is enabled, false otherwise. */ bool syd_enabled_attr(void); /** * Checks if chgrp sandboxing is enabled. * * Returns true if chgrp sandboxing is enabled, false otherwise. */ bool syd_enabled_chgrp(void); /** * Checks if chown sandboxing is enabled. * * Returns true if chown sandboxing is enabled, false otherwise. */ bool syd_enabled_chown(void); /** * Checks if create sandboxing is enabled. * * Returns true if create sandboxing is enabled, false otherwise. */ bool syd_enabled_create(void); /** * Checks if crypt sandboxing is enabled. * * Returns true if crypt sandboxing is enabled, false otherwise. */ bool syd_enabled_crypt(void); /** * Checks if delete sandboxing is enabled. * * Returns true if delete sandboxing is enabled, false otherwise. */ bool syd_enabled_delete(void); /** * Checks if exec sandboxing is enabled. * * Returns true if exec sandboxing is enabled, false otherwise. */ bool syd_enabled_exec(void); /** * Checks if force sandboxing is enabled. * * Returns true if force sandboxing is enabled, false otherwise. */ bool syd_enabled_force(void); /** * Checks if ioctl sandboxing is enabled. * * Returns true if ioctl sandboxing is enabled, false otherwise. */ bool syd_enabled_ioctl(void); /** * Checks if lock sandboxing is enabled. * * Returns true if lock sandboxing is enabled, false otherwise. */ bool syd_enabled_lock(void); /** * Checks if memory sandboxing is enabled. * * Returns true if memory sandboxing is enabled, false otherwise. */ bool syd_enabled_mem(void); /** * Checks if net sandboxing is enabled. * * Returns true if net sandboxing is enabled, false otherwise. */ bool syd_enabled_net(void); /** * Checks if node sandboxing is enabled. * * Returns true if node sandboxing is enabled, false otherwise. */ bool syd_enabled_node(void); /** * Checks if PID sandboxing is enabled. * * Returns true if PID sandboxing is enabled, false otherwise. */ bool syd_enabled_pid(void); /** * Checks if proxy sandboxing is enabled. * * Returns true if proxy sandboxing is enabled, false otherwise. */ bool syd_enabled_proxy(void); /** * Checks if read sandboxing is enabled. * * Returns true if read sandboxing is enabled, false otherwise. */ bool syd_enabled_read(void); /** * Checks if stat sandboxing is enabled. * * Returns true if stat sandboxing is enabled, false otherwise. */ bool syd_enabled_stat(void); /** * Checks if tmpfile sandboxing is enabled. * * Returns true if tmpfile sandboxing is enabled, false otherwise. */ bool syd_enabled_tmpfile(void); /** * Checks if TPE sandboxing is enabled. * * Returns true if TPE sandboxing is enabled, false otherwise. */ bool syd_enabled_tpe(void); /** * Checks if truncate sandboxing is enabled. * * Returns true if truncate sandboxing is enabled, false otherwise. */ bool syd_enabled_truncate(void); /** * Checks if write sandboxing is enabled. * * Returns true if write sandboxing is enabled, false otherwise. */ bool syd_enabled_write(void); /** * Execute a command outside the sandbox without sandboxing * * # Safety * * This function is marked `unsafe` because it dereferences raw * pointers, which is inherently unsafe in Rust. * * The caller must ensure the following conditions are met to safely * use this function: * * 1. The `file` pointer must point to a valid, null-terminated C-style * string. * * 2. The `argv` pointer must point to an array of pointers, where each * pointer refers to a valid, null-terminated C-style string. The * last pointer in the array must be null, indicating the end of the * array. * * 3. The memory pointed to by `file` and `argv` must remain valid for * the duration of the call. * * Failing to uphold these guarantees can lead to undefined behavior, * including memory corruption and data races. * * Returns 0 on success, negated errno on failure. */ int syd_exec(const char *file, const char *const *argv); /** * Adds to the given actionlist of exec sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_exec_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * exec sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_exec_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of exec sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_exec_rem(action_t action, const char *glob); /** * Adds an entry to the Integrity Force map for Force Sandboxing. * * # Safety * * This function is marked `unsafe` because it dereferences raw * pointers, which is inherently unsafe in Rust. * * The caller must ensure the following conditions are met to safely * use this function: * * 1. The `path` pointer must point to a valid, null-terminated C-style * string. * 2. The `hash` pointer must point to a valid, null-terminated C-style * string. */ int syd_force_add(const char *path, const char *hash, action_t action); /** * Clears the Integrity Force map for Force Sandboxing. */ int syd_force_clr(void); /** * Removes an entry from the Integrity Force map for Force Sandboxing. * # Safety * * This function is marked `unsafe` because it dereferences raw * pointers, which is inherently unsafe in Rust. * * The caller must ensure the following conditions are met to safely * use this function: * * 1. The `path` pointer must point to a valid, null-terminated C-style * string. */ int syd_force_del(const char *path); /** * Adds to the given actionlist of ioctl sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_ioctl_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * ioctl sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_ioctl_del(action_t action, const char *glob); /** * Adds a request to the _ioctl_(2) denylist. */ int syd_ioctl_deny(uint64_t request); /** * Removes all matching patterns from the given actionlist of ioctl sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_ioctl_rem(action_t action, const char *glob); /** * Causes syd to read configuration from the given file descriptor. * * Returns 0 on success, negated errno on failure. */ int syd_load(int fd); /** * Sets the state of the sandbox lock. * * state: The desired state of the sandbox lock. * * Returns 0 on success, negated errno on failure. */ int syd_lock(lock_state_t state); /** * Set syd maximum per-process memory usage limit for memory sandboxing. * * parse-size crate is used to parse the value so formatted strings are OK. * * Returns 0 on success, negated errno on failure. */ int syd_mem_max(const char *size); /** * Set syd maximum per-process virtual memory usage limit for memory sandboxing. * * parse-size crate is used to parse the value so formatted strings are OK. * * Returns 0 on success, negated errno on failure. */ int syd_mem_vm_max(const char *size); /** * Adds to the given actionlist of net/bind sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_bind_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * net/bind sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_bind_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of net/bind sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_bind_rem(action_t action, const char *glob); /** * Adds to the given actionlist of net/connect sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_connect_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * net/connect sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_connect_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of net/connect sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_connect_rem(action_t action, const char *glob); /** * Adds to the given actionlist of net/link sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_link_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * net/link sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_link_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of net/link sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_link_rem(action_t action, const char *glob); /** * Adds to the given actionlist of net/send sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_send_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * net/send sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_send_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of net/send sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_net_send_rem(action_t action, const char *glob); /** * Adds to the given actionlist of node sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_node_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * node sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_node_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of node sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_node_rem(action_t action, const char *glob); /** * Causes syd to exit immediately with code 127 * * Returns 0 on success, negated errno on failure. */ int syd_panic(void); /** * Set syd maximum process id limit for PID sandboxing * * Returns 0 on success, negated errno on failure. */ int syd_pid_max(size_t size); /** * Adds to the given actionlist of read sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_read_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * read sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_read_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of read sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_read_rem(action_t action, const char *glob); /** * Causes syd to reset sandboxing to the default state. * Allowlists, denylists and filters are going to be cleared. * * Returns 0 on success, negated errno on failure. */ int syd_reset(void); /** * Specify SegvGuard entry expiry timeout in seconds. * Setting this timeout to 0 effectively disables SegvGuard. * * Returns 0 on success, negated errno on failure. */ int syd_segvguard_expiry(uint64_t timeout); /** * Specify SegvGuard max number of crashes before suspension. * * Returns 0 on success, negated errno on failure. */ int syd_segvguard_maxcrashes(uint8_t max); /** * Specify SegvGuard entry suspension timeout in seconds. * * Returns 0 on success, negated errno on failure. */ int syd_segvguard_suspension(uint64_t timeout); /** * Adds to the given actionlist of stat sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_stat_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * stat sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_stat_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of stat sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_stat_rem(action_t action, const char *glob); /** * Adds to the given actionlist of tmpfile sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_tmpfile_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * tmpfile sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_tmpfile_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of tmpfile sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_tmpfile_rem(action_t action, const char *glob); /** * Adds to the given actionlist of truncate sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_truncate_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * truncate sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_truncate_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of truncate sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_truncate_rem(action_t action, const char *glob); /** * Adds to the given actionlist of write sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_write_add(action_t action, const char *glob); /** * Removes the first instance from the end of the given actionlist of * write sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_write_del(action_t action, const char *glob); /** * Removes all matching patterns from the given actionlist of write sandboxing. * * Returns 0 on success, negated errno on failure. */ int syd_write_rem(action_t action, const char *glob); #endif /* LIBSYD_3_SYD_H */