repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
cheriot-rtos | github_2023 | cpp | 169 | CHERIoT-Platform | davidchisnall | @@ -65,6 +65,85 @@ namespace
}
}
+ /**
+ * Test that destructing a lock automatically wakes up all waiters,
+ * failing them to acquire the lock.
+ */
+ template<typename Lock>
+ void test_destruct_lock_wake_up(Lock &lock)
+ {
+ modified = false;
+
+ Timeout t{1};
+ lock.try_lock(&t);
+
+ // Try to acquir... | This isn't 10s, it's 10 scheduler ticks. On the FPGA, that's 100ms, in simulation it's some made-up equivalent of time. |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,25 @@
+# Constant: location of the custom tool binaries in the dev container | I was confused by the missing shbang in a .sh file. Maybe change the extension to .inc to indicate that this should not be run directly? Or move it to an `includes` directory? |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,80 @@
+#!/bin/bash | Nope. This should either be:
```
#!/bin/sh
```
```
#!/usr/bin/env bash
```
And we should not be using bash extensions in portable scripts, so it should be the former. |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,80 @@
+#!/bin/bash
+
+SCRIPT_DIRECTORY="$(dirname "$(realpath "$0")")"
+. ${SCRIPT_DIRECTORY}/helper_find_llvm_install.sh
+
+OBJDUMP=$(find_llvm_tool llvm-objdump)
+
+if [ ! -x ${OBJDUMP} ] ; then | It would be nice to have a second argument to `find_llvm_tool` for whether to fail if the tool is not found. I think in all of our current uses we want to print an error and have the script exit with a failure exit code if it can't find the tool. |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,80 @@
+#!/bin/bash
+
+SCRIPT_DIRECTORY="$(dirname "$(realpath "$0")")"
+. ${SCRIPT_DIRECTORY}/helper_find_llvm_install.sh
+
+OBJDUMP=$(find_llvm_tool llvm-objdump)
+
+if [ ! -x ${OBJDUMP} ] ; then
+ echo Unable to locate llvm-objdump, please set TOOLS_PATH to the directory containing the LLVM toolchain.
+ ex... | This doesn't need to be separate, just put it in the `END` block of the awk program. |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,80 @@
+#!/bin/bash
+
+SCRIPT_DIRECTORY="$(dirname "$(realpath "$0")")"
+. ${SCRIPT_DIRECTORY}/helper_find_llvm_install.sh
+
+OBJDUMP=$(find_llvm_tool llvm-objdump)
+
+if [ ! -x ${OBJDUMP} ] ; then
+ echo Unable to locate llvm-objdump, please set TOOLS_PATH to the directory containing the LLVM toolchain.
+ ex... | Same as below. |
cheriot-rtos | github_2023 | others | 172 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,80 @@
+#!/bin/bash
+
+SCRIPT_DIRECTORY="$(dirname "$(realpath "$0")")"
+. ${SCRIPT_DIRECTORY}/helper_find_llvm_install.sh
+
+OBJDUMP=$(find_llvm_tool llvm-objdump)
+
+if [ ! -x ${OBJDUMP} ] ; then
+ echo Unable to locate llvm-objdump, please set TOOLS_PATH to the directory containing the LLVM toolchain.
+ ex... | It would be good to have a more raw format (without the 'size of...' bits) as an option, so that we can have a CI script that records the size of each compartment and the total image in the test suite and lets us track code growth. |
cheriot-rtos | github_2023 | cpp | 173 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,21 @@
+// Copyright CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#pragma once
+#include <stddef.h>
+#include <stdint.h>
+#include <compartment-macros.h>
+
+/**
+ * C API for `check_pointer`.
+ *
+ * This function behaves identically to `CHERI::check_pointer`, but is exposed
+ * without templatin... | Please can you document this without reference to the C++ version (or with just a note for C++ people that they should consider the C++ version instead)? C programmers shouldn't have to read C++ code to understand what C APIs do. |
cheriot-rtos | github_2023 | others | 173 | CHERIoT-Platform | davidchisnall | @@ -4,5 +4,4 @@ Compartment helpers library
This library includes functions that help securing compartment boundaries.
- [`claim_fast.cc`] contains the `heap_claim_fast` function.
-
-
+- [`check_pointer.cc`] contains the `::check_pointer` function. | ```suggestion
- [`check_pointer.cc`] contains the `check_pointer` function.
```
We don't use :: in the document for anything else in the global namespace in these libraries. |
cheriot-rtos | github_2023 | cpp | 173 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,25 @@
+// Copyright CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#pragma once
+#include <compartment-macros.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/**
+ * Checks that `ptr` is valid, unsealed, does not overlap the caller's stack, | This contradicts the next paragraph. |
cheriot-rtos | github_2023 | cpp | 173 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,25 @@
+// Copyright CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#pragma once
+#include <compartment-macros.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/**
+ * Checks that `ptr` is valid, unsealed, does not overlap the caller's stack,
+ * has at least `rawPermissions`, and has at least `spac... | ```suggestion
* If the permissions do not include Global and `checkStackNeeded` is `false`, then this will also check that the
* capability does not point to the current thread's stack.
``` |
cheriot-rtos | github_2023 | others | 173 | CHERIoT-Platform | davidchisnall | @@ -759,6 +759,7 @@ function firmware(name)
add_rules("firmware")
-- TODO: Make linking the allocator optional.
add_deps(name .. ".scheduler", "cheriot.loader", "cheriot.switcher", "cheriot.allocator")
+ add_deps("compartment_helpers") | Don't unconditionally add an optional library to everything! |
cheriot-rtos | github_2023 | others | 176 | CHERIoT-Platform | davidchisnall | @@ -1016,31 +1016,104 @@ namespace CHERI
representable_length(size) == size;
}
+ /// Concept that matches pointers.
+ template<typename T>
+ concept IsPointer = std::is_pointer_v<T>;
+
+ /// Concept that matches classes which implements a `get` method
+ /// returning a pointer, and supports `operator=` wi... | Please can you make this a `/**` comment? We try to use `///` ones only for single-line comments. |
cheriot-rtos | github_2023 | others | 176 | CHERIoT-Platform | davidchisnall | @@ -1016,31 +1016,104 @@ namespace CHERI
representable_length(size) == size;
}
+ /// Concept that matches pointers.
+ template<typename T>
+ concept IsPointer = std::is_pointer_v<T>;
+
+ /// Concept that matches classes which implements a `get` method
+ /// returning a pointer, and supports `operator=` wi... | This is trying to match smart pointers, the term 'pointer container' is not one I've seen before. |
cheriot-rtos | github_2023 | cpp | 176 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,13 @@
+// Copyright CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#define TEST_NAME "Test check_pointer"
+#include "check_pointer.h"
+#include "tests.hh"
+
+int object;
+
+void test_check_pointer() | Why do you need two compartments for this test? |
cheriot-rtos | github_2023 | cpp | 176 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,129 @@
+// Copyright CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#define TEST_NAME "Test check_pointer (inner compartment)"
+#include "check_pointer.h"
+#include "tests.hh"
+#include <cheri.hh>
+
+using namespace CHERI;
+
+/**
+ * Test the `EnforceStrictPermissions` feature of `CHERI::check_poi... | As far as I can see, none of this needs to be in a nested compartment. |
cheriot-rtos | github_2023 | others | 176 | CHERIoT-Platform | davidchisnall | @@ -1016,31 +1016,110 @@ namespace CHERI
representable_length(size) == size;
}
+ /**
+ * Concept that matches pointers.
+ */
+ template<typename T>
+ concept IsPointer = std::is_pointer_v<T>;
+
+ /**
+ * Concept that matches smart pointers, i.e., classes which implements
+ * a `get` method returning a... | Can you factor this out earlier as:`
```c++
constexpr bool IsRawPointer = std::is_pointer_v<std::remove_cvref_t<decltype(ptr)>>;
```
The same check is used here and below and that makes it clearer that they're checking the same condition.
|
cheriot-rtos | github_2023 | c | 190 | CHERIoT-Platform | davidchisnall | @@ -0,0 +1,21 @@
+// Copyright SCI Semiconductor and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include <string.h>
+
+const void *__cheri_libcall memchr(const void *voidString, int intChar, size_t n)
+{
+ const char c = (char)intChar;
+ const char *s = (const char *)voidString; | The specification for `memchr` requires that the comparison be interpreting the bytes as `unsigned char`, not `char`. |
cheriot-rtos | github_2023 | cpp | 190 | CHERIoT-Platform | davidchisnall | @@ -47,7 +48,42 @@ void check_timeouts()
TEST(t.may_block(), "An unlimited timeout should block.");
}
+/**
+ * Test memchr.
+ *
+ * This test checks the following:
+ *
+ * - memchr finds the first occurrence of the character when it is present
+ * (test for different values, particularly the first and the last o... | I don't think this use of a string view is adding anything. |
cheriot-rtos | github_2023 | cpp | 205 | CHERIoT-Platform | rmn30 | @@ -49,3 +50,9 @@ __cheri_libcall _Bool switcher_interrupt_thread(void *);
* next cross-compartment call or until they are explicitly overwritten.
*/
__cheri_libcall void **switcher_thread_hazard_slots(void);
+
+/**
+ * Returns the lowest address that has been stored to on the stack in this
+ * compartment invocat... | May be worth noting that this will be rounded down to 16-byte alignment? |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | rmn30 | @@ -741,4 +741,59 @@ namespace
Assert(auto, const char *, Ts &&...) -> Assert<Ts...>;
};
+ /**
+ * Check the stack usage of a function. If `Enabled` is true, this will
+ * print a message if the stack usage is larger than `Expected`. One
+ * message will be printed for each invocation of the function that e... | ```suggestion
ConditionalDebug<Enabled, Fn>::log("Stack use exceeded
{}: {} bytes", Expected,
``` |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | nwf-msr | @@ -741,4 +741,59 @@ namespace
Assert(auto, const char *, Ts &&...) -> Assert<Ts...>;
};
+ /**
+ * Check the stack usage of a function. If `Enabled` is true, this will
+ * print a message if the stack usage is larger than `Expected`. One | Maybe expand this comment to be that it's the _total_ stack usage by _this compartment_ rather than either the stack usage by _this particular function_ or by _the whole stack of calling compartments_?
Might also benefit from a "thereafter" before "one message"? |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | rmn30 | @@ -5,7 +5,7 @@
#include <platform/concepts/entropy.h>
#include <riscvreg.h>
-DECLARE_AND_DEFINE_INTERRUPT_CAPABILITY(RevokerInterruptEntropy, | This looks unrelated to other changes? |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | nwf-msr | @@ -741,4 +741,89 @@ namespace
Assert(auto, const char *, Ts &&...) -> Assert<Ts...>;
};
+ enum class StackCheckMode
+ {
+ Disabled,
+ Logging,
+ Asserting,
+ };
+
+ /**
+ * Check the (dynamic) stack usage of a function, including all of its
+ * callees. This is intended to be used in compartment entry poi... | I'm not quite sure what this sentence is saying. Do you mean "If this compartment calls others, then even stacks larger than this recorded threshold may fail"? |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | nwf-msr | @@ -741,4 +741,89 @@ namespace
Assert(auto, const char *, Ts &&...) -> Assert<Ts...>;
};
+ enum class StackCheckMode
+ {
+ Disabled,
+ Logging,
+ Asserting,
+ };
+
+ /**
+ * Check the (dynamic) stack usage of a function, including all of its
+ * callees. This is intended to be used in compartment entry poi... | Does this still get created even if the mode is `Disabled`? I think maybe the kind of `std::conditional_t<>`... "stunts" we pull in `snmalloc`'s freelist guard objects could avoid that? |
cheriot-rtos | github_2023 | others | 205 | CHERIoT-Platform | nwf-msr | @@ -39,6 +39,17 @@ debugOption("scheduler")
debugOption("allocator")
debugOption("token_library")
+function stackCheckOption(name)
+ option("stack-usage-check-" .. name)
+ set_default(false)
+ set_description("Enable dynamic stack usage checks in " .. name .. ". Do not enable this in debug builds!") | Hm. I'm not sure how I feel about the "do not enable in debug builds" bit. I presume that's because the constants in the source are the release build stack usage and debug messages dramatically increase the stack usage. Maybe debug builds should force any `Asserting` mode to be `Logging` instead? |
cheriot-rtos | github_2023 | cpp | 205 | CHERIoT-Platform | nwf-msr | @@ -542,7 +543,18 @@ void test_allocator()
TEST(heap_address_is_valid(&noWait) == false,
"Global object incorrectly reported as heap address");
+ t = 5;
+ Capability array{heap_allocate_array(&t, MALLOC_CAPABILITY, 0x80000004, 2)};
+ TEST(!array.is_valid(), "Allocating too large an array succeeded: {}", arra... | This hunk looks unrelated, in that I don't see it fiddling with the stack bounds? |
cheriot-rtos | github_2023 | cpp | 163 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,329 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include <debug.hh>
+
+using namespace CHERI;
+
+namespace
+{
+ /**
+ * Printer for debug messages. This implements the `DebugWriter` interface
+ * so that it can be used with custom callbacks.
+ *
+ * This is n... | ```suggestion
write(C.permissions());
write(')');
``` |
cheriot-rtos | github_2023 | cpp | 154 | CHERIoT-Platform | rmn30 | @@ -176,3 +176,20 @@ int eventgroup_get(EventGroup *group, uint32_t *outBits)
*outBits = group->bits;
return 0;
}
+
+int eventgroup_destroy(SObjStruct *heapCapability, EventGroup *group)
+{
+ group->lock.lock(); | What will happen to any threads waiting on this lock once we free `group`? I guess they will timeout and then crash? Oh well. |
cheriot-rtos | github_2023 | others | 153 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,598 @@
+#pragma once
+#include <array>
+#include <cheri.hh>
+#include <cstddef>
+#include <cstdint>
+#include <debug.hh>
+#include <futex.h>
+#include <interrupt.h>
+#include <optional>
+#include <thread.h>
+#include <platform/concepts/ethernet.hh>
+
+DECLARE_AND_DEFINE_INTERRUPT_CAPABILITY(EthernetReceive,
... | This is repeated. Typo? |
cheriot-rtos | github_2023 | others | 153 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,598 @@
+#pragma once
+#include <array>
+#include <cheri.hh>
+#include <cstddef>
+#include <cstdint>
+#include <debug.hh>
+#include <futex.h>
+#include <interrupt.h>
+#include <optional>
+#include <thread.h>
+#include <platform/concepts/ethernet.hh>
+
+DECLARE_AND_DEFINE_INTERRUPT_CAPABILITY(EthernetReceive,
... | What is `0x10` here? |
cheriot-rtos | github_2023 | others | 153 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,598 @@
+#pragma once
+#include <array>
+#include <cheri.hh>
+#include <cstddef>
+#include <cstdint>
+#include <debug.hh>
+#include <futex.h>
+#include <interrupt.h>
+#include <optional>
+#include <thread.h>
+#include <platform/concepts/ethernet.hh>
+
+DECLARE_AND_DEFINE_INTERRUPT_CAPABILITY(EthernetReceive,
... | Dead? |
cheriot-rtos | github_2023 | others | 153 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,94 @@
+#pragma once
+#include <array>
+#include <concepts>
+#include <cstdint>
+
+/**
+ * Helper concept for the type returned by `receive_frame`. This must provide a
+ * buffer and a length. It may also be an RAII type that handles any cleanup
+ * when it is destroyed.
+ *
+ * This is not required to be c... | ```suggestion
* Set the MAC address of this adaptor to the default value.
``` |
cheriot-rtos | github_2023 | c | 147 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,14 @@
+#include <string.h>
+
+char *strchr(const char *s, int intChar)
+{
+ char c = (char)intChar;
+ while (*s != c)
+ {
+ if (!*s++) | I had to look up operator precedence for this but I think it's correct... |
cheriot-rtos | github_2023 | cpp | 146 | CHERIoT-Platform | davidchisnall | @@ -55,48 +55,58 @@ namespace
int
try_lock(Timeout *timeout, uint32_t threadID, bool isPriorityInherited)
{
- uint32_t old = Flag::Unlocked;
- uint32_t desired = Flag::Locked | threadID;
- if (lockWord.compare_exchange_strong(old, desired))
- {
- return 0;
- }
- // Next time, try to acquire,... | ```suggestion
// Preserve any ThreadID
uint32_t addedWaiters = Flag::LockedWithWaiters | (old & 0xffff);
``` |
cheriot-rtos | github_2023 | others | 139 | CHERIoT-Platform | nwf-msr | @@ -1058,13 +1058,20 @@ namespace CHERI
* Checks that `ptr` is valid, unsealed, does not overlap the caller's
* stack, and has at least `Permissions` and has at least `Space` bytes
* after the current offset.
+ *
+ * If the permissions do not include Global, then this will also check that
+ * the capability... | Do you mean for this to default to `true`? |
cheriot-rtos | github_2023 | others | 139 | CHERIoT-Platform | nwf-msr | @@ -1058,13 +1058,20 @@ namespace CHERI
* Checks that `ptr` is valid, unsealed, does not overlap the caller's
* stack, and has at least `Permissions` and has at least `Space` bytes
* after the current offset.
+ *
+ * If the permissions do not include Global, then this will also check that
+ * the capability... | Wow that... that sure is a formatting decision. Would you consider...
```
constexpr bool stackish = CheckStack && !Permissions.contains(Permission::Global);
return detail::check_pointer_internal<stackish>
``` |
cheriot-rtos | github_2023 | others | 139 | CHERIoT-Platform | nwf-msr | @@ -337,5 +344,26 @@ class LockGuard
wrappedLock->unlock();
}
}
+
+ /**
+ * Conversion to bool. Returns true if this guard owns the lock, false
+ * otherwise. This allows lock guards to be used with a timeout in
+ * conditional blocks, such as:
+ *
+ * ```
+ * if (LockGuard g{lock, timeout}) | The guard object is in scope until the end of the `if` and `else` blocks or the end of the enclosing scope? |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,437 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<true, "Queue library">;
+
+#ifdef __cplusplus
+u... | Might be worth making https://github.com/microsoft/cheriot-rtos/blob/main/sdk/include/ds/ring_buffer.h use that trick rather than the separate `bool empty` and then use that here? |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,437 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<true, "Queue library">;
+
+#ifdef __cplusplus
+u... | Perhaps an `atomic_ref`, if we support those, rather than requiring that the word always be `atomic`? |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,437 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<true, "Queue library">;
+
+#ifdef __cplusplus
+u... | high _two_ bits! |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,437 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<true, "Queue library">;
+
+#ifdef __cplusplus
+u... | Not sure about the merits of keeping these `Debug::log`s around, but if we do, they should probably also include `&lockWord`, not just `value`. |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,437 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<true, "Queue library">;
+
+#ifdef __cplusplus
+u... | For maximum paranoia, I think that could be `(elementCount | (elementCount * 2)) & HighBitFlagLoc::reserved_bits()`, lest that `* 2` push the offending bit off the top and badness result. (The `__builtin_mul_overflow` above won't object to such `elementCount`s with `elementSize == 1`.) |
cheriot-rtos | github_2023 | others | 139 | CHERIoT-Platform | rmn30 | @@ -1058,13 +1058,23 @@ namespace CHERI
* Checks that `ptr` is valid, unsealed, does not overlap the caller's
* stack, and has at least `Permissions` and has at least `Space` bytes
* after the current offset.
+ *
+ * If the permissions do not include Global, then this will also check that
+ * the capability... | ```suggestion
* the capability does not point to the current thread's stack. This
``` |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,435 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<false, "Queue library">;
+
+#ifdef __cplusplus
+... | Shouldn't this check for `producer < consumer`? |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,435 @@
+#include <cheri.hh>
+#include <errno.h>
+#include <locks.hh>
+#include <queue.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <timeout.h>
+#include <type_traits>
+
+using namespace CHERI;
+using cheriot::atomic;
+
+using Debug = ConditionalDebug<false, "Queue library">;
+
+#ifdef __cplusplus
+... | Is this claim held indefinitely, until the next claim or compartment call? Same for the one in `queue_receive`. |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,230 @@
+#include "timeout.h"
+#include <atomic>
+#include <debug.hh>
+#include <errno.h>
+#include <limits>
+#include <locks.h>
+#include <thread.h>
+
+namespace
+{
+ constexpr bool DebugLocks =
+#ifdef DEBUG_LOCKS
+ DEBUG_LOCKS
+#else
+ false
+#endif
+ ;
+ using Debug = ConditionalDebug<DebugLocks, "L... | I'm thinking about the cases where this compare and exchange fails. It could mean:
1) The lock was released since we last read the lock word above. In that case we have a chance to lock it ourselves below and it will end up locked with waiters (even though there might not be any). That could lead to unnecessary notifi... |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,185 @@
+#pragma once
+#include <cdefs.h>
+#include <limits>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <thread.h>
+#include <timeout.h>
+
+/**
+ * State for a flag lock. Flag locks use a single futex word to store the lock
+ * state.
+ */
+struct FlagLockState
+{
+ /**
+ * The lock word. One b... | Nit: should this be before the `recursivemutex` prototypes? |
cheriot-rtos | github_2023 | cpp | 139 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,185 @@
+#pragma once
+#include <cdefs.h>
+#include <limits>
+#include <stdatomic.h>
+#include <stdint.h>
+#include <thread.h>
+#include <timeout.h>
+
+/**
+ * State for a flag lock. Flag locks use a single futex word to store the lock
+ * state.
+ */
+struct FlagLockState
+{
+ /**
+ * The lock word. One b... | If the underlying `FlagLockState` is PI, do we need to track this again here? |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -782,6 +797,13 @@ namespace
*capability, *chunk, bodySize, isPrecise, reallyFree);
}
+ bool timeout_is_valid(Timeout *timeout)
+ {
+ return !heap_address_is_valid(timeout) && | This is worthy of a comment, at least and should be documented on the APIs that take a `Timeout`. By the way I observe that `heap_address_is_valid` returns true for pointers into the hazardQuarantine but I think that is fine as they should never escape the allocator. |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -758,6 +758,16 @@ namespace
void boot_threads_create(const ImgHdr &image,
sched::ThreadLoaderInfo *threadInfo)
{
+ Capability<void *> hazardPointers =
+ build<void *,
+ Root::Type::RWGlobal,
+ PermissionSet{Permission::Store,
+ Pe... | Could we have a symbolic name for the number of hazard pointers per thread? Could it be configurable? |
cheriot-rtos | github_2023 | others | 137 | CHERIoT-Platform | rmn30 | @@ -23,6 +23,14 @@
"gpio_led0" : {
"start": 0x8f00f000,
"length": 0x800
+ },
+ "dmb_cfg": { | What's this? |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -891,6 +902,46 @@ class MState
size_t heapFreeSize;
size_t heapQuarantineSize;
+ /**
+ * The number of entries currently in the `hazardQuarantine` array.
+ */
+ size_t hazardQuarantineSize = 0;
+
+ /**
+ * Returns true if there are no objects in the `hazardQuarantine` array.
+ */
+ bool hazard_quarantine_i... | There don't seem to be any calls to this function? I was a bit worried about the `is_subset_of`. |
cheriot-rtos | github_2023 | others | 137 | CHERIoT-Platform | nwf-msr | @@ -23,6 +23,14 @@
"gpio_led0" : {
"start": 0x8f00f000,
"length": 0x800
+ },
+ "dmb_cfg": {
+ "start": 0x8f0f0000,
+ "length": 0x1000
+ },
+ "dmb": {
+ "start": 0x90000000,
+ "length": 0x100000 | This hunk looks unrelated; am I missing something? |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | nwf-msr | @@ -1160,26 +1250,135 @@ class MState
return bodySize;
}
+ /**
+ * Check whether `allocation` is in the hazard list. Returns true if it is.
+ *
+ * This must be called in between `hazard_list_begin` and the guard going
+ * out of scope.
+ */
+ bool hazard_pointer_check(Capability<void> allocation)
+ {
+ /... | Perhaps a comment of `guard` going out of scope after this line, just so there's _something_ written that makes it look like this can't be CSE'd with the then branch above. |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -732,12 +735,22 @@ namespace
{
return 0;
}
- owner.quota += chunk.size_get();
+ size_t chunkSize = chunk.size_get();
+ chunk.ownerID = 0;
if (chunk.claims == 0)
{
- return gm->mspace_free(chunk, bodySize);
+ int ret = gm->mspace_free(chunk, bodySize);
+ // If free fails, don't ... | A bit unfortunate that this means there is memory that is not free (could remain allocated indefinitely) but isn't attributed to a quota. With the existing claim mechanism does it get charged to the claimer's quota?
|
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | nwf-msr | @@ -891,6 +902,46 @@ class MState
size_t heapFreeSize;
size_t heapQuarantineSize;
+ /**
+ * The number of entries currently in the `hazardQuarantine` array.
+ */
+ size_t hazardQuarantineSize = 0; | ```suggestion
size_t hazardQuarantineOccupancy = 0;
```
since you use `hazardQuarantineSize` for the actual size of the reserved region, below? |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -0,0 +1,73 @@
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include <cheriot-atomic.hh>
+#include <compartment.h>
+#include <errno.h>
+#include <futex.h>
+#include <stdlib.h>
+#include <switcher.h>
+
+int heap_claim_fast(Timeout *timeout, const void *ptr, const void *ptr2)
+{
+ void **hazards = switcher_... | Is this comment a bit stale? I don't understand it and I'm not sure it describes the code. |
cheriot-rtos | github_2023 | cpp | 137 | CHERIoT-Platform | rmn30 | @@ -145,6 +145,27 @@ void *__cheri_compartment("alloc")
size_t __cheri_compartment("alloc")
heap_claim(struct SObjStruct *heapCapability, void *pointer);
+/**
+ * Interface to the fast claims mechanism. This claims two pointers using the
+ * hazard-pointer-inspired lightweight claims mechanism. If this function... | Is the idiomatic way to release a claim to call with `nullptr`? |
cheriot-rtos | github_2023 | cpp | 136 | CHERIoT-Platform | nwf-msr | @@ -405,36 +405,41 @@ namespace
*/
void *find_export_target(const ImgHdr &image,
const auto &sourceCompartment,
- ptraddr_t target,
- size_t size)
+ ImportEntry &entry)
{
// Build an MMIO capabi... | Why two `Debug::log`s back to back? |
cheriot-rtos | github_2023 | cpp | 136 | CHERIoT-Platform | nwf-msr | @@ -5,33 +5,78 @@
#include <cdefs.h>
/**
- * Provide a capability of the type `volatile type *` referring to the MMIO
- * region exported in the linker script with `name` as its name. This macro
- * can be used only in code (it cannot be used to initialise a global).
+ * Helper macro, should not be used directly.
... | Can you use symbolic constants here?
```suggestion
: "i"(((permitLoad) ? (1 << ImportEntry::PermitLoad) : 0) + \
((permitStore) ? (1 << ImportEntry::PermitStore) : 0) + \
((permitLoadStoreCapabilities) ? (1 << ImportEntry::PermitLoadStoreCapabilities) : 0) + \
... |
cheriot-rtos | github_2023 | others | 136 | CHERIoT-Platform | rmn30 | @@ -47,7 +47,10 @@ start:
la_abs a3, __compart_headers_end
sub a3, a3, a1
csetaddr ca1, ca2, a1 // ca2 still has the G root.
- csetboundsexact ca1, ca1, a3
+ // FIXME: This should be a set bounds exact, but we currently don't have a
+ // 'pad to capability alignment' command in the linker script and it need... | What are the consequences of inexact bounds? |
cheriot-rtos | github_2023 | cpp | 114 | CHERIoT-Platform | nwf-msr | @@ -905,8 +899,10 @@ namespace loader
/**
* The header of an export table.
+ *
+ * This is followed by an array of `ExportEntry`. | I suppose I understand why C++ doesn't do FAMs, and yet... |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | `compartment_switcher_sealing_key` occurs here as it is the start of `.text` and should probably be more generically rendered as `__compartment_code_start`, yes? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | Isn't this just a specialized https://github.com/microsoft/cheriot-rtos/blob/8380a1c2806e5c343f70b2f531305fa43110f4f2/sdk/include/compartment-macros-asm.S#L42
Even if you keep it as is, I think the `.section compartment_export_table` wants to be `.section compartment_exports`? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | We should probably have `#define`-d some constants for the bits of this word in assembler, since I think this is at least the second place we end up with commented magic numbers (see also https://github.com/microsoft/cheriot-rtos/blob/main/sdk/core/token_library/token_unseal.S#L100) |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -234,8 +232,10 @@ SECTIONS
@software_revoker_header@
- # Magic number
- LONG(0x43f6af90);
+ # Magic number.
+ # New versions of this can be generated with:
+ # head /dev/random | shasum | cut -c 0-8
+ LONG(0x6cef3879); | Probably wants a doc cross-reference to `is_magic_valid` above? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | ```suggestion
// Load pointer to trusted stack;
// this will be used for one load and then clobbered, so can't leak.
cspecialr ca0, mtdc
``` |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | ```suggestion
// Fetch offset from trusted stack; unless something has gone very wrong indeed,
// this cannot trap.
clhu a1, TrustedStack_offset_frameoffset(ca0)
``` |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | Similar commentary about sensitive caps and clobbering as above? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | Not that I object, but this jumping over another exported symbol seems like the kind of thing that's going to confuse a debugger? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -779,3 +779,77 @@ exception_entry_asm:
#endif
#endif // CONFIG_NO_SWITCHER_SAFETY
cret
+
+// Returns whether the trusted stack has space for N more calls.
+ .section .text, "ax", @progbits
+ .p2align 2
+ .type __Z23trusted_stack_has_spacei,@function
+__Z23trusted_stack_has_spacei:
+ li a2, Truste... | Give these constants names and add an assert in `trusted-stack-assembly.h`? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -436,7 +436,7 @@ rule("firmware")
for i, thread in ipairs(threads) do
thread.mangled_entry_point = string.format("__export_%s__Z%d%sv", thread.compartment, string.len(thread.entry_point), thread.entry_point)
thread.thread_id = i
- thread.trusted_stack_size = loader_trusted_stack_size + (64 * thread.trus... | Comment explaining 24? |
cheriot-rtos | github_2023 | cpp | 114 | CHERIoT-Platform | nwf-msr | @@ -46,6 +47,18 @@ void test_compartment_call()
bool outTestFailed = false;
int ret = 0;
+ ret = trusted_stack_index();
+ // 0: Test runner. 1: Us
+ TEST(ret == 1, "Trusted stack index is {}, expected 1", ret);
+ ret = trusted_stack_size();
+ // 9 Real frames plus the entry point size.
+ TEST(ret == 9... | oops? |
cheriot-rtos | github_2023 | others | 114 | CHERIoT-Platform | nwf-msr | @@ -26,6 +26,8 @@
#define SPILL_SLOT_pcc 24
#define SPILL_SLOT_SIZE 32
+switcher_code_start: | This is still assuming that `entry.S` is the first `.o` to place anything in the `.text` section, isn't it? Can we not use `__compartment_code_start` from the linker script? |
cheriot-rtos | github_2023 | others | 128 | CHERIoT-Platform | rmn30 | @@ -168,6 +168,20 @@ namespace
using ArgumentType = std::tuple<Args...>;
};
+ /**
+ * The concrete specialisation that decomposes the function type. | ```suggestion
* The concrete specialisation that decomposes the function type for a cross compartment call.
``` |
cheriot-rtos | github_2023 | others | 128 | CHERIoT-Platform | rmn30 | @@ -14,8 +14,14 @@ fi
if [ ! -f ./node_modules/.bin/microvium ] ; then
if ! type npm >/dev/null 2>&1 ; then
- echo npm is not installed. Please install it.
- exit 1
+ if type apt >/dev/null 2>&1 ; then
+ echo npm is not installed. Trying to install it from apt.
+ echo If you are not using the devcontainer... | Why are make, gcc and g++ needed? It works for me without... |
cheriot-rtos | github_2023 | others | 127 | CHERIoT-Platform | davidchisnall | @@ -24,6 +24,13 @@ The goal of this exercise is to apply compartmentalisation to limit the damage t
Running the exercise
--------------------
+First we need to configure the `xmake` build to run on the Ibex simulator and build with the CHERIoT toolchain.
+If you are using the [dev container](../../docs/GettingStart... | ```suggestion
xmake config --sdk=/cheriot-tools/
```
The board has a sensible default and I don't want people changing it. |
cheriot-rtos | github_2023 | others | 127 | CHERIoT-Platform | davidchisnall | @@ -112,7 +119,7 @@ Exercise 1: Confidentiality
---------------------------
First, we want to protect the secret.
-For the this exercise, we want to move the
+For the this exercise, we want to move it into a separate comparment from the JavaScript interpreter: we want to minimise the attack surface of the compartm... | I don't think we want to talk about attack surface here. We are doing this to isolate the secret, not to reduce the attack surface. We could talk about blast radius, but that's probably too much detail. |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | Perhaps we should suggest that CHERIoT platforms, including our simulator, implement the RISC-V TRNG from the scalar cryptography extension (https://github.com/riscv/riscv-crypto/releases/download/v1.0.1-scalar/riscv-crypto-spec-scalar-v1.0.1.pdf, section ; see also https://eprint.iacr.org/2020/866.pdf) |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
- Read the stack capability, global capability, and program counter capability into any of eight (virtual) register slots.
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | I think this needs some clarification: the intent seems to be that
attackers write JS+FFI code, with the FFI providing a virtual machine for manipulating real capabilities
rather than
attackers write microvium bytecode to take advantage of some aspect of the microvium implementation
and I don't thin... |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
- Run arbitrary JavaScript to perform any of the above actions, intermixed with other computation.
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
The goal of this exercise is to apply compartmentalisation to limit the damage that an attacker with even this level of compromise can do.
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
The lines that start with (magenta) `JavaScript compartment' are debugging lines that are produced by `Debug::log` calls in C++.
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
The system's memory also contains a secret.
```
or
```suggestion
This firmware image also contains a storage location for a secret.
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | Would it make sense to cut up `js.cc` and allow more of the edits to be done in `xmake`? |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | You might expand on "matter". Perhaps "Compartment names are also referenced in program source files, and so there must be some additional coordination between source and build system." or such. |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | You might mumble something about annotations on function definitions vs. declarations here? |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
This function is implicitly exported from the compartment because it's a thread entry point, described later in the `xmake.lua` like this:
``` |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
The names of both the compartment ("js") and the entry-point function ("run") must match the C++ source, here.
``` |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | ```suggestion
Debug::Assert(c == ',', "Expected comma or close brace, read {}", c);
``` |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | Maybe we should be warning if we discard something other than whitespace? |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | This name is a little confusing since there are two layers of virtual machines here: JS and the in-JS capability machine. |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | ```suggestion
* Address of the `VMRegisterState` on the stack. That structure is on the
``` |
cheriot-rtos | github_2023 | javascript | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,98 @@
+// FFI Imports
+// Each function imported from the host environment needs to be assigned to a
+// global like this and identified by a constant that the resolver in the C/C++
+// code will understand.
+
+
+/**
+ * Log function, writes all arguments to the UART.
+ */
+export const print = vmImport(1); | Document that these constants are elements of the `Exports` `enum` down in `js.cc`? |
cheriot-rtos | github_2023 | cpp | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,568 @@
+// Copyright Microsoft and CHERIoT Contributors.
+// SPDX-License-Identifier: MIT
+
+#include "cheri.hh"
+#include "compartment-macros.h"
+#include "microvium/microvium.h"
+#include <compartment.h>
+#include <cstdint>
+#include <cstdlib>
+#include <debug.hh>
+#include <functional>
+#include <magic_en... | Could all of this, through `call_export` be factored out into a microvium glue header or even pushed upstream? It feels a little generic and/or out of place here. |
cheriot-rtos | github_2023 | others | 122 | CHERIoT-Platform | nwf-msr | @@ -0,0 +1,222 @@
+Compartmentalisation Exercise 1
+===============================
+
+This exercise starts from a firmware image that simulates a bug that gives an attacker arbitrary-code execution.
+It reads JavaScript programs (as compiled bytecode) from the UART and executes them.
+This models an attacker building ... | ```suggestion
Implement an error handler that does not attempt to recover from the error but instead frees all memory associated with the JavaScript compartment and bails to the caller.
``` |
cheriot-rtos | github_2023 | others | 121 | CHERIoT-Platform | nwf-msr | @@ -1 +1 @@
-{0x07,0x1c,0x07,0x00,0x16,0x01,0xd7,0x60,0x03,0x00,0x00,0x00,0x1c,0x00,0x1e,0x00,0x22,0x00,0x22,0x00,0x28,0x00,0x32,0x00,0xf4,0x00,0x02,0x01,0x01,0x00,0xd2,0x04,0xad,0x00,0x01,0x01,0xfd,0x00,0x01,0x00,0x49,0x00,0x65,0x00,0x59,0x00,0x3d,0x00,0x35,0x00,0x05,0x40,0x70,0x75,0x73,0x68,0x00,0x00,0x04,0x40,0x6c,0... | I'm just going to trust that that's correct, since I am not a cylon. |
cheriot-rtos | github_2023 | cpp | 121 | CHERIoT-Platform | nwf-msr | @@ -165,13 +166,13 @@ fixes and improvement from the original github or npm repository.
*
* Offset may be negative
*/
-#define MVM_LONG_PTR_ADD(p, s) ((MVM_LONG_PTR_TYPE)((uint8_t*)p + (intptr_t)s))
+#define MVM_LONG_PTR_ADD(p, s) ((MVM_LONG_PTR_TYPE)((uint8_t *)p + (intptr_t)s)) | Maybe, while you're here,
```suggestion
#define MVM_LONG_PTR_ADD(p, s) ((MVM_LONG_PTR_TYPE)((uint8_t *)p + (ptrdiff_t)s))
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.