Skip to content

Commit 589bfa3

Browse files
author
=josephproject1
committed
CHERI facilitates sweeping revocation technique
1 parent 24ca03a commit 589bfa3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<cheri.h>
2+
#include<stdio.h>
3+
int main() {
4+
5+
//create a capability to a memory region
6+
7+
int data[10] = {0};
8+
9+
cheri_object data_cap;
10+
11+
data_cap = cheri_build_data_cap(data, sizeof(data), CHERI_PERM_LOAD|CHERI_PERM_STORE);
12+
13+
//read and write access capability
14+
15+
int* cap_ptr = cheri_cast(int*, data_cap);
16+
17+
//read and write data
18+
19+
cap_ptr[0] = 42;
20+
21+
int value = cap_ptr[0];
22+
23+
printf("initial value: %d\n", value);
24+
25+
//let's simulate a security breach or a vulnerability detection
26+
27+
//decide to revoke or write access to the memory region
28+
29+
cheri_set_perms(&data_cap,CHERI_PERM_LOAD);//revoke write permissions
30+
31+
//attempting to write after revoking triggers an exception
32+
33+
//uncommenting this line would trigger a capability violation exception
34+
35+
//cap_ptr[1]=99;
36+
37+
//however,read access remains allowed
38+
39+
int read_value = cap_ptr[1];
40+
41+
printf("read only value: %d\n", read_value);
42+
43+
return 0;
44+
45+
46+
}
47+

0 commit comments

Comments
 (0)