Elly Jones | e58176c | 2012-01-23 11:46:17 -0500 | [diff] [blame] | 1 | /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 3 | * found in the LICENSE file. |
| 4 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 5 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 6 | /* |
| 7 | * The general pattern of use here: |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 8 | * 1) Construct a minijail with minijail_new() |
| 9 | * 2) Apply the desired restrictions to it |
| 10 | * 3) Enter it, which locks the current process inside it, or: |
| 11 | * 3) Run a process inside it |
| 12 | * 4) Destroy it. |
| 13 | */ |
| 14 | |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 15 | #ifndef _LIBMINIJAIL_H_ |
| 16 | #define _LIBMINIJAIL_H_ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | enum { |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 26 | MINIJAIL_ERR_PRELOAD = 252, |
| 27 | MINIJAIL_ERR_JAIL = 253, |
| 28 | MINIJAIL_ERR_INIT = 254, |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct minijail; |
| 32 | |
Luis Hector Chavez | e0ba4ce | 2017-07-20 15:12:22 -0700 | [diff] [blame] | 33 | /* |
| 34 | * A hook that can be used to execute code at various events during minijail |
| 35 | * setup in the forked process. These can only be used if the jailed process is |
| 36 | * not going to be invoked with LD_PRELOAD. |
| 37 | * |
| 38 | * If the return value is non-zero, it will be interpreted as -errno and the |
| 39 | * process will abort. |
| 40 | */ |
| 41 | typedef int (*minijail_hook_t)(void *context); |
| 42 | |
| 43 | /* |
| 44 | * The events during minijail setup in which hooks can run. All the events are |
| 45 | * run in the new process. |
| 46 | */ |
| 47 | typedef enum { |
| 48 | /* The hook will run just before dropping capabilities. */ |
| 49 | MINIJAIL_HOOK_EVENT_PRE_DROP_CAPS, |
| 50 | |
| 51 | /* The hook will run just before calling execve(2). */ |
| 52 | MINIJAIL_HOOK_EVENT_PRE_EXECVE, |
| 53 | |
Luis Hector Chavez | 64730af | 2017-09-13 13:18:59 -0700 | [diff] [blame] | 54 | /* The hook will run just before calling chroot(2) / pivot_root(2). */ |
| 55 | MINIJAIL_HOOK_EVENT_PRE_CHROOT, |
| 56 | |
Luis Hector Chavez | e0ba4ce | 2017-07-20 15:12:22 -0700 | [diff] [blame] | 57 | /* Sentinel for error checking. Must be last. */ |
| 58 | MINIJAIL_HOOK_EVENT_MAX, |
| 59 | } minijail_hook_event_t; |
| 60 | |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 61 | /* Allocates a new minijail with no restrictions. */ |
| 62 | struct minijail *minijail_new(void); |
| 63 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 64 | /* |
| 65 | * These functions add restrictions to the minijail. They are not applied until |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 66 | * minijail_enter() is called. See the documentation in minijail0.1 for |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 67 | * explanations in detail of what the restrictions do. |
| 68 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 69 | void minijail_change_uid(struct minijail *j, uid_t uid); |
| 70 | void minijail_change_gid(struct minijail *j, gid_t gid); |
Jorge Lucangeli Obes | d16ac49 | 2015-12-03 14:44:35 -0800 | [diff] [blame] | 71 | /* Copies |list|. */ |
Jorge Lucangeli Obes | bc67f44 | 2016-01-08 14:43:45 -0800 | [diff] [blame] | 72 | void minijail_set_supplementary_gids(struct minijail *j, size_t size, |
| 73 | const gid_t *list); |
Lutz Justen | 13807cb | 2017-01-03 17:11:55 +0100 | [diff] [blame] | 74 | void minijail_keep_supplementary_gids(struct minijail *j); |
Will Drewry | 2ddaad0 | 2011-09-16 11:36:08 -0500 | [diff] [blame] | 75 | /* Stores user to change to and copies |user| for internal consistency. */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 76 | int minijail_change_user(struct minijail *j, const char *user); |
Will Drewry | 2ddaad0 | 2011-09-16 11:36:08 -0500 | [diff] [blame] | 77 | /* Does not take ownership of |group|. */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 78 | int minijail_change_group(struct minijail *j, const char *group); |
| 79 | void minijail_use_seccomp(struct minijail *j); |
Jorge Lucangeli Obes | c2c9bcc | 2012-05-01 09:30:24 -0700 | [diff] [blame] | 80 | void minijail_no_new_privs(struct minijail *j); |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 81 | void minijail_use_seccomp_filter(struct minijail *j); |
Jorge Lucangeli Obes | 1365061 | 2016-09-02 11:27:29 -0400 | [diff] [blame] | 82 | void minijail_set_seccomp_filter_tsync(struct minijail *j); |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 83 | void minijail_parse_seccomp_filters(struct minijail *j, const char *path); |
Jorge Lucangeli Obes | 4d4b3be | 2016-08-16 16:58:14 -0400 | [diff] [blame] | 84 | void minijail_parse_seccomp_filters_from_fd(struct minijail *j, int fd); |
Jorge Lucangeli Obes | bda833c | 2012-07-31 16:25:56 -0700 | [diff] [blame] | 85 | void minijail_log_seccomp_filter_failures(struct minijail *j); |
Jorge Lucangeli Obes | f9fcdbe | 2016-02-19 15:04:09 -0800 | [diff] [blame] | 86 | /* 'minijail_use_caps' and 'minijail_capbset_drop' are mutually exclusive. */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 87 | void minijail_use_caps(struct minijail *j, uint64_t capmask); |
Jorge Lucangeli Obes | f9fcdbe | 2016-02-19 15:04:09 -0800 | [diff] [blame] | 88 | void minijail_capbset_drop(struct minijail *j, uint64_t capmask); |
Jorge Lucangeli Obes | a6eb21a | 2017-04-20 10:44:00 -0400 | [diff] [blame] | 89 | /* 'minijail_set_ambient_caps' requires 'minijail_use_caps'. */ |
| 90 | void minijail_set_ambient_caps(struct minijail *j); |
Peter Qiu | 2860c46 | 2015-12-16 15:13:06 -0800 | [diff] [blame] | 91 | void minijail_reset_signal_mask(struct minijail *j); |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 92 | void minijail_namespace_vfs(struct minijail *j); |
Jorge Lucangeli Obes | 1563b5b | 2014-07-10 07:01:53 -0700 | [diff] [blame] | 93 | void minijail_namespace_enter_vfs(struct minijail *j, const char *ns_path); |
Chirantan Ekbote | 866bb3a | 2017-02-07 12:26:42 -0800 | [diff] [blame] | 94 | void minijail_new_session_keyring(struct minijail *j); |
Luis Hector Chavez | ec0a2c1 | 2017-06-29 20:29:57 -0700 | [diff] [blame] | 95 | void minijail_skip_setting_securebits(struct minijail *j, |
| 96 | uint64_t securebits_skip_mask); |
Chirantan Ekbote | 866bb3a | 2017-02-07 12:26:42 -0800 | [diff] [blame] | 97 | |
Jorge Lucangeli Obes | a521bee | 2016-03-03 13:47:57 -0800 | [diff] [blame] | 98 | /* |
| 99 | * This option is *dangerous* as it negates most of the functionality of |
| 100 | * minijail_namespace_vfs(). You very likely don't need this. |
| 101 | */ |
| 102 | void minijail_skip_remount_private(struct minijail *j); |
Dylan Reid | f794247 | 2015-11-18 17:55:26 -0800 | [diff] [blame] | 103 | void minijail_namespace_ipc(struct minijail *j); |
Mike Frysinger | b9a7b16 | 2017-05-30 15:25:49 -0400 | [diff] [blame] | 104 | void minijail_namespace_uts(struct minijail *j); |
| 105 | int minijail_namespace_set_hostname(struct minijail *j, const char *name); |
Elly Fong-Jones | 6c08630 | 2013-03-20 17:15:28 -0400 | [diff] [blame] | 106 | void minijail_namespace_net(struct minijail *j); |
Dylan Reid | 1102f5a | 2015-09-15 11:52:20 -0700 | [diff] [blame] | 107 | void minijail_namespace_enter_net(struct minijail *j, const char *ns_path); |
Dylan Reid | 4cbc2a5 | 2016-06-17 19:06:07 -0700 | [diff] [blame] | 108 | void minijail_namespace_cgroups(struct minijail *j); |
Luis Hector Chavez | 43ff080 | 2016-10-07 12:21:07 -0700 | [diff] [blame] | 109 | /* Closes all open file descriptors after forking. */ |
| 110 | void minijail_close_open_fds(struct minijail *j); |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 111 | /* |
| 112 | * Implies namespace_vfs and remount_proc_readonly. |
Elly Jones | 761b741 | 2012-06-13 15:49:52 -0400 | [diff] [blame] | 113 | * WARNING: this is NOT THREAD SAFE. See the block comment in </libminijail.c>. |
| 114 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 115 | void minijail_namespace_pids(struct minijail *j); |
Yu-Hsi Chiang | 10e9123 | 2015-08-05 14:40:45 +0800 | [diff] [blame] | 116 | void minijail_namespace_user(struct minijail *j); |
Jorge Lucangeli Obes | 200299c | 2016-09-23 15:21:57 -0400 | [diff] [blame] | 117 | void minijail_namespace_user_disable_setgroups(struct minijail *j); |
Yu-Hsi Chiang | 10e9123 | 2015-08-05 14:40:45 +0800 | [diff] [blame] | 118 | int minijail_uidmap(struct minijail *j, const char *uidmap); |
| 119 | int minijail_gidmap(struct minijail *j, const char *gidmap); |
Dylan Reid | 791f577 | 2015-09-14 20:02:42 -0700 | [diff] [blame] | 120 | void minijail_remount_proc_readonly(struct minijail *j); |
Yu-Hsi Chiang | 3e954ec | 2015-07-28 16:48:14 +0800 | [diff] [blame] | 121 | void minijail_run_as_init(struct minijail *j); |
Yu-Hsi Chiang | 3cc05ea | 2015-08-11 11:23:17 +0800 | [diff] [blame] | 122 | int minijail_write_pid_file(struct minijail *j, const char *path); |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 123 | void minijail_inherit_usergroups(struct minijail *j); |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 124 | /* |
| 125 | * Changes the jailed process's syscall table to the alt_syscall table |
Andrew Bresticker | eac2894 | 2015-11-11 16:04:46 -0800 | [diff] [blame] | 126 | * named |table|. |
| 127 | */ |
| 128 | int minijail_use_alt_syscall(struct minijail *j, const char *table); |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 129 | |
Dylan Reid | 0f72ef4 | 2017-06-06 15:42:49 -0700 | [diff] [blame] | 130 | /* Sets the given runtime limit. See getrlimit(2). */ |
| 131 | int minijail_rlimit(struct minijail *j, int type, uint32_t cur, uint32_t max); |
| 132 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 133 | /* |
Dylan Reid | 605ce7f | 2016-01-19 19:21:00 -0800 | [diff] [blame] | 134 | * Adds the jailed process to the cgroup given by |path|. |path| should be the |
| 135 | * full path to the cgroups "tasks" file. |
| 136 | * Example: /sys/fs/cgroup/cpu/jailed_procs/tasks adds to the "jailed_procs" cpu |
| 137 | * cgroup. |
| 138 | */ |
| 139 | int minijail_add_to_cgroup(struct minijail *j, const char *path); |
| 140 | |
| 141 | /* |
Jorge Lucangeli Obes | dba6209 | 2017-05-18 17:10:23 -0400 | [diff] [blame] | 142 | * Install signal handlers in the minijail process that forward received |
| 143 | * signals to the jailed child process. |
| 144 | */ |
| 145 | int minijail_forward_signals(struct minijail *j); |
| 146 | |
| 147 | /* |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 148 | * minijail_enter_chroot: enables chroot() restriction for @j |
Elly Jones | 51a5b6c | 2011-10-12 19:09:26 -0400 | [diff] [blame] | 149 | * @j minijail to apply restriction to |
| 150 | * @dir directory to chroot() to. Owned by caller. |
| 151 | * |
| 152 | * Enters @dir, binding all bind mounts specified with minijail_bind() into |
| 153 | * place. Requires @dir to contain all necessary directories for bind mounts |
| 154 | * (i.e., if you have requested a bind mount at /etc, /etc must exist in @dir.) |
| 155 | * |
| 156 | * Returns 0 on success. |
| 157 | */ |
| 158 | int minijail_enter_chroot(struct minijail *j, const char *dir); |
Yu-Hsi Chiang | 64d65a7 | 2015-08-13 17:43:27 +0800 | [diff] [blame] | 159 | int minijail_enter_pivot_root(struct minijail *j, const char *dir); |
Elly Jones | 51a5b6c | 2011-10-12 19:09:26 -0400 | [diff] [blame] | 160 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 161 | /* |
| 162 | * minijail_get_original_path: returns the path of a given file outside of the |
Dylan Reid | 08946cc | 2015-09-16 19:10:57 -0700 | [diff] [blame] | 163 | * chroot. |
| 164 | * @j minijail to obtain the path from. |
| 165 | * @chroot_path path inside of the chroot() to. |
| 166 | * |
| 167 | * When executing a binary in a chroot or pivot_root, return path to the binary |
| 168 | * outside of the chroot. |
| 169 | * |
| 170 | * Returns a string containing the path. This must be freed by the caller. |
| 171 | */ |
| 172 | char *minijail_get_original_path(struct minijail *j, const char *chroot_path); |
| 173 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 174 | /* |
Martin Pelikán | ab9eb44 | 2017-01-25 11:53:58 +1100 | [diff] [blame] | 175 | * minijail_mount_tmp: enables mounting of a 64M tmpfs filesystem on /tmp. |
Lee Campbell | 11af062 | 2014-05-22 12:36:04 -0700 | [diff] [blame] | 176 | * As be rules of bind mounts, /tmp must exist in chroot. |
| 177 | */ |
| 178 | void minijail_mount_tmp(struct minijail *j); |
| 179 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 180 | /* |
Martin Pelikán | ab9eb44 | 2017-01-25 11:53:58 +1100 | [diff] [blame] | 181 | * minijail_mount_tmp_size: enables mounting of a tmpfs filesystem on /tmp. |
| 182 | * As be rules of bind mounts, /tmp must exist in chroot. Size is in bytes. |
| 183 | */ |
| 184 | void minijail_mount_tmp_size(struct minijail *j, size_t size); |
| 185 | |
| 186 | /* |
Dylan Reid | 81e2397 | 2016-05-18 14:06:35 -0700 | [diff] [blame] | 187 | * minijail_mount_with_data: when entering minijail @j, |
| 188 | * mounts @src at @dst with @flags and @data. |
| 189 | * @j minijail to bind inside |
| 190 | * @src source to bind |
| 191 | * @dest location to bind (inside chroot) |
| 192 | * @type type of filesystem |
| 193 | * @flags flags passed to mount |
| 194 | * @data data arguments passed to mount(2), e.g. "mode=755" |
| 195 | * |
| 196 | * This may be called multiple times; all mounts will be applied in the order |
| 197 | * of minijail_mount() calls. |
| 198 | */ |
| 199 | int minijail_mount_with_data(struct minijail *j, const char *src, |
| 200 | const char *dest, const char *type, |
| 201 | unsigned long flags, const char *data); |
| 202 | |
| 203 | /* |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 204 | * minijail_mount: when entering minijail @j, mounts @src at @dst with @flags |
Dylan Reid | 648b220 | 2015-10-23 00:50:00 -0700 | [diff] [blame] | 205 | * @j minijail to bind inside |
| 206 | * @src source to bind |
| 207 | * @dest location to bind (inside chroot) |
| 208 | * @type type of filesystem |
| 209 | * @flags flags passed to mount |
| 210 | * |
Dylan Reid | 81e2397 | 2016-05-18 14:06:35 -0700 | [diff] [blame] | 211 | * This may be called multiple times; all mounts will be applied in the order |
Dylan Reid | 648b220 | 2015-10-23 00:50:00 -0700 | [diff] [blame] | 212 | * of minijail_mount() calls. |
| 213 | */ |
| 214 | int minijail_mount(struct minijail *j, const char *src, const char *dest, |
Jorge Lucangeli Obes | d16ac49 | 2015-12-03 14:44:35 -0800 | [diff] [blame] | 215 | const char *type, unsigned long flags); |
Dylan Reid | 648b220 | 2015-10-23 00:50:00 -0700 | [diff] [blame] | 216 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 217 | /* |
| 218 | * minijail_bind: bind-mounts @src into @j as @dest, optionally writeable |
Elly Jones | 51a5b6c | 2011-10-12 19:09:26 -0400 | [diff] [blame] | 219 | * @j minijail to bind inside |
| 220 | * @src source to bind |
| 221 | * @dest location to bind (inside chroot) |
| 222 | * @writeable 1 if the bind mount should be writeable |
| 223 | * |
| 224 | * This may be called multiple times; all bindings will be applied in the order |
| 225 | * of minijail_bind() calls. |
| 226 | */ |
| 227 | int minijail_bind(struct minijail *j, const char *src, const char *dest, |
Jorge Lucangeli Obes | 2f61ee4 | 2014-06-16 11:08:18 -0700 | [diff] [blame] | 228 | int writeable); |
Elly Jones | 51a5b6c | 2011-10-12 19:09:26 -0400 | [diff] [blame] | 229 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 230 | /* |
Luis Hector Chavez | e0ba4ce | 2017-07-20 15:12:22 -0700 | [diff] [blame] | 231 | * minijail_add_hook: adds @hook to the list of hooks that will be |
| 232 | * invoked when @event is reached during minijail setup. The caller is |
| 233 | * responsible for the lifetime of @payload. |
| 234 | * @j minijail to add the hook to |
| 235 | * @hook the function that will be invoked |
| 236 | * @payload an opaque pointer |
| 237 | * @event the event that will trigger the hook |
| 238 | */ |
| 239 | int minijail_add_hook(struct minijail *j, |
| 240 | minijail_hook_t hook, void *payload, |
| 241 | minijail_hook_event_t event); |
| 242 | |
| 243 | /* |
Luis Hector Chavez | 1617f63 | 2017-08-01 18:32:30 -0700 | [diff] [blame] | 244 | * minijail_preserve_fd: preserves @parent_fd and makes it available as |
| 245 | * @child_fd in the child process. @parent_fd will be closed if no other |
| 246 | * redirect has claimed it as a @child_fd. This works even if |
| 247 | * minijail_close_open_fds() is invoked. |
| 248 | * @j minijail to add the fd to |
| 249 | * @parent_fd the fd in the parent process |
| 250 | * @child_fd the fd that will be available in the child process |
| 251 | */ |
| 252 | int minijail_preserve_fd(struct minijail *j, int parent_fd, int child_fd); |
| 253 | |
| 254 | /* |
Jorge Lucangeli Obes | deca9f2 | 2016-07-01 09:49:39 -0400 | [diff] [blame] | 255 | * Lock this process into the given minijail. Note that this procedure cannot |
| 256 | * fail, since there is no way to undo privilege-dropping; therefore, if any |
| 257 | * part of the privilege-drop fails, minijail_enter() will abort the entire |
| 258 | * process. |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 259 | * |
| 260 | * Some restrictions cannot be enabled this way (pid namespaces) and attempting |
| 261 | * to do so will cause an abort. |
| 262 | */ |
| 263 | void minijail_enter(const struct minijail *j); |
| 264 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 265 | /* |
Dylan Reid | 0412dcc | 2017-08-24 11:33:15 -0700 | [diff] [blame] | 266 | * Run the specified command in the given minijail, execve(2)-style. |
| 267 | * If minijail_namespace_pids() or minijail_namespace_user() are used, |
| 268 | * this or minijail_fork() is required instead of minijail_enter(). |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 269 | */ |
| 270 | int minijail_run(struct minijail *j, const char *filename, |
| 271 | char *const argv[]); |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 272 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 273 | /* |
| 274 | * Run the specified command in the given minijail, execve(2)-style. |
Jorge Lucangeli Obes | 5471450 | 2015-09-30 10:08:45 -0700 | [diff] [blame] | 275 | * Used with static binaries, or on systems without support for LD_PRELOAD. |
Lee Campbell | 1e4fc6a | 2014-06-06 17:40:02 -0700 | [diff] [blame] | 276 | */ |
Jorge Lucangeli Obes | 5471450 | 2015-09-30 10:08:45 -0700 | [diff] [blame] | 277 | int minijail_run_no_preload(struct minijail *j, const char *filename, |
| 278 | char *const argv[]); |
Lee Campbell | 1e4fc6a | 2014-06-06 17:40:02 -0700 | [diff] [blame] | 279 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 280 | /* |
| 281 | * Run the specified command in the given minijail, execve(2)-style. |
Jorge Lucangeli Obes | 9807d03 | 2012-04-17 13:36:00 -0700 | [diff] [blame] | 282 | * Update |*pchild_pid| with the pid of the child. |
| 283 | */ |
| 284 | int minijail_run_pid(struct minijail *j, const char *filename, |
| 285 | char *const argv[], pid_t *pchild_pid); |
| 286 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 287 | /* |
| 288 | * Run the specified command in the given minijail, execve(2)-style. |
Jorge Lucangeli Obes | df4bd35 | 2012-08-29 19:12:28 -0700 | [diff] [blame] | 289 | * Update |*pstdin_fd| with a fd that allows writing to the child's |
| 290 | * standard input. |
| 291 | */ |
| 292 | int minijail_run_pipe(struct minijail *j, const char *filename, |
| 293 | char *const argv[], int *pstdin_fd); |
| 294 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 295 | /* |
| 296 | * Run the specified command in the given minijail, execve(2)-style. |
Jorge Lucangeli Obes | df4bd35 | 2012-08-29 19:12:28 -0700 | [diff] [blame] | 297 | * Update |*pchild_pid| with the pid of the child. |
| 298 | * Update |*pstdin_fd| with a fd that allows writing to the child's |
| 299 | * standard input. |
Jorge Lucangeli Obes | 339a113 | 2013-02-15 16:53:47 -0800 | [diff] [blame] | 300 | * Update |*pstdout_fd| with a fd that allows reading from the child's |
| 301 | * standard output. |
| 302 | * Update |*pstderr_fd| with a fd that allows reading from the child's |
| 303 | * standard error. |
| 304 | */ |
| 305 | int minijail_run_pid_pipes(struct minijail *j, const char *filename, |
| 306 | char *const argv[], pid_t *pchild_pid, |
| 307 | int *pstdin_fd, int *pstdout_fd, int *pstderr_fd); |
| 308 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 309 | /* |
| 310 | * Run the specified command in the given minijail, execve(2)-style. |
Samuel Tan | 63187f4 | 2015-10-16 13:01:53 -0700 | [diff] [blame] | 311 | * Update |*pchild_pid| with the pid of the child. |
| 312 | * Update |*pstdin_fd| with a fd that allows writing to the child's |
| 313 | * standard input. |
| 314 | * Update |*pstdout_fd| with a fd that allows reading from the child's |
| 315 | * standard output. |
| 316 | * Update |*pstderr_fd| with a fd that allows reading from the child's |
| 317 | * standard error. |
| 318 | * Used with static binaries, or on systems without support for LD_PRELOAD. |
| 319 | */ |
| 320 | int minijail_run_pid_pipes_no_preload(struct minijail *j, const char *filename, |
| 321 | char *const argv[], pid_t *pchild_pid, |
Jorge Lucangeli Obes | 43a6a86 | 2015-12-04 14:53:36 -0800 | [diff] [blame] | 322 | int *pstdin_fd, int *pstdout_fd, |
| 323 | int *pstderr_fd); |
Samuel Tan | 63187f4 | 2015-10-16 13:01:53 -0700 | [diff] [blame] | 324 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 325 | /* |
Dylan Reid | 0412dcc | 2017-08-24 11:33:15 -0700 | [diff] [blame] | 326 | * Fork, jail the child, and return. This behaves similar to fork(2), except it |
| 327 | * puts the child process in a jail before returning. |
| 328 | * `minijail_fork` returns in both the parent and the child. The pid of the |
| 329 | * child is returned to the parent. Zero is returned in the child. LD_PRELOAD |
| 330 | * is not supported. |
| 331 | * If minijail_namespace_pids() or minijail_namespace_user() are used, |
| 332 | * this or minijail_run*() is required instead of minijail_enter(). |
| 333 | */ |
| 334 | pid_t minijail_fork(struct minijail *j); |
| 335 | |
| 336 | /* |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 337 | * Kill the specified minijail. The minijail must have been created with pid |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 338 | * namespacing; if it was, all processes inside it are atomically killed. |
| 339 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 340 | int minijail_kill(struct minijail *j); |
| 341 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 342 | /* |
Jorge Lucangeli Obes | deca9f2 | 2016-07-01 09:49:39 -0400 | [diff] [blame] | 343 | * Wait for all processes in the specified minijail to exit. Returns the exit |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 344 | * status of the _first_ process spawned in the jail. |
| 345 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 346 | int minijail_wait(struct minijail *j); |
| 347 | |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 348 | /* |
Jorge Lucangeli Obes | deca9f2 | 2016-07-01 09:49:39 -0400 | [diff] [blame] | 349 | * Frees the given minijail. It does not matter if the process is inside the |
| 350 | * minijail or not. |
Jorge Lucangeli Obes | d0a6e2f | 2015-11-24 14:21:21 -0800 | [diff] [blame] | 351 | */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 352 | void minijail_destroy(struct minijail *j); |
| 353 | |
Luis Hector Chavez | 114a930 | 2017-09-05 20:36:58 -0700 | [diff] [blame] | 354 | /* |
| 355 | * minijail_log_to_fd: redirects the module-wide logging to an FD instead of |
| 356 | * syslog. |
| 357 | * @fd FD to log to. Caller must ensure this is available after |
| 358 | * jailing (e.g. with minijail_preserve_fd()). |
| 359 | * @min_priority the minimum logging priority. Same as the priority argument |
| 360 | * to syslog(2). |
| 361 | */ |
| 362 | void minijail_log_to_fd(int fd, int min_priority); |
| 363 | |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 364 | #ifdef __cplusplus |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 365 | }; /* extern "C" */ |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 366 | #endif |
| 367 | |
Elly Jones | e1749eb | 2011-10-07 13:54:59 -0400 | [diff] [blame] | 368 | #endif /* !_LIBMINIJAIL_H_ */ |