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

CFE_EVS_WriteLogFileCmd requires recursive locking #373

Closed
thewonderidiot opened this issue Oct 10, 2019 · 2 comments · Fixed by #388
Closed

CFE_EVS_WriteLogFileCmd requires recursive locking #373

thewonderidiot opened this issue Oct 10, 2019 · 2 comments · Fixed by #388
Assignees
Labels
Milestone

Comments

@thewonderidiot
Copy link

Describe the bug
The function CFE_EVS_WriteLogFileCmd in cfe_evs_log.c locks CFE_EVS_GlobalData.EVS_SharedDataMutexID for the entire duration of the function. If an error is encountered, it will call EVS_SendEvent, which also tries to lock the mutex. If the OS/OSAL do not support recursive locking on mutexes, this will lead to a deadlock.

To Reproduce
Steps to reproduce the behavior:

  1. Cause an error during the execution of CFE_EVS_WriteLogFileCmd (by e.g. giving it an invalid filename).

Expected behavior
This may be expected behavior, if cFE requires its mutexes to be recursively lockable. If so, this isn't a bug and I'll have to modify our OSAL. But if that is not the expectation, then I would this function should relinquish its lock before calling EVS_SendEvent.

More specifically, it looks like the this can be accomplished by moving the line

   OS_MutSemGive(CFE_EVS_GlobalData.EVS_SharedDataMutexID);

to just before each instance of EVS_SendEvent() in the function. By each of these points, this function is done accessing sensitive EVS data.

Code snips

System observed on:

  • Capella flight computer
  • OS: FreeRTOS 10.1.1
  • Versions: cFE 6.5.0, OSAL 4.2.0 (plus in-house FreeRTOS port)

Additional context
I found this while testing our fix for #372.

Reporter Info
Mike Stewart, Capella Space.

@jphickey
Copy link
Contributor

Has this bug been checked in the current version?

This bug is for cFE 6.5.0. The logging code was considerably updated in CFE 6.6.0.

@jphickey
Copy link
Contributor

I checked the code and concur that this still does apply to the current version. The function is now called CFE_EVS_WriteLogDataFileCmd() but it is basically the same.

We don't support recursive locking. The code must be updated to avoid calling EVS_SendEvent while holding the lock. There are several calls to this function. As a general style it is preferred to have a single sem give that corresponds to a single sem take, and a code path that always goes through either both or neither.

My vote would be to defer the actual EVS_SendEvent until the process is done. It looks like it can only be a write error or success. I can implement this.

@jphickey jphickey self-assigned this Oct 11, 2019
jphickey added a commit to jphickey/cFE that referenced this issue Oct 12, 2019
The mutex for the log file write during the WriteLogFileCmd
excution was held longer than it should have been.

This lock must *NOT* be held during EVS_SendEvent, as this
will cause deadlock.

This moves the mutex to protect only the area that actually
accesses the log data, and it moves all send event calls
to be AFTER the mutex is released.
@skliper skliper added this to the 6.8.0 milestone Oct 13, 2019
@skliper skliper added the bug label Oct 14, 2019
skliper pushed a commit that referenced this issue Oct 31, 2019
The mutex for the log file write during the WriteLogFileCmd
excution was held longer than it should have been.

This lock must *NOT* be held during EVS_SendEvent, as this
will cause deadlock.

This moves the mutex to protect only the area that actually
accesses the log data, and it moves all send event calls
to be AFTER the mutex is released.
skliper added a commit that referenced this issue Oct 31, 2019
Fixes #361, #373, #374, #381
Code reviewed and approved at 20191023 and 30 CCBs
skliper added a commit that referenced this issue Oct 31, 2019
Fixes #361, #373, #374, #381
Code reviewed and approved at 20191023 and 30 CCBs
@skliper skliper closed this as completed in bbdf201 Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants