blob: 0853c179805812e028e322c7806f910a51d002d5 [file] [log] [blame]
Elly Jonese58176c2012-01-23 11:46:17 -05001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Elly Jonescd7a9042011-07-22 13:56:51 -04002 * Use of this source code is governed by a BSD-style license that can be
Will Drewry32ac9f52011-08-18 21:36:27 -05003 * found in the LICENSE file.
4 */
Elly Jonescd7a9042011-07-22 13:56:51 -04005
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -08006/*
7 * The general pattern of use here:
Elly Jonescd7a9042011-07-22 13:56:51 -04008 * 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 Jonese1749eb2011-10-07 13:54:59 -040015#ifndef _LIBMINIJAIL_H_
16#define _LIBMINIJAIL_H_
Elly Jonescd7a9042011-07-22 13:56:51 -040017
18#include <stdint.h>
Luis Hector Chavez7058a2d2018-01-29 08:41:34 -080019#include <sys/resource.h>
Elly Jonescd7a9042011-07-22 13:56:51 -040020#include <sys/types.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26enum {
Elly Jonese1749eb2011-10-07 13:54:59 -040027 MINIJAIL_ERR_PRELOAD = 252,
28 MINIJAIL_ERR_JAIL = 253,
29 MINIJAIL_ERR_INIT = 254,
Elly Jonescd7a9042011-07-22 13:56:51 -040030};
31
32struct minijail;
Luis Hector Chavezc3e17722018-10-16 20:43:12 -070033struct sock_fprog;
Elly Jonescd7a9042011-07-22 13:56:51 -040034
Luis Hector Chaveze0ba4ce2017-07-20 15:12:22 -070035/*
36 * A hook that can be used to execute code at various events during minijail
37 * setup in the forked process. These can only be used if the jailed process is
38 * not going to be invoked with LD_PRELOAD.
39 *
40 * If the return value is non-zero, it will be interpreted as -errno and the
41 * process will abort.
42 */
43typedef int (*minijail_hook_t)(void *context);
44
45/*
46 * The events during minijail setup in which hooks can run. All the events are
47 * run in the new process.
48 */
49typedef enum {
50 /* The hook will run just before dropping capabilities. */
51 MINIJAIL_HOOK_EVENT_PRE_DROP_CAPS,
52
53 /* The hook will run just before calling execve(2). */
54 MINIJAIL_HOOK_EVENT_PRE_EXECVE,
55
Jorge Lucangeli Obes06bba012019-01-25 11:12:30 -050056 /* The hook will run just before calling chroot(2) / pivot_root(2). */
Luis Hector Chavez64730af2017-09-13 13:18:59 -070057 MINIJAIL_HOOK_EVENT_PRE_CHROOT,
58
Luis Hector Chaveze0ba4ce2017-07-20 15:12:22 -070059 /* Sentinel for error checking. Must be last. */
60 MINIJAIL_HOOK_EVENT_MAX,
61} minijail_hook_event_t;
62
Elly Jonescd7a9042011-07-22 13:56:51 -040063/* Allocates a new minijail with no restrictions. */
64struct minijail *minijail_new(void);
65
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -080066/*
67 * These functions add restrictions to the minijail. They are not applied until
Elly Jonescd7a9042011-07-22 13:56:51 -040068 * minijail_enter() is called. See the documentation in minijail0.1 for
Elly Jonese1749eb2011-10-07 13:54:59 -040069 * explanations in detail of what the restrictions do.
70 */
Elly Jonescd7a9042011-07-22 13:56:51 -040071void minijail_change_uid(struct minijail *j, uid_t uid);
72void minijail_change_gid(struct minijail *j, gid_t gid);
Jorge Lucangeli Obesd16ac492015-12-03 14:44:35 -080073/* Copies |list|. */
Jorge Lucangeli Obesbc67f442016-01-08 14:43:45 -080074void minijail_set_supplementary_gids(struct minijail *j, size_t size,
75 const gid_t *list);
Lutz Justen13807cb2017-01-03 17:11:55 +010076void minijail_keep_supplementary_gids(struct minijail *j);
Will Drewry2ddaad02011-09-16 11:36:08 -050077/* Stores user to change to and copies |user| for internal consistency. */
Elly Jonescd7a9042011-07-22 13:56:51 -040078int minijail_change_user(struct minijail *j, const char *user);
Will Drewry2ddaad02011-09-16 11:36:08 -050079/* Does not take ownership of |group|. */
Elly Jonescd7a9042011-07-22 13:56:51 -040080int minijail_change_group(struct minijail *j, const char *group);
81void minijail_use_seccomp(struct minijail *j);
Jorge Lucangeli Obesc2c9bcc2012-05-01 09:30:24 -070082void minijail_no_new_privs(struct minijail *j);
Will Drewry32ac9f52011-08-18 21:36:27 -050083void minijail_use_seccomp_filter(struct minijail *j);
Jorge Lucangeli Obes13650612016-09-02 11:27:29 -040084void minijail_set_seccomp_filter_tsync(struct minijail *j);
Luis Hector Chavezc3e17722018-10-16 20:43:12 -070085/* Does not take ownership of |filter|. */
86void minijail_set_seccomp_filters(struct minijail *j,
87 const struct sock_fprog *filter);
Will Drewry32ac9f52011-08-18 21:36:27 -050088void minijail_parse_seccomp_filters(struct minijail *j, const char *path);
Jorge Lucangeli Obes4d4b3be2016-08-16 16:58:14 -040089void minijail_parse_seccomp_filters_from_fd(struct minijail *j, int fd);
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070090void minijail_log_seccomp_filter_failures(struct minijail *j);
Jorge Lucangeli Obesf9fcdbe2016-02-19 15:04:09 -080091/* 'minijail_use_caps' and 'minijail_capbset_drop' are mutually exclusive. */
Elly Jonescd7a9042011-07-22 13:56:51 -040092void minijail_use_caps(struct minijail *j, uint64_t capmask);
Jorge Lucangeli Obesf9fcdbe2016-02-19 15:04:09 -080093void minijail_capbset_drop(struct minijail *j, uint64_t capmask);
Jorge Lucangeli Obesa6eb21a2017-04-20 10:44:00 -040094/* 'minijail_set_ambient_caps' requires 'minijail_use_caps'. */
95void minijail_set_ambient_caps(struct minijail *j);
Peter Qiu2860c462015-12-16 15:13:06 -080096void minijail_reset_signal_mask(struct minijail *j);
Luis Hector Chaveza27118a2018-04-04 08:18:01 -070097void minijail_reset_signal_handlers(struct minijail *j);
Elly Jonescd7a9042011-07-22 13:56:51 -040098void minijail_namespace_vfs(struct minijail *j);
Jorge Lucangeli Obes1563b5b2014-07-10 07:01:53 -070099void minijail_namespace_enter_vfs(struct minijail *j, const char *ns_path);
Chirantan Ekbote866bb3a2017-02-07 12:26:42 -0800100void minijail_new_session_keyring(struct minijail *j);
Luis Hector Chavezec0a2c12017-06-29 20:29:57 -0700101void minijail_skip_setting_securebits(struct minijail *j,
102 uint64_t securebits_skip_mask);
Chirantan Ekbote866bb3a2017-02-07 12:26:42 -0800103
Jorge Lucangeli Obesa521bee2016-03-03 13:47:57 -0800104/*
105 * This option is *dangerous* as it negates most of the functionality of
106 * minijail_namespace_vfs(). You very likely don't need this.
107 */
108void minijail_skip_remount_private(struct minijail *j);
Mike Frysinger785b1c32018-02-23 15:47:24 -0500109void minijail_remount_mode(struct minijail *j, unsigned long mode);
Dylan Reidf7942472015-11-18 17:55:26 -0800110void minijail_namespace_ipc(struct minijail *j);
Mike Frysingerb9a7b162017-05-30 15:25:49 -0400111void minijail_namespace_uts(struct minijail *j);
112int minijail_namespace_set_hostname(struct minijail *j, const char *name);
Elly Fong-Jones6c086302013-03-20 17:15:28 -0400113void minijail_namespace_net(struct minijail *j);
Dylan Reid1102f5a2015-09-15 11:52:20 -0700114void minijail_namespace_enter_net(struct minijail *j, const char *ns_path);
Dylan Reid4cbc2a52016-06-17 19:06:07 -0700115void minijail_namespace_cgroups(struct minijail *j);
Luis Hector Chavez43ff0802016-10-07 12:21:07 -0700116/* Closes all open file descriptors after forking. */
117void minijail_close_open_fds(struct minijail *j);
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800118/*
119 * Implies namespace_vfs and remount_proc_readonly.
Elly Jones761b7412012-06-13 15:49:52 -0400120 * WARNING: this is NOT THREAD SAFE. See the block comment in </libminijail.c>.
121 */
Elly Jonescd7a9042011-07-22 13:56:51 -0400122void minijail_namespace_pids(struct minijail *j);
Jorge Lucangeli Obes2fa96d12019-02-05 10:51:57 -0500123/*
124 * Implies namespace_vfs.
125 * WARNING: this is NOT THREAD SAFE. See the block comment in </libminijail.c>.
126 * Minijail will by default remount /proc read-only when using a PID namespace.
127 * Certain complex applications expect to be able to do their own sandboxing
128 * which might require writing to /proc, so support a weaker version of PID
129 * namespacing with a RW /proc.
130 */
131void minijail_namespace_pids_rw_proc(struct minijail *j);
Yu-Hsi Chiang10e91232015-08-05 14:40:45 +0800132void minijail_namespace_user(struct minijail *j);
Jorge Lucangeli Obes200299c2016-09-23 15:21:57 -0400133void minijail_namespace_user_disable_setgroups(struct minijail *j);
Yu-Hsi Chiang10e91232015-08-05 14:40:45 +0800134int minijail_uidmap(struct minijail *j, const char *uidmap);
135int minijail_gidmap(struct minijail *j, const char *gidmap);
Dylan Reid791f5772015-09-14 20:02:42 -0700136void minijail_remount_proc_readonly(struct minijail *j);
Yu-Hsi Chiang3e954ec2015-07-28 16:48:14 +0800137void minijail_run_as_init(struct minijail *j);
Yu-Hsi Chiang3cc05ea2015-08-11 11:23:17 +0800138int minijail_write_pid_file(struct minijail *j, const char *path);
Elly Jonescd7a9042011-07-22 13:56:51 -0400139void minijail_inherit_usergroups(struct minijail *j);
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800140/*
141 * Changes the jailed process's syscall table to the alt_syscall table
Andrew Brestickereac28942015-11-11 16:04:46 -0800142 * named |table|.
143 */
144int minijail_use_alt_syscall(struct minijail *j, const char *table);
Elly Jonescd7a9042011-07-22 13:56:51 -0400145
Dylan Reid0f72ef42017-06-06 15:42:49 -0700146/* Sets the given runtime limit. See getrlimit(2). */
Luis Hector Chavez7058a2d2018-01-29 08:41:34 -0800147int minijail_rlimit(struct minijail *j, int type, rlim_t cur, rlim_t max);
Dylan Reid0f72ef42017-06-06 15:42:49 -0700148
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800149/*
Dylan Reid605ce7f2016-01-19 19:21:00 -0800150 * Adds the jailed process to the cgroup given by |path|. |path| should be the
151 * full path to the cgroups "tasks" file.
152 * Example: /sys/fs/cgroup/cpu/jailed_procs/tasks adds to the "jailed_procs" cpu
153 * cgroup.
154 */
155int minijail_add_to_cgroup(struct minijail *j, const char *path);
156
157/*
Jorge Lucangeli Obesdba62092017-05-18 17:10:23 -0400158 * Install signal handlers in the minijail process that forward received
159 * signals to the jailed child process.
160 */
161int minijail_forward_signals(struct minijail *j);
162
163/*
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800164 * minijail_enter_chroot: enables chroot() restriction for @j
Elly Jones51a5b6c2011-10-12 19:09:26 -0400165 * @j minijail to apply restriction to
166 * @dir directory to chroot() to. Owned by caller.
167 *
168 * Enters @dir, binding all bind mounts specified with minijail_bind() into
169 * place. Requires @dir to contain all necessary directories for bind mounts
170 * (i.e., if you have requested a bind mount at /etc, /etc must exist in @dir.)
171 *
172 * Returns 0 on success.
173 */
174int minijail_enter_chroot(struct minijail *j, const char *dir);
Yu-Hsi Chiang64d65a72015-08-13 17:43:27 +0800175int minijail_enter_pivot_root(struct minijail *j, const char *dir);
Elly Jones51a5b6c2011-10-12 19:09:26 -0400176
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800177/*
178 * minijail_get_original_path: returns the path of a given file outside of the
Dylan Reid08946cc2015-09-16 19:10:57 -0700179 * chroot.
180 * @j minijail to obtain the path from.
181 * @chroot_path path inside of the chroot() to.
182 *
183 * When executing a binary in a chroot or pivot_root, return path to the binary
184 * outside of the chroot.
185 *
186 * Returns a string containing the path. This must be freed by the caller.
187 */
188char *minijail_get_original_path(struct minijail *j, const char *chroot_path);
189
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800190/*
Martin Pelikánab9eb442017-01-25 11:53:58 +1100191 * minijail_mount_tmp: enables mounting of a 64M tmpfs filesystem on /tmp.
Lee Campbell11af0622014-05-22 12:36:04 -0700192 * As be rules of bind mounts, /tmp must exist in chroot.
193 */
194void minijail_mount_tmp(struct minijail *j);
195
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800196/*
Martin Pelikánab9eb442017-01-25 11:53:58 +1100197 * minijail_mount_tmp_size: enables mounting of a tmpfs filesystem on /tmp.
198 * As be rules of bind mounts, /tmp must exist in chroot. Size is in bytes.
199 */
200void minijail_mount_tmp_size(struct minijail *j, size_t size);
201
202/*
Mike Frysinger33ffef32017-01-13 19:53:19 -0500203 * minijail_mount_dev: enables mounting of a tmpfs filesystem on /dev.
204 * It will then be seeded with a basic set of device nodes. For the exact
205 * list, consult the minijail(0) man page.
206 */
207void minijail_mount_dev(struct minijail *j);
208
209/*
Dylan Reid81e23972016-05-18 14:06:35 -0700210 * minijail_mount_with_data: when entering minijail @j,
211 * mounts @src at @dst with @flags and @data.
212 * @j minijail to bind inside
213 * @src source to bind
214 * @dest location to bind (inside chroot)
215 * @type type of filesystem
216 * @flags flags passed to mount
217 * @data data arguments passed to mount(2), e.g. "mode=755"
218 *
219 * This may be called multiple times; all mounts will be applied in the order
220 * of minijail_mount() calls.
Mike Frysingercb8674d2018-08-12 00:53:35 -0400221 * If @flags is 0, then MS_NODEV | MS_NOEXEC | MS_NOSUID will be used instead.
Mike Frysingerb7803c82018-08-23 15:43:15 -0400222 * If @data is NULL or "", and @type is tmpfs, then "mode=0755,size=10M" will
223 * be used instead.
Dylan Reid81e23972016-05-18 14:06:35 -0700224 */
225int minijail_mount_with_data(struct minijail *j, const char *src,
226 const char *dest, const char *type,
227 unsigned long flags, const char *data);
228
229/*
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800230 * minijail_mount: when entering minijail @j, mounts @src at @dst with @flags
Dylan Reid648b2202015-10-23 00:50:00 -0700231 * @j minijail to bind inside
232 * @src source to bind
233 * @dest location to bind (inside chroot)
234 * @type type of filesystem
235 * @flags flags passed to mount
236 *
Dylan Reid81e23972016-05-18 14:06:35 -0700237 * This may be called multiple times; all mounts will be applied in the order
Dylan Reid648b2202015-10-23 00:50:00 -0700238 * of minijail_mount() calls.
239 */
240int minijail_mount(struct minijail *j, const char *src, const char *dest,
Jorge Lucangeli Obesd16ac492015-12-03 14:44:35 -0800241 const char *type, unsigned long flags);
Dylan Reid648b2202015-10-23 00:50:00 -0700242
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800243/*
244 * minijail_bind: bind-mounts @src into @j as @dest, optionally writeable
Elly Jones51a5b6c2011-10-12 19:09:26 -0400245 * @j minijail to bind inside
246 * @src source to bind
247 * @dest location to bind (inside chroot)
248 * @writeable 1 if the bind mount should be writeable
249 *
250 * This may be called multiple times; all bindings will be applied in the order
251 * of minijail_bind() calls.
252 */
253int minijail_bind(struct minijail *j, const char *src, const char *dest,
Jorge Lucangeli Obes2f61ee42014-06-16 11:08:18 -0700254 int writeable);
Elly Jones51a5b6c2011-10-12 19:09:26 -0400255
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800256/*
Luis Hector Chaveze0ba4ce2017-07-20 15:12:22 -0700257 * minijail_add_hook: adds @hook to the list of hooks that will be
258 * invoked when @event is reached during minijail setup. The caller is
259 * responsible for the lifetime of @payload.
260 * @j minijail to add the hook to
261 * @hook the function that will be invoked
262 * @payload an opaque pointer
263 * @event the event that will trigger the hook
264 */
265int minijail_add_hook(struct minijail *j,
266 minijail_hook_t hook, void *payload,
267 minijail_hook_event_t event);
268
269/*
Luis Hector Chavez1617f632017-08-01 18:32:30 -0700270 * minijail_preserve_fd: preserves @parent_fd and makes it available as
271 * @child_fd in the child process. @parent_fd will be closed if no other
272 * redirect has claimed it as a @child_fd. This works even if
273 * minijail_close_open_fds() is invoked.
274 * @j minijail to add the fd to
275 * @parent_fd the fd in the parent process
276 * @child_fd the fd that will be available in the child process
277 */
278int minijail_preserve_fd(struct minijail *j, int parent_fd, int child_fd);
279
280/*
Luis Hector Chavez9acba452018-10-11 10:13:25 -0700281 * minijail_set_preload_path: overrides the default path for
282 * libminijailpreload.so.
283 */
284int minijail_set_preload_path(struct minijail *j, const char *preload_path);
285
286/*
Jorge Lucangeli Obesdeca9f22016-07-01 09:49:39 -0400287 * Lock this process into the given minijail. Note that this procedure cannot
288 * fail, since there is no way to undo privilege-dropping; therefore, if any
289 * part of the privilege-drop fails, minijail_enter() will abort the entire
290 * process.
Elly Jonescd7a9042011-07-22 13:56:51 -0400291 *
292 * Some restrictions cannot be enabled this way (pid namespaces) and attempting
293 * to do so will cause an abort.
294 */
295void minijail_enter(const struct minijail *j);
296
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800297/*
Dylan Reid0412dcc2017-08-24 11:33:15 -0700298 * Run the specified command in the given minijail, execve(2)-style.
299 * If minijail_namespace_pids() or minijail_namespace_user() are used,
300 * this or minijail_fork() is required instead of minijail_enter().
Elly Jonese1749eb2011-10-07 13:54:59 -0400301 */
302int minijail_run(struct minijail *j, const char *filename,
303 char *const argv[]);
Elly Jonescd7a9042011-07-22 13:56:51 -0400304
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800305/*
306 * Run the specified command in the given minijail, execve(2)-style.
Jorge Lucangeli Obesd2c951d2019-02-01 15:43:36 -0500307 * Don't use LD_PRELOAD to do privilege dropping. This is useful when sandboxing
308 * static binaries, or on systems without support for LD_PRELOAD.
Lee Campbell1e4fc6a2014-06-06 17:40:02 -0700309 */
Jorge Lucangeli Obes54714502015-09-30 10:08:45 -0700310int minijail_run_no_preload(struct minijail *j, const char *filename,
311 char *const argv[]);
Lee Campbell1e4fc6a2014-06-06 17:40:02 -0700312
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800313/*
314 * Run the specified command in the given minijail, execve(2)-style.
Jorge Lucangeli Obes9807d032012-04-17 13:36:00 -0700315 * Update |*pchild_pid| with the pid of the child.
316 */
317int minijail_run_pid(struct minijail *j, const char *filename,
318 char *const argv[], pid_t *pchild_pid);
319
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800320/*
321 * Run the specified command in the given minijail, execve(2)-style.
Jorge Lucangeli Obesdf4bd352012-08-29 19:12:28 -0700322 * Update |*pstdin_fd| with a fd that allows writing to the child's
323 * standard input.
324 */
325int minijail_run_pipe(struct minijail *j, const char *filename,
326 char *const argv[], int *pstdin_fd);
327
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800328/*
329 * Run the specified command in the given minijail, execve(2)-style.
Jorge Lucangeli Obesdf4bd352012-08-29 19:12:28 -0700330 * Update |*pchild_pid| with the pid of the child.
331 * Update |*pstdin_fd| with a fd that allows writing to the child's
332 * standard input.
Jorge Lucangeli Obes339a1132013-02-15 16:53:47 -0800333 * Update |*pstdout_fd| with a fd that allows reading from the child's
334 * standard output.
335 * Update |*pstderr_fd| with a fd that allows reading from the child's
336 * standard error.
337 */
338int minijail_run_pid_pipes(struct minijail *j, const char *filename,
339 char *const argv[], pid_t *pchild_pid,
340 int *pstdin_fd, int *pstdout_fd, int *pstderr_fd);
341
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800342/*
343 * Run the specified command in the given minijail, execve(2)-style.
Samuel Tan63187f42015-10-16 13:01:53 -0700344 * Update |*pchild_pid| with the pid of the child.
345 * Update |*pstdin_fd| with a fd that allows writing to the child's
346 * standard input.
347 * Update |*pstdout_fd| with a fd that allows reading from the child's
348 * standard output.
349 * Update |*pstderr_fd| with a fd that allows reading from the child's
350 * standard error.
Jorge Lucangeli Obesd2c951d2019-02-01 15:43:36 -0500351 * Don't use LD_PRELOAD to do privilege dropping. This is useful when sandboxing
352 * static binaries, or on systems without support for LD_PRELOAD.
Samuel Tan63187f42015-10-16 13:01:53 -0700353 */
354int minijail_run_pid_pipes_no_preload(struct minijail *j, const char *filename,
355 char *const argv[], pid_t *pchild_pid,
Jorge Lucangeli Obes43a6a862015-12-04 14:53:36 -0800356 int *pstdin_fd, int *pstdout_fd,
357 int *pstderr_fd);
Samuel Tan63187f42015-10-16 13:01:53 -0700358
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800359/*
Jorge Lucangeli Obesd2c951d2019-02-01 15:43:36 -0500360 * Run the specified command in the given minijail, execve(2)-style.
361 * Pass |envp| as the full environment for the child.
362 * Update |*pchild_pid| with the pid of the child.
363 * Update |*pstdin_fd| with a fd that allows writing to the child's
364 * standard input.
365 * Update |*pstdout_fd| with a fd that allows reading from the child's
366 * standard output.
367 * Update |*pstderr_fd| with a fd that allows reading from the child's
368 * standard error.
369 * Don't use LD_PRELOAD to do privilege dropping. This is useful when sandboxing
370 * static binaries, or on systems without support for LD_PRELOAD.
371 */
372int minijail_run_env_pid_pipes_no_preload(struct minijail *j,
373 const char *filename,
374 char *const argv[],
375 char *const envp[], pid_t *pchild_pid,
376 int *pstdin_fd, int *pstdout_fd,
377 int *pstderr_fd);
378
379/*
Dylan Reid0412dcc2017-08-24 11:33:15 -0700380 * Fork, jail the child, and return. This behaves similar to fork(2), except it
381 * puts the child process in a jail before returning.
382 * `minijail_fork` returns in both the parent and the child. The pid of the
383 * child is returned to the parent. Zero is returned in the child. LD_PRELOAD
384 * is not supported.
385 * If minijail_namespace_pids() or minijail_namespace_user() are used,
386 * this or minijail_run*() is required instead of minijail_enter().
387 */
388pid_t minijail_fork(struct minijail *j);
389
390/*
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800391 * Kill the specified minijail. The minijail must have been created with pid
Elly Jonese1749eb2011-10-07 13:54:59 -0400392 * namespacing; if it was, all processes inside it are atomically killed.
393 */
Elly Jonescd7a9042011-07-22 13:56:51 -0400394int minijail_kill(struct minijail *j);
395
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800396/*
Jorge Lucangeli Obesdeca9f22016-07-01 09:49:39 -0400397 * Wait for all processes in the specified minijail to exit. Returns the exit
Elly Jonese1749eb2011-10-07 13:54:59 -0400398 * status of the _first_ process spawned in the jail.
399 */
Elly Jonescd7a9042011-07-22 13:56:51 -0400400int minijail_wait(struct minijail *j);
401
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800402/*
Jorge Lucangeli Obesdeca9f22016-07-01 09:49:39 -0400403 * Frees the given minijail. It does not matter if the process is inside the
404 * minijail or not.
Jorge Lucangeli Obesd0a6e2f2015-11-24 14:21:21 -0800405 */
Elly Jonescd7a9042011-07-22 13:56:51 -0400406void minijail_destroy(struct minijail *j);
407
Luis Hector Chavez114a9302017-09-05 20:36:58 -0700408/*
409 * minijail_log_to_fd: redirects the module-wide logging to an FD instead of
410 * syslog.
411 * @fd FD to log to. Caller must ensure this is available after
412 * jailing (e.g. with minijail_preserve_fd()).
413 * @min_priority the minimum logging priority. Same as the priority argument
414 * to syslog(2).
415 */
416void minijail_log_to_fd(int fd, int min_priority);
417
Elly Jonescd7a9042011-07-22 13:56:51 -0400418#ifdef __cplusplus
Elly Jonese1749eb2011-10-07 13:54:59 -0400419}; /* extern "C" */
Elly Jonescd7a9042011-07-22 13:56:51 -0400420#endif
421
Elly Jonese1749eb2011-10-07 13:54:59 -0400422#endif /* !_LIBMINIJAIL_H_ */