blob: 7926380f7a741a1c7d6c527e061b8af037a88026 [file] [log] [blame]
Jeff Vander Stoepc9ea2112016-02-17 10:52:20 -08001/*
2**
3** Copyright 2016, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
Mark Salyzyn60d02072016-09-29 08:48:48 -070018#define LOG_TAG "minijail"
19
20#include <unistd.h>
21
22#include <android/log.h>
Jeff Vander Stoepc9ea2112016-02-17 10:52:20 -080023#include <libminijail.h>
24
25#include "minijail.h"
26
27namespace android {
28
29/* Must match location in Android.mk */
30static const char kSeccompFilePath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy";
31
32int MiniJail()
33{
34 /* no seccomp policy for this architecture */
35 if (access(kSeccompFilePath, R_OK) == -1) {
36 ALOGW("No seccomp filter defined for this architecture.");
37 return 0;
38 }
39
40 struct minijail *jail = minijail_new();
41 if (jail == NULL) {
42 ALOGW("Failed to create minijail.");
43 return -1;
44 }
45
46 minijail_no_new_privs(jail);
47 minijail_log_seccomp_filter_failures(jail);
48 minijail_use_seccomp_filter(jail);
49 minijail_parse_seccomp_filters(jail, kSeccompFilePath);
50 minijail_enter(jail);
51 minijail_destroy(jail);
52 return 0;
53}
54}