You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2025-01-09-capabilities-not-trust-third-party.markdown
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -24,18 +24,20 @@ int __cheri_compartment("MQTT") mqtt_publish(Timeout *t,
24
24
```
25
25
26
26
and has the following comment about their scope:
27
-
28
-
_Both the topic and payload buffers must remain valid during the execution of this function._
29
-
_If the caller frees them during the execution of this function, the publish may leak application data to the broker through the topic and payload._
27
+
>```
28
+
>Both the topic and payload buffers must remain valid during the execution of this function.
29
+
>If the caller frees them during the execution of this function, the publish may leak application data to the broker through the topic and payload.
30
+
>```
30
31
31
32
Ok, so it seems clear that I only need to make sure that they remain valid and unchanged until the call returns, but I was hitting a bug that seemed to suggest they might be being used outside of that by another thread in the network stack.
32
-
_It turns out I was wrong about that BTW, but anyway I'm a suspicious kind of guy when it comes to trusting external modules._
33
-
A quick look through the code quickly persuaded me that a) I'm not very good at reading other peoples code and b) it was probably not the issue but I still wanted to rule it out.
33
+
> _It turns out I was wrong about that BTW, but anyway I'm a suspicious kind of guy when it comes to trusting external modules._
34
+
35
+
A quick look through the code quickly persuaded me that: a) I'm not very good at reading other people's code; and b) it was probably not the issue but I still wanted to rule it out.
34
36
35
37
Luckily by thinking of these in terms of capabilities rather than pointers I can directly implement my intent rather that trust what the library is telling me.
36
38
Specifically I can derive new capabilities that are read only and can't be captured.
37
39
So I can be guaranteed that at the end of the call nothing in the network stack can have modified the message or saved a reference to it.
38
-
And for good measure I can also limit the bounds so that I don't have to trust that the MQTT code will only read within topicLength and payloadLength.
40
+
And for good measure I can also limit the bounds so that I don't have to trust that the MQTT code will only read within `topicLength` and `payloadLength`.
39
41
This is what the resulting code looks like in my demo:
40
42
41
43
```c++
@@ -87,5 +89,5 @@ Using the following would instead return an invalid capability if `statusLength`
87
89
88
90
89
91
So by explicitly using the extra controls that CHERIoT provides we can eliminate any trust relationship between our code and some third party module and its compilation environment.
90
-
The CHERI processor will guarantee that the MQTT library can only use the pointers we supply in the way we intend it to, even if the library is implemented to make use of compiler escape hatches such as "unsafe".
92
+
The CHERI processor will guarantee that the MQTT library can only use the pointers we supply in the way we intend it to, even if the library is implemented to make use of compiler escape hatches such as "`unsafe`".
91
93
And that's a significant step forwards in creating safe and reliable systems.
0 commit comments