1 /* $OpenBSD: pledge.h,v 1.51 2024/10/29 12:40:17 jsg Exp $ */ 2 3 /* 4 * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> 5 * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _SYS_PLEDGE_H_ 21 #define _SYS_PLEDGE_H_ 22 23 /* 24 * pledge(2) requests 25 */ 26 #define PLEDGE_ALWAYS 0xffffffffffffffffULL 27 #define PLEDGE_RPATH 0x0000000000000001ULL /* allow open for read */ 28 #define PLEDGE_WPATH 0x0000000000000002ULL /* allow open for write */ 29 #define PLEDGE_CPATH 0x0000000000000004ULL /* allow creat, mkdir, unlink etc */ 30 #define PLEDGE_STDIO 0x0000000000000008ULL /* operate on own pid */ 31 #define PLEDGE_TMPPATH 0x0000000000000010ULL /* for mk*temp() */ 32 #define PLEDGE_DNS 0x0000000000000020ULL /* DNS services */ 33 #define PLEDGE_INET 0x0000000000000040ULL /* AF_INET/AF_INET6 sockets */ 34 #define PLEDGE_FLOCK 0x0000000000000080ULL /* file locking */ 35 #define PLEDGE_UNIX 0x0000000000000100ULL /* AF_UNIX sockets */ 36 #define PLEDGE_ID 0x0000000000000200ULL /* allow setuid, setgid, etc */ 37 #define PLEDGE_TAPE 0x0000000000000400ULL /* Tape ioctl */ 38 #define PLEDGE_GETPW 0x0000000000000800ULL /* YP enables if ypbind.lock */ 39 #define PLEDGE_PROC 0x0000000000001000ULL /* fork, waitpid, etc */ 40 #define PLEDGE_SETTIME 0x0000000000002000ULL /* able to set/adj time/freq */ 41 #define PLEDGE_FATTR 0x0000000000004000ULL /* allow explicit file st_* mods */ 42 #define PLEDGE_PROTEXEC 0x0000000000008000ULL /* allow use of PROT_EXEC */ 43 #define PLEDGE_TTY 0x0000000000010000ULL /* tty setting */ 44 #define PLEDGE_SENDFD 0x0000000000020000ULL /* AF_UNIX CMSG fd sending */ 45 #define PLEDGE_RECVFD 0x0000000000040000ULL /* AF_UNIX CMSG fd receiving */ 46 #define PLEDGE_EXEC 0x0000000000080000ULL /* execve, child is free of pledge */ 47 #define PLEDGE_ROUTE 0x0000000000100000ULL /* routing lookups */ 48 #define PLEDGE_MCAST 0x0000000000200000ULL /* multicast joins */ 49 #define PLEDGE_VMINFO 0x0000000000400000ULL /* vminfo listings */ 50 #define PLEDGE_PS 0x0000000000800000ULL /* ps listings */ 51 #define PLEDGE_DISKLABEL 0x0000000002000000ULL /* disklabels */ 52 #define PLEDGE_PF 0x0000000004000000ULL /* pf ioctls */ 53 #define PLEDGE_AUDIO 0x0000000008000000ULL /* audio ioctls */ 54 #define PLEDGE_DPATH 0x0000000010000000ULL /* mknod & mkfifo */ 55 #define PLEDGE_DRM 0x0000000020000000ULL /* drm ioctls */ 56 #define PLEDGE_VMM 0x0000000040000000ULL /* vmm ioctls */ 57 #define PLEDGE_CHOWN 0x0000000080000000ULL /* chown(2) family */ 58 #define PLEDGE_CHOWNUID 0x0000000100000000ULL /* allow owner/group changes */ 59 #define PLEDGE_BPF 0x0000000200000000ULL /* bpf ioctl */ 60 #define PLEDGE_ERROR 0x0000000400000000ULL /* ENOSYS instead of kill */ 61 #define PLEDGE_WROUTE 0x0000000800000000ULL /* interface address ioctls */ 62 #define PLEDGE_UNVEIL 0x0000001000000000ULL /* allow unveil() */ 63 #define PLEDGE_VIDEO 0x0000002000000000ULL /* video ioctls */ 64 65 /* 66 * Bits outside PLEDGE_USERSET are used by the kernel itself 67 * to track program behaviours which have been observed. 68 */ 69 #define PLEDGE_USERSET 0x0fffffffffffffffULL 70 71 #ifdef PLEDGENAMES 72 static const struct { 73 uint64_t bits; 74 const char *name; 75 } pledgenames[] = { 76 { PLEDGE_STDIO, "stdio" }, 77 { PLEDGE_RPATH, "rpath" }, 78 { PLEDGE_WPATH, "wpath" }, 79 { PLEDGE_CPATH, "cpath" }, 80 { PLEDGE_DPATH, "dpath" }, 81 { PLEDGE_TMPPATH, "tmppath" }, 82 { PLEDGE_INET, "inet" }, 83 { PLEDGE_MCAST, "mcast" }, 84 { PLEDGE_FATTR, "fattr" }, 85 { PLEDGE_CHOWNUID, "chown" }, 86 { PLEDGE_FLOCK, "flock" }, 87 { PLEDGE_UNIX, "unix" }, 88 { PLEDGE_DNS, "dns" }, 89 { PLEDGE_GETPW, "getpw" }, 90 { PLEDGE_SENDFD, "sendfd" }, 91 { PLEDGE_RECVFD, "recvfd" }, 92 { PLEDGE_TAPE, "tape" }, 93 { PLEDGE_TTY, "tty" }, 94 { PLEDGE_PROC, "proc" }, 95 { PLEDGE_EXEC, "exec" }, 96 { PLEDGE_PROTEXEC, "prot_exec" }, 97 { PLEDGE_SETTIME, "settime" }, 98 { PLEDGE_PS, "ps" }, 99 { PLEDGE_VMINFO, "vminfo" }, 100 { PLEDGE_ID, "id" }, 101 { PLEDGE_PF, "pf" }, 102 { PLEDGE_ROUTE, "route" }, 103 { PLEDGE_WROUTE, "wroute" }, 104 { PLEDGE_AUDIO, "audio" }, 105 { PLEDGE_VIDEO, "video" }, 106 { PLEDGE_BPF, "bpf" }, 107 { PLEDGE_UNVEIL, "unveil" }, 108 { PLEDGE_ERROR, "error" }, 109 { PLEDGE_DISKLABEL, "disklabel" }, 110 { PLEDGE_DRM, "drm" }, 111 { PLEDGE_VMM, "vmm" }, 112 { 0, NULL }, 113 }; 114 #endif 115 116 #ifdef _KERNEL 117 118 int pledge_syscall(struct proc *, int, uint64_t *); 119 int pledge_fail(struct proc *, int, uint64_t); 120 121 struct nameidata; 122 int pledge_namei(struct proc *, struct nameidata *, char *); 123 int pledge_sendfd(struct proc *p, struct file *); 124 int pledge_recvfd(struct proc *p, struct file *); 125 int pledge_sysctl(struct proc *p, int namelen, int *name, void *new); 126 int pledge_chown(struct proc *p, uid_t, gid_t); 127 int pledge_adjtime(struct proc *p, const void *v); 128 int pledge_sendit(struct proc *p, const void *to); 129 int pledge_sockopt(struct proc *p, int set, int level, int optname); 130 int pledge_socket(struct proc *p, int domain, unsigned int state); 131 int pledge_ioctl(struct proc *p, long com, struct file *); 132 int pledge_ioctl_drm(struct proc *p, long com, dev_t device); 133 int pledge_ioctl_vmm(struct proc *p, long com); 134 int pledge_ioctl_psp(struct proc *p, long com); 135 int pledge_flock(struct proc *p); 136 int pledge_fcntl(struct proc *p, int cmd); 137 int pledge_swapctl(struct proc *p, int cmd); 138 int pledge_kill(struct proc *p, pid_t pid); 139 int pledge_profil(struct proc *, u_int); 140 int pledge_protexec(struct proc *p, int prot); 141 142 #endif /* _KERNEL */ 143 144 #endif /* _SYS_PLEDGE_H_ */ 145