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

prevent race conditions with uvwasi_fd_close() #91

Merged
merged 1 commit into from
Jan 22, 2020
Merged

Conversation

cjihrig
Copy link
Collaborator

@cjihrig cjihrig commented Jan 22, 2020

This depends on #90 (the first commit in this PR).

uvwasi_fd_close() performed the following operations:

  • lock the file descriptor mutex
  • close the file
  • release the file descriptor mutex
  • call the file table's remove() function

Once the fd's mutex is released, another thread could acquire it
before the fd is removed from the file table. If this happens,
remove() could destroy a held mutex.

This commit updates uvwasi_fd_close() to perform the entire
sequence while holding the file table's lock, preventing new
acquisitions of the fd's mutex.

Fixes: #88

uvwasi_fd_close() performed the following operations:

- lock the file descriptor mutex
- close the file
- release the file descriptor mutex
- call the file table's remove() function

Once the fd's mutex is released, another thread could acquire it
before the fd is removed from the file table. If this happens,
remove() could destroy a held mutex.

This commit updates uvwasi_fd_close() to perform the entire
sequence while holding the file table's lock, preventing new
acquisitions of the fd's mutex.

Fixes: #88
@cjihrig cjihrig merged commit eea4508 into master Jan 22, 2020
@cjihrig cjihrig deleted the close-race branch January 22, 2020 15:04
This was referenced Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition in uvwasi_fd_close()
2 participants