1 /*
2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12 #include <common/types.h>
13 #include <object/thread.h>
14 #include <object/cap_group.h>
15
16 /*
17 * The syscall hooks can offer several features.
18 * First, authorize the badge of the caller for the privileged syscalls.
19 * Second, ease of debugging or export more information.
20 */
21
hook_sys_create_device_pmo(unsigned long paddr,unsigned long size)22 int hook_sys_create_device_pmo(unsigned long paddr, unsigned long size)
23 {
24 /* This one is provided for user-level drivers only. */
25 /*
26 if (current_cap_group->badge >= APP_BADGE_START
27 || current_cap_group->badge < DRIVER_BADGE_START) {
28 kwarn("An unthorized process tries to create device pmo.\n");
29 return -EPERM;
30 }
31 */
32 return 0;
33 }
34
hook_sys_get_phys_addr(vaddr_t va,paddr_t * pa_buf)35 int hook_sys_get_phys_addr(vaddr_t va, paddr_t *pa_buf)
36 {
37 /* This one is only used in drivers and unit test now. */
38 if (current_cap_group->badge >= APP_BADGE_START
39 || current_cap_group->badge < DRIVER_BADGE_START) {
40 kwarn("An unthorized process tries to get phys addr.\n");
41 return -EPERM;
42 }
43 return 0;
44 }
45
hook_sys_create_cap_group(unsigned long cap_group_args_p)46 int hook_sys_create_cap_group(unsigned long cap_group_args_p)
47 {
48 if ((current_cap_group->badge != ROOT_CAP_GROUP_BADGE)
49 && (current_cap_group->badge != FSM_BADGE)
50 && (current_cap_group->badge != PROCMGR_BADGE)) {
51 kwarn("An unthorized process tries to create cap_group.\n");
52 return -EPERM;
53 }
54 return 0;
55 }
56
hook_sys_register_recycle(cap_t notifc_cap,vaddr_t msg_buffer)57 int hook_sys_register_recycle(cap_t notifc_cap, vaddr_t msg_buffer)
58 {
59 if (current_cap_group->badge != PROCMGR_BADGE) {
60 kwarn("A process (not the procmgr) tries to register recycle.\n");
61 return -EPERM;
62 }
63 return 0;
64 }
65
hook_sys_cap_group_recycle(cap_t cap_group_cap)66 int hook_sys_cap_group_recycle(cap_t cap_group_cap)
67 {
68 if (current_cap_group->badge != PROCMGR_BADGE) {
69 kwarn("A process (not the procmgr) tries to register recycle.\n");
70 return -EPERM;
71 }
72 return 0;
73 }
74