Skip to content

Commit 3fcb96a

Browse files
author
Flavio Ceolin
committed
userspace: Additional checks in K_SYSCALL_MEMORY
This macros needed additional checks before invoking arch_buffer_validate. - size can not be less then 0. Some functions invoke this macro using signed type which will be promote to unsigned when invoking arch_buffer_validate. We need to do an early check. - We need to check for possible overflow, since a malicious user application could use a negative number that would be promoted to a big value that would cause a integer overflow when adding it to the buffer address, leading to invalid checks. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
1 parent 1dc6279 commit 3fcb96a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/zephyr/internal/syscall_handler.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ int k_usermode_string_copy(char *dst, const char *src, size_t maxlen);
413413
* functionality in the Zephyr tree.
414414
*/
415415
#define K_SYSCALL_MEMORY(ptr, size, write) \
416-
K_SYSCALL_VERIFY_MSG(arch_buffer_validate((void *)ptr, size, write) \
417-
== 0, \
416+
K_SYSCALL_VERIFY_MSG((size >= 0) && !Z_DETECT_POINTER_OVERFLOW(ptr, size) \
417+
&& (arch_buffer_validate((void *)ptr, size, write) \
418+
== 0), \
418419
"Memory region %p (size %zu) %s access denied", \
419420
(void *)(ptr), (size_t)(size), \
420421
write ? "write" : "read")

0 commit comments

Comments
 (0)