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

Token fixes: reattach token on container reload #511

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

quitschbo
Copy link
Member

daemon/cmld: reattach token on container reload

On reload the new container object is created with container_new()
and afterwards the previous object is deleted by a call to
container_free(). Makes sens to first try to create the new updated
container object and only if this succeeds, the old object is
destroyed. However on container_new() the token is attached to the
scd and on container_free() it is removed:

Thus we now have the following behavior:

  1. We have the token attached in the scd. The config updated kicks
    in and we get a new container object created by container_new().
    A second attach is made in the scd:
    control.c+221: Token already exists.

  2. That is ok, we just ignore that in the scd and the new updated
    container object is created successfully.

  3. However afterwards the container_free()
    is made and also the scd resources are released by an internal
    call to usbtoken_free() in scd:
    usbtoken.c+603: Closing CT interface (ctn=0) done.

  4. Since both container objects map to the same token in the scd, we
    now have no token attached in the scd anymore.

  5. An attempt to do anything token related in the cmld now results
    in that the token is not available:
    control.c+254: No token loaded, unlock failed

Simply fix this by reattaching the token after the container_free()
of the outdated container.

Fixes: c13ef81 ("daemon/cmld: cleanup observer handling")
Signed-off-by: Michael Weiß [email protected]

To avoid references to destroyed container objects, use deep copies
of container_usbdev_t elements in tracking list allow_on_unplug_list.
E.g., on container reload the corresponding container is freed and so
is the list of usbdevs of which the references were held in other
container's 'allow_on_unplug_list's.
This use-after-free was triggered if the container was reloaded and
started again.

Fixes: 1dd99f4 ("daemon/c_hotplug: Deny access to USB tokens")
Signed-off-by: Michael Weiß <[email protected]>
On reload the new container object is created with container_new()
and afterwards the previous object is deleted by a call to
container_free(). Makes sens to first try to create the new updated
container object and only if this succeeds, the old object is
destroyed. However on container_new() the token is attached to the
scd and on container_free() it is removed:

Thus we now have the following behavior:

1) We have the token attached in the scd. The config updated kicks
   in and we get a new container object created by container_new().
   A second attach is made in the scd:
      <INFO>  control.c+221: Token already exists.

2) That is ok, we just ignore that in the scd and the new updated
   container object is created successfully.

3) However afterwards the container_free(<outdated container object>)
   is made and also the scd resources are released by an internal
   call to usbtoken_free() in scd:
      <DEBUG> usbtoken.c+603: Closing CT interface (ctn=0) done.

4) Since both container objects map to the same token in the scd, we
   now have no token attached in the scd anymore.

5) An attempt to do anything token related in the cmld now results
   in that the token is not available:
      <ERROR> control.c+254: No token loaded, unlock failed

Simply fix this by reattaching the token after the container_free()
of the outdated container.

Fixes: c13ef81 ("daemon/cmld: cleanup observer handling")
Signed-off-by: Michael Weiß <[email protected]>
@quitschbo quitschbo requested a review from k0ch4lo December 5, 2024 12:18
@quitschbo quitschbo merged commit 7ae3e11 into gyroidos:kirkstone Dec 6, 2024
3 checks passed
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.

2 participants