Skip to content
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

Merged

Conversation

andrewboie
Copy link
Contributor

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.

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);
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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

@agross-oss agross-oss added the area: Security Security label Oct 10, 2017
@andrewboie
Copy link
Contributor Author

Note to self: CI error is need to fix include path in obj_validation test case

 /home/buildslave/src/github.com/zephyrproject-rtos/zephyr/tests/kernel/mem_protect/obj_validation/src/main.c: In function ‘test_bad_object’:
/home/buildslave/src/github.com/zephyrproject-rtos/zephyr/tests/kernel/mem_protect/obj_validation/src/main.c:26:10: error: implicit declaration of function ‘_k_object_validate’ [-Werror=implicit-function-declaration]
  return !_k_object_validate(sem, K_OBJ_SEM, 0);
          ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

@andrewboie
Copy link
Contributor Author

fixed array bounds multiplication issue with an additional patch

#define _SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write, ssf) \
do { \
u32_t product; \
_SYSCALL_VERIFY_MSG(!__builtin_umul_overflow((u32_t)nmemb, \
Copy link
Collaborator

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.

@andrewboie andrewboie force-pushed the syscall-handler-cleanups branch from fd05130 to 8279b6c Compare October 11, 2017 16:53
@andrewboie
Copy link
Contributor Author

Added parens around macro arguments.
CI failure fixed by #4275

Copy link
Collaborator

@lpereira lpereira left a 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!

@andrewboie
Copy link
Contributor Author

CI issue should be fixed by #4280 I'll rebase once that goes in.

Andrew Boie added 5 commits October 11, 2017 17:30
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]>
@andrewboie andrewboie force-pushed the syscall-handler-cleanups branch from 8279b6c to 3985f75 Compare October 12, 2017 00:31
@andrewboie andrewboie merged commit 38ac235 into zephyrproject-rtos:master Oct 12, 2017
@andrewboie andrewboie deleted the syscall-handler-cleanups branch October 12, 2017 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants