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

clarify system call verification data copying policies #23974

Merged

Conversation

andrewboie
Copy link
Contributor

@andrewboie andrewboie commented Mar 31, 2020

Expand on policies on what to do with parameters passed to system calls by reference.

Security people, please feel free to throw spitballs at this.

The special case for large data buffers I think is needed, although it will require some care in writing the implementation functions. Otherwise, there will be the overhead of both a heap allocation to duplicate the buffer and an extra copy operation. I am particularly averse to requiring a heap for what is a very common operation in syscalls.

Also, what used to be called "handler functions" are now called "verification functions", update docs for this.

Andrew Boie added 2 commits March 31, 2020 14:24
Handler functions are now referred to as verification functions,
update documentation to reflect this.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Show best practices when handling parameters passed to
system calls by reference.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@andrewboie
Copy link
Contributor Author

One detail I'm not sure of: what is Zephyr's polices on VLAs? I know we have a couple verifiers that use them.

@andrewboie andrewboie changed the title Added syscall documentation clarify system call verification data copying policies Mar 31, 2020
@ceolin
Copy link
Member

ceolin commented Mar 31, 2020

I'd say we should not have VLAs, there are unspecified and undefined behaviours associated with VLAs. e.g: when the size is 0 or negative

The size expression in an array declaration is not a constant expression and evaluates
at program execution time to a nonpositive value (6.7.5.2). 

Also, it is undefined what happens when the allocation fails and there is not way to figure it out.
Another thing that Linus pointed is:

It generates much more code, and much _slower_ code (and more fragile code), than just using a fixed key size would have done." 

MISRA-C 18.8 requires to no use VLA as well

as a block of memory to write to some hardware destination, this data
must be read without any processing. No conditional logic can be implemented
due to the data buffer's contents. If such logic is required a copy must be
made.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've covered my concern :)

Copy link
Member

@ceolin ceolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is pretty much what we have discussed. I'm ok with that, thanks for documenting it.

Copy link
Collaborator

@d3zd3z d3zd3z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this clarification is reasonable. Things are a little ambiguous because we really haven't come up with a threat model to describe what usermode addresses. But these changes do seem reasonable things to do.

verification function, and only perform parameter checks on the copies, which
user threads will never have access to. The implementation functions get passed
the copy and not the original data sent by the user. The
:c:func:`z_user_to_copy()` and :c:func:`z_user_from_copy()` APIs exist for
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are kind of confusing. Any reason to not use z_copy_to_user and z_copy_from_user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these APIs already exist, and Zephyr naming convention (not followed 100%) is to have the verb last.

@andrewboie
Copy link
Contributor Author

Things are a little ambiguous because we really haven't come up with a thread model to describe what usermode addresses

@d3zd3z this is a serious assertion. We have a threat model posted here: https://docs.zephyrproject.org/latest/reference/usermode/index.html. This is the first time anyone has communicated that this is insufficient. Please provide specific, actionable feedback on what is ambiguous or missing as soon as possible. Why have you not spoken about this before??

@d3zd3z
Copy link
Collaborator

d3zd3z commented Apr 1, 2020

We have a threat model posted here

My sincerest apologies for the unbased claim. I was not aware of the threat model.

@nashif nashif merged commit cc680a8 into zephyrproject-rtos:master Apr 2, 2020
@andrewboie andrewboie deleted the added-syscall-documentation branch September 24, 2020 20:44
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.

7 participants