mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
Kernel: Handle promise violations in the syscall handler
Previously we would crash the process immediately when a promise violation was found during a syscall. This is error prone, as we don't unwind the stack. This means that in certain cases we can leak resources, like an OwnPtr / RefPtr tracked on the stack. Or even leak a lock acquired in a ScopeLockLocker. To remedy this situation we move the promise violation handling to the syscall handler, right before we return to user space. This allows the code to follow the normal unwind path, and grantees there is no longer any cleanup that needs to occur. The Process::require_promise() and Process::require_no_promises() functions were modified to return ErrorOr<void> so we enforce that the errors are always propagated by the caller.
This commit is contained in:
parent
c444a3fc9e
commit
54b9a4ec1e
66 changed files with 156 additions and 148 deletions
|
@ -14,9 +14,9 @@ namespace Kernel {
|
|||
#define REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(domain) \
|
||||
do { \
|
||||
if (domain == AF_INET) \
|
||||
require_promise(Pledge::inet); \
|
||||
TRY(require_promise(Pledge::inet)); \
|
||||
else if (domain == AF_LOCAL) \
|
||||
require_promise(Pledge::unix); \
|
||||
TRY(require_promise(Pledge::unix)); \
|
||||
} while (0)
|
||||
|
||||
void Process::setup_socket_fd(int fd, NonnullRefPtr<OpenFileDescription> description, int type)
|
||||
|
@ -76,7 +76,7 @@ ErrorOr<FlatPtr> Process::sys$listen(int sockfd, int backlog)
|
|||
ErrorOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
require_promise(Pledge::accept);
|
||||
TRY(require_promise(Pledge::accept));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
int accepting_socket_fd = params.sockfd;
|
||||
|
@ -146,7 +146,7 @@ ErrorOr<FlatPtr> Process::sys$connect(int sockfd, Userspace<const sockaddr*> use
|
|||
ErrorOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
require_promise(Pledge::stdio);
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
if (how & ~SHUT_RDWR)
|
||||
return EINVAL;
|
||||
auto description = TRY(fds().open_file_description(sockfd));
|
||||
|
@ -161,7 +161,7 @@ ErrorOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
|
|||
ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*> user_msg, int flags)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
require_promise(Pledge::stdio);
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
auto msg = TRY(copy_typed_from_user(user_msg));
|
||||
|
||||
if (msg.msg_iovlen != 1)
|
||||
|
@ -189,7 +189,7 @@ ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*
|
|||
ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user_msg, int flags)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
require_promise(Pledge::stdio);
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
|
||||
struct msghdr msg;
|
||||
TRY(copy_from_user(&msg, user_msg));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue