Create a convencience function to set the name of a thread/process

PiperOrigin-RevId: 436661002
Change-Id: Ia66cef2f3eda829c65bc07e2ac43a0b2c878eb7b
This commit is contained in:
Oliver Kunz 2022-03-22 23:38:29 -07:00 committed by Copybara-Service
parent df8a2f77eb
commit ab9c4afb15
2 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <linux/net.h> // For SYS_CONNECT #include <linux/net.h> // For SYS_CONNECT
#include <linux/random.h> // For GRND_NONBLOCK #include <linux/random.h> // For GRND_NONBLOCK
#include <sys/mman.h> // For mmap arguments #include <sys/mman.h> // For mmap arguments
#include <sys/prctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <syscall.h> #include <syscall.h>
@ -646,6 +647,11 @@ PolicyBuilder& PolicyBuilder::AllowRename() {
return *this; return *this;
} }
PolicyBuilder& PolicyBuilder::AllowPrctlSetName() {
AddPolicyOnSyscall(__NR_prctl, {ARG_32(0), JEQ32(PR_SET_NAME, ALLOW)});
return *this;
}
PolicyBuilder& PolicyBuilder::AllowFutexOp(int op) { PolicyBuilder& PolicyBuilder::AllowFutexOp(int op) {
return AddPolicyOnSyscall( return AddPolicyOnSyscall(
__NR_futex, { __NR_futex, {

View File

@ -379,6 +379,11 @@ class PolicyBuilder final {
// - renameat2 // - renameat2
PolicyBuilder& AllowRename(); PolicyBuilder& AllowRename();
// Appends code to allow setting the name of a thread
// Allows the following
// - prctl(PR_SET_NAME, ...)
PolicyBuilder& AllowPrctlSetName();
// Enables the syscalls necessary to start a statically linked binary // Enables the syscalls necessary to start a statically linked binary
// //
// NOTE: This will call BlockSyscallWithErrno(__NR_readlink, ENOENT). If you // NOTE: This will call BlockSyscallWithErrno(__NR_readlink, ENOENT). If you