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

vm: _page_get() may cause unexpected behavior #1074

Open
niewim19 opened this issue May 10, 2024 · 2 comments
Open

vm: _page_get() may cause unexpected behavior #1074

niewim19 opened this issue May 10, 2024 · 2 comments
Labels

Comments

@niewim19
Copy link
Contributor

Function that can cause a problem: phoenix-rtos-kernel/vm/page.c:_page_get(): https://github.com/phoenix-rtos/phoenix-rtos-kernel/blob/f29031f5ca6707f70e2720819f1255828a0c5cba/vm/page.c#L177

The problem: _page_get() searches through the binary tree without locking the pages lock. This function is used here: https://github.com/phoenix-rtos/phoenix-rtos-kernel/blob/f29031f5ca6707f70e2720819f1255828a0c5cba/vm/map.c#L949

There is possibility that one thread indirectly executes page deallocation (for example through msg_respond()->msg_release()->vm_pageFree()) while other thread indirectly seeks pages (syscalls_beginthreadex()->proc_put()->process_destroy()->vm_mapDestroy()-> _page_get()) then the binary tree might be changed while it is searched which leads to undefined behavior. I did not examine in detail this approach (maybe other lock prevents it) but there is also other use in https://github.com/phoenix-rtos/phoenix-rtos-kernel/blob/f29031f5ca6707f70e2720819f1255828a0c5cba/vm/object.c#L201 which is also unguarded.

astalke added a commit to phoenix-rtos/phoenix-rtos-kernel that referenced this issue May 16, 2024
@astalke
Copy link
Contributor

astalke commented May 16, 2024

I've made a test branch that adds guarding locks and fortunately it doesn't cause a deadlock. I haven't checked yet if there is another lock protecting everything.

@astalke
Copy link
Contributor

astalke commented May 16, 2024

There is no lock in the call chain:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants