blob: 463f1617d0deef4d9e8c55ccd7b276accb688da4 [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
Mark Salyzyne74bbf12017-01-12 15:10:27 -080022#include <log/log.h>
23
Jeff Vander Stoepc9ea2112016-02-17 10:52:20 -080024#include <libminijail.h>
25
26#include "minijail.h"
27
28namespace android {
29
30/* Must match location in Android.mk */
31static const char kSeccompFilePath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy";
32
33int MiniJail()
34{
35 /* no seccomp policy for this architecture */
36 if (access(kSeccompFilePath, R_OK) == -1) {
37 ALOGW("No seccomp filter defined for this architecture.");
38 return 0;
39 }
40
41 struct minijail *jail = minijail_new();
42 if (jail == NULL) {
43 ALOGW("Failed to create minijail.");
44 return -1;
45 }
46
47 minijail_no_new_privs(jail);
48 minijail_log_seccomp_filter_failures(jail);
49 minijail_use_seccomp_filter(jail);
50 minijail_parse_seccomp_filters(jail, kSeccompFilePath);
51 minijail_enter(jail);
52 minijail_destroy(jail);
53 return 0;
54}
55}