You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sandbox Plugin will provide a high-level API similar to Deno Permissions but with full control like in Docker containers. With this, any language like higher level ones like NodeJS, Ruby, Python.. will be able to control execution, especially for untrusted code. This also applies to any other supported language in MetaCall, like Rust, Java, C#
APIs
API Flag Format: --allow-{category} / --disallow-{category}
Mapped Function Format: int sandbox_{category}(void *ctx, bool allow)
I/O system calls in Linux enable processes to read from and write to various input and output devices, including files, network sockets, and terminals. These calls allow data to be transferred between the program and external resources.
read: Reads data from a file descriptor into a buffer.
write: Writes data from a buffer to a file descriptor.
open: Opens a file or creates a new one.
close: Closes a file descriptor.
lseek: Changes the file position of a file descriptor.
dup: Duplicates a file descriptor.
dup2: Duplicates a file descriptor to a specified target file descriptor.
pipe: Creates an interprocess communication (IPC) pipe.
select: Monitors multiple file descriptors for read, write, or error conditions.
poll: Similar to select, monitors multiple file descriptors for events.
epoll: Provides a scalable and more efficient mechanism for monitoring file descriptors.
fcntl: Performs various operations on file descriptors.
ioctl: Performs I/O control operations on devices or sockets.
pread: Reads data from a file descriptor at a specific offset without changing the file position.
pwrite: Writes data to a file descriptor at a specific offset without changing the file position.
readv: Reads data into multiple buffers from a file descriptor.
writev: Writes data from multiple buffers to a file descriptor.
send: Sends data on a connected socket.
recv: Receives data from a connected socket.
sendto: Sends data to a specified address and port on a socket.
recvfrom: Receives data from a socket, including the sender's address and port.
sendmsg: Sends a message on a socket with greater control over headers and data.
recvmsg: Receives a message from a socket with control information.
fsync: Synchronizes a file's in-memory state with its on-disk state.
fdatasync: Synchronizes only the data part of a file with its on-disk state.
Sockets:
Socket system calls provide the foundation for network communication in Linux. They allow processes to create, connect, send, and receive data over network sockets, facilitating communication between processes across different devices or even over a network.
socket: Creates a new socket.
bind: Associates a socket with a specific address and port.
listen: Puts a socket into listening mode for incoming connections (used with server sockets).
accept: Accepts an incoming connection on a listening socket.
connect: Initiates a connection to a remote socket.
send: Sends data on a connected socket.
recv: Receives data from a connected socket.
sendto: Sends data to a specified address and port on a socket.
recvfrom: Receives data from a socket, including the sender's address and port.
shutdown: Shuts down part or all of a socket's communication.
getsockname: Retrieves the local address and port of a socket.
getpeername: Retrieves the remote address and port of a connected socket.
socketpair: Creates a pair of connected sockets for local interprocess communication (IPC).
setsockopt: Sets options on a socket.
getsockopt: Retrieves options from a socket.
select: Monitors multiple sockets for read, write, or error conditions.
poll: Similar to select, monitors multiple sockets for events.
epoll: Provides a scalable and more efficient mechanism for monitoring sockets.
fcntl: Performs various operations on socket file descriptors.
ioctl: Performs I/O control operations on sockets.
getaddrinfo: Resolves hostnames and service names to socket addresses.
getnameinfo: Retrieves human-readable information from socket addresses.
gethostname: Retrieves the name of the local host.
gethostbyname: Retrieves host information based on a hostname (deprecated, use getaddrinfo instead).
gethostbyaddr: Retrieves host information based on an IP address (deprecated, use getaddrinfo instead).
IPC (Interprocess Communication):
IPC system calls enable processes to exchange data and synchronize their actions. This category includes shared memory, message queues, and semaphores, which facilitate communication and coordination between different processes running on the same system.
shmget: Allocates a shared memory segment.
shmat: Attaches a shared memory segment to the calling process's address space.
shmdt: Detaches a shared memory segment from the calling process.
shmctl: Performs control operations on a shared memory segment.
msgget: Allocates a new message queue.
msgsnd: Sends a message to a message queue.
msgrcv: Receives a message from a message queue.
msgctl: Performs control operations on a message queue.
semget: Allocates a new set of semaphores.
semop: Performs semaphore operations (e.g., wait, signal) on a semaphore set.
semctl: Performs control operations on a semaphore set.
ftok: Generates a key for interprocess communication resources.
Process Management:
Process management system calls are crucial for creating, controlling, and managing processes. These calls include process creation, termination, signal handling, and resource management, allowing processes to interact and coordinate their activities.
fork: Creates a new process by duplicating the calling process.
vfork: Creates a new process, but suspends the parent process until the child process terminates.
clone: Creates a new process or thread, allowing for more fine-grained control than fork.
exec: Replaces the current process image with a new one.
wait: Waits for a child process to terminate and collects its exit status.
waitpid: Waits for a specific child process to terminate and collects its exit status.
waitid: Waits for the termination of a specific process or group of processes.
exit: Terminates the calling process and returns an exit status to the parent process.
exit_group: Terminates all threads in the calling process and exits the process group.
kill: Sends a signal to a specified process or process group.
getpid: Retrieves the process ID (PID) of the calling process.
getppid: Retrieves the parent process's PID of the calling process.
setsid: Creates a new session and sets the calling process as the session leader.
setpgid: Sets the process group ID of a specified process.
nice: Adjusts the scheduling priority of a process.
sched_yield: Yields the CPU to other processes in the same priority range.
setpriority: Sets the scheduling priority of a process.
getpriority: Retrieves the scheduling priority of a process.
getpgid: Retrieves the process group ID of a process.
setsid: Creates a new session and sets the calling process as the session leader.
File Systems:
File system system calls provide the means to interact with the file system, including file and directory creation, manipulation, and access control. These calls allow processes to read, write, and manage files and directories on storage devices.
open: Opens a file or creates a new one.
close: Closes a file descriptor.
read: Reads data from a file descriptor into a buffer.
write: Writes data from a buffer to a file descriptor.
lseek: Changes the file position of a file descriptor.
unlink: Removes a directory entry or a file.
mkdir: Creates a new directory.
rmdir: Removes a directory.
rename: Renames a file or directory.
link: Creates a hard link to an existing file.
symlink: Creates a symbolic link to a file.
stat: Retrieves file status information.
fstat: Retrieves file status information for an open file.
lstat: Retrieves symbolic link status information.
chmod: Changes the permissions of a file or directory.
newfstatat: Retrieves file status information relative to a directory file descriptor.
chown: Changes the ownership of a file or directory.
utime: Sets access and modification times for a file.
access: Checks accessibility of a file.
truncate: Truncates a file to a specified length.
ftruncate: Truncates an open file to a specified length.
sync: Synchronizes cached writes to persistent storage.
fsync: Synchronizes a file's in-memory state with its on-disk state.
fdatasync: Synchronizes only the data part of a file with its on-disk state.
chdir: Changes the current working directory.
getcwd: Retrieves the current working directory.
opendir: Opens a directory for reading.
readdir: Reads the next entry from a directory.
closedir: Closes a directory.
chroot: Changes the root directory for a process.
mount: Mounts a file system.
umount: Unmounts a file system.
Date and Time:
Date and time system calls allow processes to work with time-related information. These calls include functions for retrieving the current time, setting timers, and manipulating time values, helping programs manage timestamps and schedule events.
time: Retrieves the current time since the Epoch.
gettimeofday: Retrieves the current time with microsecond precision.
clock_gettime: Retrieves the current time based on a specified clock.
clock_settime: Sets the time of a specified clock.
clock_getres: Retrieves the resolution of a specified clock.
date: Displays or sets the system date and time.
sleep: Suspends the execution of a process for a specified number of seconds.
usleep: Suspends the execution of a process for a specified number of microseconds.
nanosleep: Suspends the execution of a process for a specified number of nanoseconds.
clock_nanosleep: Suspends the execution of a process until a specified clock time is reached, with nanosecond precision.
Memory Management:
Memory management system calls deal with the allocation, deallocation, and manipulation of memory in a process's address space. They include functions for memory mapping, memory protection, dynamic memory allocation, and memory locking.
mmap: Maps files or devices into memory.
munmap: Unmaps files or devices from memory.
mprotect: Changes the protection of memory regions.
brk: Sets the end of the data (heap) segment.
sbrk: Increases or decreases the program's data space.
mincore: Determines whether pages are resident in memory.
madvise: Provides advice about memory use.
posix_memalign: Allocates aligned memory.
malloc: Allocates memory.
calloc: Allocates and initializes memory.
realloc: Changes the size of allocated memory.
free: Frees allocated memory.
mlock: Locks memory into RAM.
munlock: Unlocks memory locked with mlock.
mlockall: Locks all current and future pages into RAM.
munlockall: Unlocks all locked pages.
getrlimit: Gets resource limits.
setrlimit: Sets resource limits.
getrusage: Gets resource usage statistics.
getpagesize: Gets the system page size.
Signal Handling:
Signal handling system calls are essential for managing asynchronous notifications, known as signals, sent to processes. These calls allow processes to establish signal handlers, send signals to other processes, and respond to specific events or exceptions, ensuring proper error handling and process coordination.
signal: Sets a function to handle a signal.
sigaction: Examines and modifies signal action.
kill: Sends a signal to a process.
raise: Sends a signal to the calling process.
abort: Terminates the calling process.
pause: Suspends the calling process until a signal is received.
sigpending: Gets the set of blocked signals.
sigprocmask: Examines and modifies the signal mask.
sigsuspend: Replaces the signal mask and suspends the process.
sigqueue: Sends a signal with data to a process.
sigsetjmp: Saves the calling environment for later use with siglongjmp.
siglongjmp: Restores the environment saved by sigsetjmp and returns control.
sigaltstack: Sets an alternative signal stack.
signalfd: Creates a file descriptor for signals.
Issues to be considered
Is seccomp filters affect the caller process only or the children too?
You should ensure the security for the sandbox plugin to prevent anyone from disabling or missing the sandbox source code.
Todo
Add the user management system calls to the table.
Implement the APIs using ext_loader.
Provide security for the sandbox plugin directory.
Write test suites for all the APIs and check all the common functions in different languages.
Resources
You can find all the provided system calls by Linux kernel here.
Like the previous resource, This is a similar approach for Seccomp called Capabilities introduced by Docker. But don't forget we are working on "Seccomp" approach.
🚀 Feature
Sandbox Plugin System Design
Description
Sandbox Plugin will provide a high-level API similar to Deno Permissions but with full control like in Docker containers. With this, any language like higher level ones like NodeJS, Ruby, Python.. will be able to control execution, especially for untrusted code. This also applies to any other supported language in MetaCall, like Rust, Java, C#
APIs
API Flag Format: --allow-{category} / --disallow-{category}
Mapped Function Format: int sandbox_{category}(void *ctx, bool allow)
System Calls Categories:
I/O (Input/Output):
Sockets:
IPC (Interprocess Communication):
Process Management:
File Systems:
Date and Time:
Memory Management:
Signal Handling:
Issues to be considered
Todo
Resources
You can find all the provided system calls by Linux kernel here.
For inspiration, you can look at Seccomp Security Profiles for Docker
For more inspiration, you can look at Runtime privilege and Linux capabilities.
Like the previous resource, This is a similar approach for Seccomp called Capabilities introduced by Docker. But don't forget we are working on "Seccomp" approach.
For more and more inspiration, you can look at Deno's Permissions
The text was updated successfully, but these errors were encountered: