diff options
| author | Laura Peskin <pesk@google.com> | 2022-11-22 14:28:37 -0800 |
|---|---|---|
| committer | Ange Albertini <105304039+corkamig@users.noreply.github.com> | 2022-11-23 18:50:14 +0000 |
| commit | 4b01db733a68d41909ab469cacf83de587aa83c0 (patch) | |
| tree | c88909a9c508b86349d146681f2d4bbfbef99c8c /sys | |
| parent | 12c66417513689207e96cb377eba36af9bf78535 (diff) | |
sys/fuchsia: add test for handle syscall descriptions
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/fuchsia/test/handle | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/sys/fuchsia/test/handle b/sys/fuchsia/test/handle new file mode 100644 index 000000000..1f82da0ff --- /dev/null +++ b/sys/fuchsia/test/handle @@ -0,0 +1,48 @@ +r0 = syz_job_default() +zx_job_create(r0, 0x0, &AUTO=<r1=>0x0) +zx_socket_create(0x0, &AUTO=<r2=>0x0, &AUTO=<r3=>0x0) + +# Duplicate the child job handle with the same rights (ZX_DEFAULT_JOB_RIGHTS), then with no rights. + +zx_handle_duplicate(r1, 0x80000000, &AUTO=<r4=>0x0) +zx_handle_duplicate(r1, 0x0, &AUTO=<r5=>0x0) + +# Duplicating a handle without ZX_RIGHT_DUPLICATE should fail. +# Duplicating a handle with rights that are not a subset of the original's rights should also fail. + +zx_handle_duplicate(r5, 0x1, &AUTO) # ZX_ERR_ACCESS_DENIED +zx_handle_duplicate(r1, 0x10, &AUTO) # ZX_ERR_INVALID_ARGS + +# Replace a job handle with the same rights. +# The original handle is now invalid. + +zx_handle_replace(r4, 0x80000000, &AUTO=<r6=>0x0) +zx_object_get_info$ZX_INFO_HANDLE_VALID(r4, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE + +# Replacing a handle with rights that are not a subset of the original's rights should fail. +# Even though zx_handle_replace returned an error, the handles we tried to replace are invalidated. + +zx_object_get_info$ZX_INFO_HANDLE_VALID(r5, 0x1, nil, 0, nil, nil) +zx_object_get_info$ZX_INFO_HANDLE_VALID(r6, 0x1, nil, 0, nil, nil) + +zx_handle_replace(r5, 0x1, &AUTO) # ZX_ERR_INVALID_ARGS +zx_handle_replace(r6, 0x10, &AUTO) # ZX_ERR_INVALID_ARGS + +zx_object_get_info$ZX_INFO_HANDLE_VALID(r5, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE +zx_object_get_info$ZX_INFO_HANDLE_VALID(r6, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE + +# Close one of the socket handles. +# This should block operations on the handle's peer. + +zx_handle_close(r2) +zx_object_get_info$ZX_INFO_HANDLE_VALID(r2, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE +zx_socket_read(r3, 0x0, &AUTO, 0x10, &AUTO) # ZX_ERR_PEER_CLOSED + +# Close the remaining handles. +# Operations on those handles should now fail. + +zx_handle_close_many(&AUTO=[r0, r1, r3], 0x3) +zx_object_get_info$ZX_INFO_HANDLE_VALID(r0, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE +zx_object_get_info$ZX_INFO_HANDLE_VALID(r1, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE +zx_object_get_info$ZX_INFO_HANDLE_VALID(r3, 0x1, nil, 0, nil, nil) # ZX_ERR_BAD_HANDLE +zx_handle_duplicate(r0, 0x80000000, &AUTO) # ZX_ERR_BAD_HANDLE |
