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

Incorrect call to OS_ObjectIdCompose_Impl in OS_TimerDelete #649

Closed
jphickey opened this issue Nov 10, 2020 · 1 comment · Fixed by #666 or #680
Closed

Incorrect call to OS_ObjectIdCompose_Impl in OS_TimerDelete #649

jphickey opened this issue Nov 10, 2020 · 1 comment · Fixed by #666 or #680
Assignees
Labels
Milestone

Comments

@jphickey
Copy link
Contributor

Describe the bug
OSAL has an incorrect setting of first_cb when deleting timers.

if (local->next_ref != local_id)
{
OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TIMEBASE, local->next_ref,
&OS_timebase_table[local->timebase_ref].first_cb);
}

The second argument to OS_ObjectIdCompose_Impl() is a serial number, not a table index. These are only the same value until table entries start to be re-used, after this they become different, and this will start to fail. This should really not be using OS_ObjectIdCompose_Impl() at all here.

To Reproduce

  • Create and delete several timebases - at least OS_MAX_TIMEBASES - such that table entries start to be re-used.
  • Create another valid timebase for the test (do not delete).
  • Create at least two timers based on this timebase
  • Delete one of the timers.

At this point the ID in the timebase callback ring (first_cb member) may refer to an invalid entry - a timebase ID which does not exist.

Expected behavior
Should look up the active_id from the actual table entry instead - do not re-compose the ID, because next_ref is a table index, not a serial number.

System observed on:
Ubuntu 20.04

Additional context
It is only possible to trigger this after a rather extensive sequence of creating and deleting these resources. So this is probably unlikely to ever occur in a real system where timers are typically created and run forever. Should still be fixed though.

This was initially discovered by enforcing type-safety in the osal_index_t and osal_id_t - during this scrub it revealed that this was passing an osal_index_t to a function which is supposed to accept a serial number. So type safety = good.

Reporter Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey self-assigned this Nov 10, 2020
@jphickey jphickey added the bug label Nov 10, 2020
@skliper skliper added this to the 6.0.0 milestone Nov 12, 2020
@jphickey
Copy link
Contributor Author

jphickey commented Dec 1, 2020

Note - found an easier way to reproduce this error, which is to simply delete timers in a different order than they were created. Turns out all of the current functional tests create and delete in the same order, so it wasn't noticed.

Will update at least one test case to delete timers in a different order than they were created.

The recommended solution is to use the full object ID - not just the table index - to form the linked list of timer callbacks. This will be more robust and be simpler too, at least after #648 is done.

The reason #648 is relevant/related here is that it can provide a simpler and more reliable way to tracking table lock status via lock tokens. Without this it becomes difficult to track the lock status when using functions like OS_ObjectIdGetById inside other functions.

jphickey added a commit to jphickey/osal that referenced this issue Dec 2, 2020
For the linked list of timer callbacks, use the full object ID
value rather than just the index.  This ensures consistency
in the list and also makes it easier to manage.
jphickey added a commit to jphickey/osal that referenced this issue Dec 2, 2020
For the linked list of timer callbacks, use the full object ID
value rather than just the index.  This ensures consistency
in the list and also makes it easier to manage.
jphickey added a commit to jphickey/osal that referenced this issue Dec 2, 2020
For the linked list of timer callbacks, use the full object ID
value rather than just the index.  This ensures consistency
in the list and also makes it easier to manage.
jphickey added a commit to jphickey/osal that referenced this issue Dec 2, 2020
For the linked list of timer callbacks, use the full object ID
value rather than just the index.  This ensures consistency
in the list and also makes it easier to manage.
jphickey added a commit to jphickey/osal that referenced this issue Dec 4, 2020
For the linked list of timer callbacks, use the full object ID
value rather than just the index.  This ensures consistency
in the list and also makes it easier to manage.
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants