aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaura Peskin <pesk@google.com>2022-11-22 14:28:37 -0800
committerAnge Albertini <105304039+corkamig@users.noreply.github.com>2022-11-23 18:50:14 +0000
commit4b01db733a68d41909ab469cacf83de587aa83c0 (patch)
treec88909a9c508b86349d146681f2d4bbfbef99c8c
parent12c66417513689207e96cb377eba36af9bf78535 (diff)
sys/fuchsia: add test for handle syscall descriptions
-rw-r--r--pkg/runtest/run.go1
-rw-r--r--sys/fuchsia/test/handle48
2 files changed, 49 insertions, 0 deletions
diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go
index 952a2e1e6..a0daf2b86 100644
--- a/pkg/runtest/run.go
+++ b/pkg/runtest/run.go
@@ -310,6 +310,7 @@ func parseProg(target *prog.Target, dir, filename string) (*prog.Prog, map[strin
"ZX_ERR_BAD_HANDLE": 11,
"ZX_ERR_BAD_STATE": 20,
"ZX_ERR_TIMED_OUT": 21,
+ "ZX_ERR_PEER_CLOSED": 24,
"ZX_ERR_ALREADY_EXISTS": 26,
"ZX_ERR_ACCESS_DENIED": 30,
}
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