2
* lxc: linux Container library
4
* (C) Copyright Canonical, Inc. 2012
7
* Serge Hallyn <serge.hallyn@canonical.com>
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include "lxcseccomp.h"
34
lxc_log_define(lxc_seccomp, lxc);
37
* The first line of the config file has a policy language version
38
* the second line has some directives
39
* then comes policy subject to the directives
40
* right now version must be '1'
41
* the directives must include 'whitelist' (only type of policy currently
42
* supported) and can include 'debug' (though debug is not yet supported).
44
static int parse_config(FILE *f, struct lxc_conf *conf)
49
ret = fscanf(f, "%d\n", &version);
50
if (ret != 1 || version != 1) {
51
ERROR("invalid version");
54
if (!fgets(line, 1024, f)) {
55
ERROR("invalid config file");
58
if (!strstr(line, "whitelist")) {
59
ERROR("only whitelist policy is supported");
62
if (strstr(line, "debug")) {
63
ERROR("debug not yet implemented");
66
/* now read in the whitelist entries one per line */
67
while (fgets(line, 1024, f)) {
69
ret = sscanf(line, "%d", &nr);
72
ret = seccomp_rule_add(SCMP_ACT_ALLOW, nr, 0);
74
ERROR("failed loading allow rule for %d\n", nr);
81
int lxc_read_seccomp_config(struct lxc_conf *conf)
86
if (seccomp_init(SCMP_ACT_ERRNO(31)) < 0) { /* for debug, pass in SCMP_ACT_TRAP */
87
ERROR("failed initializing seccomp");
93
/* turn of no-new-privs. We don't want it in lxc, and it breaks
95
if (seccomp_attr_set(SCMP_FLTATR_CTL_NNP, 0)) {
96
ERROR("failed to turn off n-new-privs\n");
100
f = fopen(conf->seccomp, "r");
102
SYSERROR("failed to open seccomp policy file %s\n", conf->seccomp);
105
ret = parse_config(f, conf);
110
int lxc_seccomp_load(struct lxc_conf *conf)
115
ret = seccomp_load();
117
ERROR("Error loading the seccomp policy");