From 9c91c3b5a28d3dcfc6d6d96a52b7abfd112b04d9 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 27 Aug 2021 18:56:28 -0400 Subject: [PATCH] kernel: Adjust timeout computation for syscall_restart. If the timeout is already >= B_INFINITE_TIMEOUT, we do not need to do any of the following math (which would usually overflow anyway) and can leave the timeout alone. Spotted by kernel undefined behavior sanitizer. --- headers/private/kernel/syscall_restart.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headers/private/kernel/syscall_restart.h b/headers/private/kernel/syscall_restart.h index 88ac6aaafc..bcccb2f1d6 100644 --- a/headers/private/kernel/syscall_restart.h +++ b/headers/private/kernel/syscall_restart.h @@ -50,8 +50,8 @@ syscall_restart_handle_timeout_pre(uint32& flags, bigtime_t& timeout) timeout = *(bigtime_t*)thread->syscall_restart.parameters; if (timeout > 0 && (flags & B_RELATIVE_TIMEOUT) != 0) flags = (flags & ~B_RELATIVE_TIMEOUT) | B_ABSOLUTE_TIMEOUT; - } else if ((flags & B_RELATIVE_TIMEOUT) != 0) { - if (timeout > 0) { + } else if ((flags & B_RELATIVE_TIMEOUT)) { + if (timeout > 0 && timeout < B_INFINITE_TIMEOUT) { timeout += system_time(); // deal with overflow if (timeout < 0)