[kernel] Add automatic verification to syscalls

Since we have a DSL for specifying syscalls, we can create a verificaton
method for each syscall that can cover most argument (and eventually
capability) verification instead of doing it piecemeal in each syscall
implementation, which can be more error-prone.

Now a new _syscall_verify_* function exists for every syscall, which
calls the real implementation. The syscall table for the syscall handler
now maps to these verify functions.

Other changes:

- Updated the definition grammar to allow options to have a "key:value"
  style, to eventually support capabilities.
- Added an "optional" option for parameters that says a syscall will
  accept a null value.
- Some bonnibel fixes, as definition file changes weren't always
  properly causing updates in the build dep graph.
- The syscall implementation function signatures are no longer exposed
  in syscall.h. Also, the unused syscall enum has been removed.
This commit is contained in:
Justin C. Miller
2022-01-16 15:11:58 -08:00
parent e845379b1e
commit e0246df26b
21 changed files with 415 additions and 219 deletions

View File

@@ -29,7 +29,9 @@ endpoint_send(j6_handle_t handle, uint64_t tag, const void * data, size_t data_l
j6_status_t
endpoint_receive(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len, uint64_t timeout)
{
if (!tag || !data_len || (*data_len && !data))
// Data is marked optional, but we need the length, and if length > 0,
// data is not optional.
if (!data_len || (*data_len && !data))
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);
@@ -46,7 +48,7 @@ endpoint_receive(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_
j6_status_t
endpoint_sendrecv(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len, uint64_t timeout)
{
if (!tag || (*tag & j6_tag_system_flag))
if (*tag & j6_tag_system_flag)
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);

View File

@@ -13,9 +13,6 @@ namespace syscalls {
j6_status_t
kobject_koid(j6_handle_t handle, j6_koid_t *koid)
{
if (koid == nullptr)
return j6_err_invalid_arg;
kobject *obj = get_handle<kobject>(handle);
if (!obj)
return j6_err_invalid_arg;

View File

@@ -19,9 +19,6 @@ namespace syscalls {
j6_status_t
log(const char *message)
{
if (message == nullptr)
return j6_err_invalid_arg;
thread &th = thread::current();
log::info(logs::syscall, "Message[%llx]: %s", th.koid(), message);
return j6_status_ok;
@@ -36,23 +33,24 @@ noop()
}
j6_status_t
system_get_log(j6_handle_t sys, void *buffer, size_t *size)
system_get_log(j6_handle_t sys, void *buffer, size_t *buffer_len)
{
if (!size || (*size && !buffer))
// Buffer is marked optional, but we need the length, and if length > 0,
// buffer is not optional.
if (!buffer_len || (*buffer_len && !buffer))
return j6_err_invalid_arg;
size_t orig_size = *size;
*size = g_logger.get_entry(buffer, *size);
size_t orig_size = *buffer_len;
*buffer_len = g_logger.get_entry(buffer, *buffer_len);
if (!g_logger.has_log())
system::get().deassert_signal(j6_signal_system_has_log);
return (*size > orig_size) ? j6_err_insufficient : j6_status_ok;
return (*buffer_len > orig_size) ? j6_err_insufficient : j6_status_ok;
}
j6_status_t
system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq)
{
// TODO: check capabilities on sys handle
endpoint *e = get_handle<endpoint>(endp);
if (!e) return j6_err_invalid_arg;
@@ -65,9 +63,6 @@ system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq)
j6_status_t
system_map_phys(j6_handle_t handle, j6_handle_t * area, uintptr_t phys, size_t size, uint32_t flags)
{
// TODO: check capabilities on sys handle
if (!area) return j6_err_invalid_arg;
// TODO: check to see if frames are already used? How would that collide with
// the bootloader's allocated pages already being marked used?
if (!(flags & vm_flags::mmio))
@@ -82,7 +77,6 @@ system_map_phys(j6_handle_t handle, j6_handle_t * area, uintptr_t phys, size_t s
j6_status_t
system_request_iopl(j6_handle_t handle, unsigned iopl)
{
// TODO: check capabilities on sys handle
if (iopl != 0 && iopl != 3)
return j6_err_invalid_arg;

View File

@@ -56,9 +56,6 @@ vma_unmap(j6_handle_t handle, j6_handle_t proc)
j6_status_t
vma_resize(j6_handle_t handle, size_t *size)
{
if (!size)
return j6_err_invalid_arg;
vm_area *a = get_handle<vm_area>(handle);
if (!a) return j6_err_invalid_arg;