google / fscrypt

Go tool for managing Linux filesystem encryption
Apache License 2.0
886 stars 99 forks source link

Concurrency issue when new mounts are added #411

Closed NymanRobin closed 5 months ago

NymanRobin commented 5 months ago

In the filesystem/mountpoint.go file the mountsByDevice map is recreated on each call of update UpdateMountInfo. This causes problem, if these steps occurs!

  1. Mount is assigned to policy.context
  2. UpdateMountInfo is called
  3. policy.apply is called

This will result in the fact that the policy.context.Mount will have the old memory address from the old mountsByDevice map while the filesystems.findMount will find the new object and then in the comparison the following error will be thrown in the policy.apply function.

(%!w(*actions.ErrDifferentFilesystem=&{0xc00157b130 0xc00208a140}).

This currently affects the ceph-csi project and more information can be found in this issue: https://github.com/ceph/ceph-csi/issues/4592

I have tested a solution were only the new mount objects are updated and that would at least work for my specific use-case, I will open a PR for this and look forward to any feedback

josephlr commented 5 months ago

Another approach to fixing this would just be to compare the Mounts by value rather than by pointer.

Happy to review any PR!

NymanRobin commented 5 months ago

Great point @josephlr! I went ahead with the comparison as that removed the responsibility of removing unused mounts from the map and made it a tad bit easier

ebiggers commented 5 months ago

Fixed by 068b9f8f5dec46b222470f6d3f03244ba5b65f5c

NymanRobin commented 5 months ago

Thanks for the helping me get this change in @ebiggers and @josephlr! I've got one more question: when could we expect a new release of fscrypt? Do you have any plans in mind? I'm asking because I'd like to get this fix into ceph-csi.

ebiggers commented 5 months ago

There was a release recently, and there haven't been many changes since then, so it probably will be at least a few months before we do another release.