mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-23 11:29:46 +00:00
0a13649c05
* sys/linux: enhanced descs for io_uring Introduced pseudo-call "syz_io_uring_put_sqes_on_ring()" for writing submission queue entries (sqes) on sq_ring, which was obtained by mmap'ping the offsets obtained from io_uring_setup(). Added descriptions for io_ring_register operations that were missing earlier. Did misc changes to adapt the descriptions for the updates on the io_uring subsystem. * pkg/host: add io_uring pseudo-syscall * executor/common_linux.h: fix issues with io_uring pseudo-syscall * executor: fixed io_uring offset computation * executor: fixes and refactorings in syz_io_uring_submit() * executor: added syz_io_uring_complete() pseudo-syscall for io_uring * sys/linux: added descriptions for io_uring operations Each operation requires a different struct io_uring_sqe set up. Those are described to be submitted to the sq ring. * executor: use uint32 instead of uint32_t * executor: remove nonfailing from pseudo-calls * sys/linux: fix io_uring epoll_ctl sqe * prog: fix TestTransitivelyEnabledCallsLinux() The newly introduced syscall, syz_io_uring_submit$IORING_OP_EPOLL_CTL, uses fd_epoll. Adapt TestTransitivelyEnabledCallsLinux() to account for this. * sys/linux: add IORING_OP_PROVIDE_BUFFERS and IORING_OP_REMOVE_BUFFERS * sys/linux: fix IORING_OP_WRITE_FIXED and IORING_OP_READ_FIXED addr and len are for the buffer located at buf_index * sys/linux: io_uring: use reg. bufs for READ, READV, RECV, RECVMSG As a result, IOSQE_BUFFER_SELECT_BIT is included in the iosqe_flags. * sys/linux: io_uring: misc fixes * sys/linux: io_uring: add IORING_SETUP_ATTACH_WQ * executor: refactorings on io_uring pseudo syscalls * sys/linux: io_uring: fix desc for params.cq_entries * executor: fix SQ_ARRAY_OFFSET computation This is required with the fix in io_uring kernel code. https://lore.kernel.org/io-uring/CACT4Y+bgTCMXi3eU7xV+W0ZZNceZFUWRTkngojdr0G_yuY8w9w@mail.gmail.com/T/#t * executor: added pseudosyscall syz_io_uring_cq_eventfd_toggle() The usage of cq_ring->flags is only for manipulating IORING_CQ_EVENTFD_DISABLED bit. This is achieved by a pseudo-syscall, which toggles the bit. * executor: added pseudocall syz_io_uring_put_ring_metadata Removed syz_io_uring_cq_eventfd_toggle() and introduced syz_io_uring_put_ring_metadata() instead. We have many pieces of metadata for both sq_ring and cq_ring, for which we are given the offsets, and some of are not supposed to be manipulated by the application. Among them, both sq and cq flags can be changed. Both valid and invalid cases might cause interesting outcomes. Use the newly introduced pseudo syscall to manipulate them randomly while also manipulating the flags to their special values. * executor: added pseudo-syscall syz_memcpy_off Removed syz_io_uring_put_ring_metadata() and instead added a much more generic pseudo systemcall to achieve the task. This should benefit other subsystems as well. * sys/linux: refactored io_uring descriptions syz_io_uring_submit() is called with a union of sqes to reduce duplication of other parameters of the function. io_uring_sqe is templated with io_uring_sqe_t, and this template type is used to describe sqes for different ops. The organization of io_uring.txt is changed. * sys/linux: io_uring: improved descs to utilize registered files The files are registered using io_uring_register$IORING_REGISTER_FILES(). When IOSQE_FIXED_FILE_BIT is enabled in iosqe_flags in sqe, a variety of operations can use those registered files using the index of the file instead of fd. Changed the sqe descriptions for the eligible operations to utilize this. * sys/linux: io_uring: improved the descs to utilize personality_id in sqes A personality_id can be registered for a io_uring fd using io_uring_register$IORING_REGISTER_PERSONALITY(). This id can be utilized within sqes. This commit improves the descs for io_uring to utilize it. In addition, the descriptions for the misc field in io_uring_sqe_t is refactored as most are shared among sqes. * sys/linux: io_uring: utilized cqe.res io_uring_cqe.res is used to carry the return value of operations achieved through io_uring. The only operations with meaningful return values (in terms of their possible usage) are openat and openat2. The pseudo-syscall syz_io_uring_complete() is modified to account for this and return those fds. The description for sqe_user_data is splitted into two to identify openat and non-openat io_uring ops. IORING_OP_IOCTL was suggested but never supported in io_uring. Thus, the note on this is removed in the descriptions. tee() expects pipefds, thus, IORING_OP_TEE. The descriptions for the pipe r/w fds are written as ordinary fd. Thus, in the description for IORING_OP_TEE, which is io_uring_sqe_tee, fd is used in the place where pipefds are expected. The note on this is removed in the descriptions. * sys/linux/test: added test for io_uring This is not tested yet. * sys/linux/test: fixed the test for io_uring The changes successfully pass the sys/linux/test/io_uring test. sys/linux/io_uring.txt: sq_ring_ptr and cq_ring_ptr are really the same. Thus, they are replaced with ring_ptr. executor/common_linux.h: thanks to io_uring test, a bug is found in where the sq_array's address is computed in syz_io_uring_submit(). Fixed. In addition, similar to the descriptions, the naming for the ring_ptr is changed from {sq,cq}_ring_ptr to ring_ptr. * sys/linux: io_uring: misc fixes * sys/linux: io_uring: changed the sqe_user_data enum Used a smaller range to ease the collisions. Used comperatively unique and magic numbers for openat user_data to avoid thinking as if the cqe belongs to openat while the user_data is coming from some random location. * pkg/host: added checks for io_uring syscall * pkg/host: fixed checks for io_uring syscall * sys/linux: fixed io_uring test
115 lines
3.5 KiB
Go
115 lines
3.5 KiB
Go
// Copyright 2015 syzkaller project authors. All rights reserved.
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
package prog
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestResourceCtors(t *testing.T) {
|
|
if testing.Short() && raceEnabled {
|
|
t.Skip("too slow")
|
|
}
|
|
testEachTarget(t, func(t *testing.T, target *Target) {
|
|
for _, res := range target.Resources {
|
|
if len(target.calcResourceCtors(res, true)) == 0 && !strings.HasPrefix(res.Name, "ANY") {
|
|
t.Errorf("resource %v can't be created", res.Name)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestTransitivelyEnabledCalls(t *testing.T) {
|
|
testEachTarget(t, func(t *testing.T, target *Target) {
|
|
calls := make(map[*Syscall]bool)
|
|
for _, c := range target.Syscalls {
|
|
calls[c] = true
|
|
}
|
|
enabled, disabled := target.TransitivelyEnabledCalls(calls)
|
|
for c, ok := range enabled {
|
|
if !ok {
|
|
t.Fatalf("syscalls %v is false in enabled map", c.Name)
|
|
}
|
|
}
|
|
if target.OS == "test" {
|
|
for c := range enabled {
|
|
if c.CallName == "unsupported" {
|
|
t.Errorf("call %v is not disabled", c.Name)
|
|
}
|
|
}
|
|
for c, reason := range disabled {
|
|
if c.CallName != "unsupported" {
|
|
t.Errorf("call %v is disabled: %v", c.Name, reason)
|
|
}
|
|
}
|
|
} else {
|
|
if len(enabled) != len(target.Syscalls) {
|
|
t.Errorf("some calls are disabled: %v/%v", len(enabled), len(target.Syscalls))
|
|
}
|
|
if len(disabled) != 0 {
|
|
for c, reason := range disabled {
|
|
t.Errorf("disabled %v: %v", c.Name, reason)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestTransitivelyEnabledCallsLinux(t *testing.T) {
|
|
t.Parallel()
|
|
target, err := GetTarget("linux", "amd64")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
calls := make(map[*Syscall]bool)
|
|
for _, c := range target.Syscalls {
|
|
calls[c] = true
|
|
}
|
|
delete(calls, target.SyscallMap["epoll_create"])
|
|
if trans, disabled := target.TransitivelyEnabledCalls(calls); len(disabled) != 0 || len(trans) != len(calls) {
|
|
t.Fatalf("still must be able to create epoll fd with epoll_create1")
|
|
}
|
|
delete(calls, target.SyscallMap["epoll_create1"])
|
|
trans, disabled := target.TransitivelyEnabledCalls(calls)
|
|
if len(calls)-7 != len(trans) ||
|
|
trans[target.SyscallMap["epoll_ctl$EPOLL_CTL_ADD"]] ||
|
|
trans[target.SyscallMap["epoll_ctl$EPOLL_CTL_MOD"]] ||
|
|
trans[target.SyscallMap["epoll_ctl$EPOLL_CTL_DEL"]] ||
|
|
trans[target.SyscallMap["epoll_wait"]] ||
|
|
trans[target.SyscallMap["epoll_pwait"]] ||
|
|
trans[target.SyscallMap["kcmp$KCMP_EPOLL_TFD"]] ||
|
|
trans[target.SyscallMap["syz_io_uring_submit$IORING_OP_EPOLL_CTL"]] {
|
|
t.Fatalf("epoll fd is not disabled")
|
|
}
|
|
if len(disabled) != 7 {
|
|
t.Fatalf("disabled %v syscalls, want 7", len(disabled))
|
|
}
|
|
for c, reason := range disabled {
|
|
if !strings.Contains(reason, "no syscalls can create resource fd_epoll,"+
|
|
" enable some syscalls that can create it [epoll_create epoll_create1]") {
|
|
t.Fatalf("%v: wrong disable reason: %v", c.Name, reason)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestClockGettime(t *testing.T) {
|
|
t.Parallel()
|
|
target, err := GetTarget("linux", "amd64")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
calls := make(map[*Syscall]bool)
|
|
for _, c := range target.Syscalls {
|
|
calls[c] = true
|
|
}
|
|
// Removal of clock_gettime should disable all calls that accept timespec/timeval.
|
|
delete(calls, target.SyscallMap["clock_gettime"])
|
|
trans, disabled := target.TransitivelyEnabledCalls(calls)
|
|
if len(trans)+10 > len(calls) || len(trans)+len(disabled) != len(calls) || len(trans) == 0 {
|
|
t.Fatalf("clock_gettime did not disable enough calls: before %v, after %v, disabled %v",
|
|
len(calls), len(trans), len(disabled))
|
|
}
|
|
}
|