On 18/01/2024 18:31, Akram Ahmad wrote:
[...]
+TEST(test_copy_to_user) +{
- struct sysinfo my_sysinfo;
- ASSERT_EQ(sysinfo(&my_sysinfo), 0);
- ASSERT_EQ(sysinfo(&my_sysinfo + sizeof(struct sysinfo)), -EFAULT);
We are still using a byte offset of sizeof(struct sysinfo) * sizeof(struct sysinfo). Arithmetic operations on T * work at a granularity of sizeof(T), so incrementing a T * pointer by 1 increases its address by sizeof(T), and that should be enough here.
- ASSERT_EQ(sysinfo(cheri_tag_clear(&my_sysinfo)), -EFAULT);
- ASSERT_EQ(sysinfo(cheri_perms_and(&my_sysinfo, 0)), -EFAULT);
+}
[...]
+TEST(test_futex) +{
- static struct futex_waitv waitv;
This is not actually used any more.
- uint32_t futex = 0;
- waitv.uaddr = (uintptr_t)&futex;
- waitv.flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
- waitv.val = futex;
- waitv.__reserved = 0;
- ASSERT_GE(futex_wake_op(&futex, &futex, 0), 0);
- ASSERT_EQ(futex_wake_op(&futex, &futex + sizeof(uint32_t), 0), -EFAULT);
- ASSERT_EQ(futex_wake_op(&futex, cheri_tag_clear(&futex), 0), -EFAULT);
- ASSERT_EQ(futex_wake_op(&futex, cheri_perms_and(&futex, 0), 0),
-EFAULT);
+}
+/*
- Test explicit accesses used in iov_iter via readv and writev. Both
- syscalls use explicit checking on the iov_base field of struct iovec,
- so the metadata of the capability provided for iov_base is modified as
- per the needs of each individual test.
- */
+TEST(test_explicit_iov_iter) +{
- char buf0[2];
- char buf1[4];
- char buf2[6];
- const char *write_buf0 = "Hello I am the first char buffer!\n";
- const char *write_buf1 = "Hello, I am the second char buffer.\n";
- const char *write_buf2 = "Hello, I am the third and final char buffer.\n";
- struct iovec iov[3];
- int iovcnt;
- int fd;
- fd = open_file();
- ASSERT_NE(fd, -1);
- iov[0].iov_base = buf0;
- iov[0].iov_len = sizeof(buf0);
- iov[1].iov_base = buf1;
- iov[1].iov_len = sizeof(buf1);
- iov[2].iov_base = buf2;
- iov[2].iov_len = sizeof(buf2);
- iovcnt = sizeof(iov) / sizeof(struct iovec);
- ASSERT_GE(readv(fd, iov, iovcnt), 0);
- iov[0].iov_base = buf0 + sizeof(iov) * 100;
In this case sizeof(iov) has nothing to do with the address of iov_base (pointer to a string). Incrementing by 100 sounds reasonable.
Kevin
[...]