X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..5ba3f43ea354af8ad55bea84372a2bc834d8757c:/bsd/sys/guarded.h diff --git a/bsd/sys/guarded.h b/bsd/sys/guarded.h index 57c9661e7..ae1ec05f9 100644 --- a/bsd/sys/guarded.h +++ b/bsd/sys/guarded.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Apple Inc. All rights reserved. + * Copyright (c) 2016 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -32,6 +32,7 @@ #include #include +#include #ifdef PRIVATE __BEGIN_DECLS @@ -46,24 +47,29 @@ typedef __uint64_t guardid_t; #if !defined(KERNEL) extern int guarded_open_np(const char *path, const guardid_t *guard, u_int guardflags, int flags, ...); +extern int guarded_open_dprotected_np(const char *path, + const guardid_t *guard, u_int guardflags, int flags, + int dpclass, int dpflags, ...); extern int guarded_kqueue_np(const guardid_t *guard, u_int guardflags); extern int guarded_close_np(int fd, const guardid_t *guard); extern int change_fdguard_np(int fd, const guardid_t *guard, u_int guardflags, const guardid_t *nguard, u_int nguardflags, int *fdflagsp); +extern ssize_t guarded_write_np(int fd, const guardid_t *guard, const void *buf, size_t nbyte); +extern ssize_t guarded_pwrite_np(int fd, const guardid_t *guard, const void *buf, size_t nbyte, off_t offset); +extern ssize_t guarded_writev_np(int fd, const guardid_t *guard, const struct iovec *iovp, int iovcnt); #endif /* KERNEL */ -/* - * Guard types. - * - * GUARD_TYPE_FD: Guarded file descriptor. - */ -#define GUARD_TYPE_FD 0x2 +#ifndef GUARD_TYPE_FD +/* temporary source compat: use instead */ +#define GUARD_TYPE_FD 0x2 +#endif /* * File descriptor guard flavors. */ -/* Forbid close(2), and the implicit close() that a dup2(2) may do. +/* + * Forbid close(2), and the implicit close() that a dup2(2) may do. * Forces close-on-fork to be set immutably too. */ #define GUARD_CLOSE (1u << 0) @@ -85,19 +91,79 @@ extern int change_fdguard_np(int fd, const guardid_t *guard, u_int guardflags, */ #define GUARD_FILEPORT (1u << 3) +/* + * Forbid writes on a guarded fd + */ +#define GUARD_WRITE (1u << 4) + /* * Violating a guard results in an error (EPERM), and potentially * an exception with one or more of the following bits set. */ -enum guard_exception_codes { +enum guard_fd_exception_codes { kGUARD_EXC_CLOSE = 1u << 0, /* close of a guarded fd */ kGUARD_EXC_DUP = 1u << 1, /* dup of a guarded fd */ kGUARD_EXC_NOCLOEXEC = 1u << 2, /* clear close-on-exec */ kGUARD_EXC_SOCKET_IPC = 1u << 3, /* sendmsg of a guarded fd */ kGUARD_EXC_FILEPORT = 1u << 4, /* fileport_makeport .. */ - kGUARD_EXC_MISMATCH = 1u << 5 /* wrong guard for guarded fd */ + kGUARD_EXC_MISMATCH = 1u << 5, /* wrong guard for guarded fd */ + kGUARD_EXC_WRITE = 1u << 6 /* write on a guarded fd */ +}; + +/* + * Experimental guarded vnode support + */ +#define VNG_RENAME_TO (1u << 0) +#define VNG_RENAME_FROM (1u << 1) +#define VNG_UNLINK (1u << 2) +#define VNG_WRITE_OTHER (1u << 3) +#define VNG_TRUNC_OTHER (1u << 4) +#define VNG_LINK (1u << 5) +#define VNG_EXCHDATA (1u << 6) + +#define VNG_ALL \ + (VNG_RENAME_TO | VNG_RENAME_FROM | VNG_UNLINK | VNG_LINK | \ + VNG_WRITE_OTHER | VNG_TRUNC_OTHER | VNG_EXCHDATA) + +struct vnguard_set { + int vns_fd; + unsigned vns_attrs; + guardid_t vns_guard; }; +#define VNG_SYSC_PING 0 +#define VNG_SYSC_SET_GUARD 1 + +#define VNG_POLICY_NAME "vnguard" + +/* + * Violating a guard may result in an error (EPERM), and potentially + * an exception with one or more of the following bits set. + */ +enum guard_vn_exception_codes { + kGUARD_EXC_RENAME_TO = VNG_RENAME_TO, + kGUARD_EXC_RENAME_FROM = VNG_RENAME_FROM, + kGUARD_EXC_UNLINK = VNG_UNLINK, + kGUARD_EXC_WRITE_OTHER = VNG_WRITE_OTHER, + kGUARD_EXC_TRUNC_OTHER = VNG_TRUNC_OTHER, + kGUARD_EXC_LINK = VNG_LINK, + kGUARD_EXC_EXCHDATA = VNG_EXCHDATA, +}; + +#if defined(KERNEL) + +/* Guard violation behaviors: not all combinations make sense */ + +#define kVNG_POLICY_LOGMSG (1u << 0) +#define kVNG_POLICY_EPERM (1u << 1) +#define kVNG_POLICY_EXC (1u << 2) +#define kVNG_POLICY_EXC_CORPSE (1u << 3) +#define kVNG_POLICY_SIGKILL (1u << 4) + +extern int vnguard_exceptions_active(void); +extern void vnguard_policy_init(void); +#endif /* KERNEL */ + #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ __END_DECLS