Skip to content

Commit

Permalink
mqtt: de-permission publish callback capabilities.
Browse files Browse the repository at this point in the history
The `topic` and `payload` capabilities of the publish callback are only
valid within the context of the callback. They should thus passed as a
read-only, non-capturable capabilities.

Currently we pass them as capturable and writable capabilities, which
may allow API users to compromise the MQTT compartment.

This addresses issue #43.

Signed-off-by: Hugo Lefeuvre <[email protected]>
  • Loading branch information
hlef committed Oct 22, 2024
1 parent a9a540b commit d216e33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* will be called on all PUBLISH notifications from the broker.
*
* `topicName` and `payload` (and their respective size arguments) indicate the
* topic of the PUBLISH, and the corresponding payload.
* topic of the PUBLISH, and the corresponding payload. Both are only valid
* within the context of the callback and thus passed as a read-only,
* non-capturable capabilities.
*/
typedef void __cheri_callback (*MQTTPublishCallback)(const char *topicName,
size_t topicNameLength,
Expand Down
12 changes: 10 additions & 2 deletions lib/mqtt/mqtt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,17 @@ namespace
"The packet is of type PUBLISH, but topic or payload "
"are not set.");

publishCallback(publishInfo->pTopicName,
// The payload and topic are only valid within the
// context of the callback: make them read-only and
// non-capturable.
Capability topic{publishInfo->pTopicName};
Capability payload{publishInfo->pPayload};
topic.permissions() &= CHERI::Permission::Load;
payload.permissions() &= CHERI::Permission::Load;

publishCallback(topic,
publishInfo->topicNameLength,
publishInfo->pPayload,
payload,
publishInfo->payloadLength);
}
else if (ackCallback)
Expand Down

0 comments on commit d216e33

Please sign in to comment.