-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syscall handler cleanups #4255
Syscall handler cleanups #4255
Conversation
kernel/msg_q.c
Outdated
_SYSCALL_IS_OBJ(q, K_OBJ_MSGQ, 1, ssf); | ||
_SYSCALL_MEMORY(buffer, msg_size * max_msgs, 1, ssf); | ||
_SYSCALL_OBJ_INIT(q, K_OBJ_MSGQ, ssf); | ||
_SYSCALL_MEMORY_WRITE(buffer, msg_size * max_msgs, ssf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the patch, but if msg_size * max_msgs
overflows, since they're both unsigned, this check can be bypassed. Better to use __builtin_mul_overflow()
, maybe wrapped in a _SYSCALL_MEMORY_WRITE_ARRAY()
macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other instances where a multiplication is performed, which could lead to the same problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll add this to this PR good catch
Note to self: CI error is need to fix include path in obj_validation test case
|
fixed array bounds multiplication issue with an additional patch |
kernel/include/syscall_handler.h
Outdated
#define _SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write, ssf) \ | ||
do { \ | ||
u32_t product; \ | ||
_SYSCALL_VERIFY_MSG(!__builtin_umul_overflow((u32_t)nmemb, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put parenthesis around nmemb
and size
, as they're likely to be used in expressions, and you want the whole expression cast as u32_t
.
fd05130
to
8279b6c
Compare
Added parens around macro arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better, thanks!
CI issue should be fixed by #4280 I'll rebase once that goes in. |
This API only gets used inside system call handlers and a specific test case dedicated to it. Move definition to the private kernel header along with the rest of the defines for system call handlers. A non-userspace inline variant of this function is unnecessary and has been deleted. Signed-off-by: Andrew Boie <[email protected]>
Expecting stringified expressions to be completely comprehensible to end users is wishful thinking; we really need to express what a failed system call verification step means in human terms in most cases. Memory buffer and kernel object checks now are implemented in terms of _SYSCALL_VERIFY_MSG. Signed-off-by: Andrew Boie <[email protected]>
Instead of boolean arguments to indicate memory read/write permissions, or init/non-init APIs, new macros are introduced which bake the semantics directly into the name of the macro. Signed-off-by: Andrew Boie <[email protected]>
Use new _SYSCALL_OBJ/_SYSCALL_OBJ_INIT macros. Use new _SYSCALL_MEMORY_READ/_SYSCALL_MEMORY_WRITE macros. Some non-obvious checks changed to use _SYSCALL_VERIFY_MSG. Signed-off-by: Andrew Boie <[email protected]>
Computing the total size of the array need to handle the case where the product overflow a 32-bit unsigned integer. Signed-off-by: Andrew Boie <[email protected]>
8279b6c
to
3985f75
Compare
The macros in syscall_handler.h have been updated and extended for clarity.
A C API only used in handlers moved to the proper header.
Syscall handlers updated to use the new macros.