-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcap.c
More file actions
81 lines (72 loc) · 1.66 KB
/
Copy pathcap.c
File metadata and controls
81 lines (72 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Capability manipulation syscall.
*
* The entry to Codezero security
* mechanisms.
*
* Copyright (C) 2009 Bahadir Balban
*/
#include <l4/api/capability.h>
#include <l4/generic/capability.h>
#include <l4/generic/cap-types.h>
#include <l4/generic/container.h>
#include <l4/generic/tcb.h>
#include <l4/api/errno.h>
#include INC_API(syscall.h)
/*
* Read all capabilitites of the current process.
* This includes the private ones as well as
* ones shared by other tasks that the task has
* rights to but doesn't own.
*/
int cap_read_all(struct capability *caparray)
{
struct capability *cap;
int capidx = 0;
list_foreach_struct(cap, ¤t->space->cap_list.caps, list) {
memcpy(&caparray[capidx], cap, sizeof(*cap));
capidx++;
}
list_foreach_struct(cap, &curcont->cap_list.caps, list) {
memcpy(&caparray[capidx], cap, sizeof(*cap));
capidx++;
}
return 0;
}
/*
* Read, manipulate capabilities.
*/
int sys_capability_control(unsigned int req, unsigned int flags, void *userbuf)
{
int err = 0;
/* Check access for each request */
switch(req) {
case CAP_CONTROL_NCAPS:
if ((err = check_access((unsigned long)userbuf,
sizeof(int),
MAP_USR_RW, 1)) < 0)
return err;
break;
case CAP_CONTROL_READ:
if ((err = check_access((unsigned long)userbuf,
cap_count(current) *
sizeof(struct capability),
MAP_USR_RW, 1)) < 0)
return err;
break;
default:
return -EINVAL;
}
/* Take action for each request */
switch(req) {
case CAP_CONTROL_NCAPS:
*((int *)userbuf) = cap_count(current);
break;
case CAP_CONTROL_READ:
err = cap_read_all((struct capability *)userbuf);
break;
default:
return -EINVAL;
}
return err;
}