blob: 1f5c414ec33faf75927e1877cd06170e24f0be4e [file] [log] [blame]
Elly Jonescd7a9042011-07-22 13:56:51 -04001/* libminijail-private.h
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 *
6 * Values shared between libminijailpreload and libminijail, but not visible to
7 * the outside world.
8 */
9
10#ifndef LIBMINIJAIL_PRIVATE_H
11#define LIBMINIJAIL_PRIVATE_H
12
Will Drewry2f54b6a2011-09-16 13:45:31 -050013static const char *kFdEnvVar = "__MINIJAIL_FD";
Ben Chan541c7e52011-08-26 14:55:53 -070014static const char *kLdPreloadEnvVar = "LD_PRELOAD";
Elly Jonescd7a9042011-07-22 13:56:51 -040015
Will Drewry32ac9f52011-08-18 21:36:27 -050016#define MINIJAIL_MAX_SECCOMP_FILTER_LINE 512
Will Drewry2f54b6a2011-09-16 13:45:31 -050017#define MINIJAIL_MAX_ARG_LINE (MINIJAIL_MAX_SECCOMP_FILTER_LINE + 64)
Will Drewry32ac9f52011-08-18 21:36:27 -050018
Will Drewry2ddaad02011-09-16 11:36:08 -050019struct seccomp_filter {
20 int nr;
21 char *filter;
22 struct seccomp_filter *next, *prev;
23};
24
25struct minijail {
26 struct {
27 int uid : 1;
28 int gid : 1;
29 int caps : 1;
30 int vfs : 1;
31 int pids : 1;
32 int seccomp : 1;
33 int readonly : 1;
34 int usergroups : 1;
35 int ptrace : 1;
36 int seccomp_filter : 1;
37 } flags;
38 uid_t uid;
39 gid_t gid;
40 gid_t usergid;
41 char *user;
42 uint64_t caps;
43 pid_t initpid;
44 struct seccomp_filter *filters;
45};
46
47/* minijail_size returns the size of |j| if marshalled.
48 * 0 is returned on error.
49 */
50extern size_t minijail_size(const struct minijail *j);
51/* minijail_marshal: serializes |j| to |buf|
52 * Writes |j| to |buf| such that it can be reparsed by the same
53 * library on the same architecture. This is meant to be used
54 * by minijail0.c and libminijailpreload.c. minijail flags that
55 * require minijail_run() will be excluded.
56 *
57 * The marshalled data is not robust to differences between the child
58 * and parent process (personality, etc).
59 *
60 * Returns 0 on success.
61 */
62extern int minijail_marshal(const struct minijail *j,
63 char *buf,
64 size_t available);
65/* minijail_unmarshal: initializes minijail |j| from |serialized|. */
66extern int minijail_unmarshal(struct minijail *j,
67 char *serialized,
68 size_t length);
Will Drewryfe4a3722011-09-16 14:50:50 -050069/* Using minijail_unmarshal, build |j| from |fd|. */
70extern int minijail_from_fd(int fd, struct minijail *j);
71/* Using minijail_marshal, sends |j| to |fd|. */
72extern int minijail_to_fd(struct minijail *j, int fd);
73/* minijail_preexec: strips |j| of all options handled by minijail_enter(). */
74extern void minijail_preexec(struct minijail *j);
Will Drewry2ddaad02011-09-16 11:36:08 -050075/* minijail_preenter: strips |j| of all options handled by minijail_run(). */
76extern void minijail_preenter(struct minijail *j);
77
Elly Jonescd7a9042011-07-22 13:56:51 -040078#endif /* !LIBMINIJAIL_PRIVATE_H */