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

Fix more encryption issues on exFAT filesystem #7162

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

ironage
Copy link
Contributor

@ironage ironage commented Nov 23, 2023

Fixes #7156
The issues here can be reproduced by running the core tests on an exFAT file system. See tools/run-tests-on-exfat.sh
Specifically, opening several new encrypted Realms at the same time in the same process. For example, I used UNITTEST_FILTER=*_EncryptionKey* and UNITTEST_REPEAT=1000 to reliably debug this.

The issue is the same underlying issue as described in #6959 where the exFAT file system does not actually reserve the inode until the file is non-empty. The effect of having the unique id reused across multiple files in this case is that the static mappings_by_file structure merges encrypted mappings across different files. This can lead to data from one file ending up in the other, and general corruption.

In addition to fixing the issue, and cleaning up the surrounding code a bit, I have added an assertion in the File::get_unique_id() method to check that it is called on a non-empty file so that we don't hit this bug again.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed
  • bindgen/spec.yml, if public C++ API changed

@ironage ironage self-assigned this Nov 23, 2023
@ironage ironage changed the title Js/multi encryption exfat Fix more encryption issues on exFAT filesystem Nov 23, 2023
Copy link

coveralls-official bot commented Nov 23, 2023

Pull Request Test Coverage Report for Build james.stone_440

  • 91 of 99 (91.92%) changed or added relevant lines in 6 files are covered.
  • 18 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.2%) to 91.814%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/util/file.cpp 57 61 93.44%
test/test_file.cpp 4 8 50.0%
Files with Coverage Reduction New Missed Lines %
src/realm/alloc_slab.cpp 1 95.6%
src/realm/sync/noinst/server/server.cpp 1 76.02%
test/test_query2.cpp 1 99.08%
src/realm/util/file_mapper.cpp 2 90.29%
src/realm/query_expression.cpp 3 87.01%
src/realm/sync/noinst/client_reset.cpp 4 93.5%
src/realm/util/file.cpp 6 96.02%
Totals Coverage Status
Change from base Build 1873: 0.2%
Covered Lines: 232512
Relevant Lines: 253242

💛 - Coveralls

…ave the same fallback tmp path which could cause issues if running on a filesystem that doesn't support mkfifo such as exFAT
@ironage ironage marked this pull request as draft November 24, 2023 01:31
@ironage
Copy link
Contributor Author

ironage commented Nov 29, 2023

Ping for reviews @finnschiermer @kiburtse @tgoyne

src/realm/alloc_slab.cpp Outdated Show resolved Hide resolved
src/realm/util/file.cpp Outdated Show resolved Hide resolved
asserting in consideration of external processes.
Use prealloc to size the file instead of a separate resize operation.
Add the file path to help debug exceptions.
src/realm/group.cpp Show resolved Hide resolved
src/realm/util/file.cpp Outdated Show resolved Hide resolved
src/realm/util/file.cpp Outdated Show resolved Hide resolved
src/realm/util/file_mapper.cpp Outdated Show resolved Hide resolved
@ironage ironage requested a review from kiburtse December 4, 2023 23:53
Copy link
Contributor

@finnschiermer finnschiermer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! :-D

@ironage ironage merged commit c3ed40b into master Dec 6, 2023
30 of 33 checks passed
@ironage ironage deleted the js/multi-encryption-exfat branch December 6, 2023 18:11
@kraenhansen
Copy link
Member

since the beginning

Was encryption a feature of the 1.0.0 Realm Core release?

@ironage
Copy link
Contributor Author

ironage commented Dec 11, 2023

@kraenhansen yes, there was encryption in v1.0.0 and I'm fairly certain the bug was present there because we had the static mappings_for_file structure as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EncryptionKeyCheck test failure on exfat
5 participants