1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <string.h>
16 #include "init_module_engine.h"
17 #include "plugin_adapter.h"
18 #include "seccomp_policy.h"
19
SetSystemSeccompPolicy(int id,const char * name,int argc,const char ** argv)20 static int SetSystemSeccompPolicy(int id, const char *name, int argc, const char **argv)
21 {
22 PLUGIN_LOGI("SetSystemSeccompPolicy argc %d %s", argc, name);
23 PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
24
25 bool ret = SetSeccompPolicyWithName(SYSTEM_NAME);
26 PLUGIN_CHECK(ret == true, return -1, "SetSystemSeccompPolicy failed");
27
28 return 0;
29 }
30
31 static int32_t g_executorId = -1;
SetSeccompPolicyInit(void)32 static int SetSeccompPolicyInit(void)
33 {
34 if (g_executorId == -1) {
35 g_executorId = AddCmdExecutor("SetSeccompPolicy", SetSystemSeccompPolicy);
36 PLUGIN_LOGI("SetSeccompPolicy executorId %d", g_executorId);
37 }
38 return 0;
39 }
40
SeccompHook(const HOOK_INFO * info,void * cookie)41 static int SeccompHook(const HOOK_INFO *info, void *cookie)
42 {
43 SetSeccompPolicyInit();
44 PLUGIN_LOGI("seccomp enabled.");
45 return 0;
46 }
47
MODULE_CONSTRUCTOR(void)48 MODULE_CONSTRUCTOR(void)
49 {
50 InitAddPostPersistParamLoadHook(0, SeccompHook);
51 }
52