Skip to content

[daemon] fix unchecked iterator access in async start mounts #4006

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

xmkg
Copy link
Member

@xmkg xmkg commented Mar 26, 2025

MULTI-1913

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.25%. Comparing base (e5b457f) to head (e00810d).
Report is 3607 commits behind head on main.

Files with missing lines Patch % Lines
src/daemon/daemon.cpp 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4006      +/-   ##
==========================================
- Coverage   89.26%   89.25%   -0.02%     
==========================================
  Files         260      260              
  Lines       14693    14696       +3     
==========================================
+ Hits        13116    13117       +1     
- Misses       1577     1579       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xmkg
Copy link
Member Author

xmkg commented Mar 26, 2025

Testing this has proven to be hard since the async_wait_for_ssh_and_start_mounts_for function is a templated non-virtual private function. Also, triggering this condition depends on a synchronization failure or a race condition.

@xmkg
Copy link
Member Author

xmkg commented Mar 26, 2025

Testing this has proven to be hard since the async_wait_for_ssh_and_start_mounts_for function is a templated non-virtual private function. Also, triggering this condition depends on a synchronization failure or a race condition.

I stumbled upon this one while trying to fix the #4005, specifically by calling the monitor->on_restart() function in the VM constructor. That resulted in a crash since the operative_instances map is actively being populated during the constructor call:

auto instance = instance_record[name] =
config->factory->create_virtual_machine(vm_desc, *config->ssh_key_provider, *this);

Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
@xmkg xmkg force-pushed the bugfix/daemon-start-mount-unchecked-itr-access branch from 084d1e3 to e00810d Compare March 28, 2025 22:06
@ricab ricab requested a review from georgeliao April 4, 2025 15:12
@ricab ricab requested a review from Sploder12 April 14, 2025 14:53
Copy link
Contributor

@Sploder12 Sploder12 left a comment

Choose a reason for hiding this comment

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

Good catch! There is still the issue of thread safety, but at least it might not break as bad hopefully if we're lucky.

Copy link
Contributor

@georgeliao georgeliao left a comment

Choose a reason for hiding this comment

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

Nice catch, it looks good to me.

@@ -3425,8 +3425,15 @@ mp::Daemon::async_wait_for_ssh_and_start_mounts_for(const std::string& name, con
fmt::memory_buffer errors;
try
{
auto it = operative_instances.find(name);
auto vm = it->second;
const auto& it = operative_instances.find(name);
Copy link
Contributor

Choose a reason for hiding this comment

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

const auto& and const auto should not make a difference here since the find function returns value.

@xmkg xmkg added this pull request to the merge queue Apr 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Apr 18, 2025
@ricab ricab added this pull request to the merge queue Apr 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Apr 21, 2025
@ricab ricab added this pull request to the merge queue Apr 21, 2025
Merged via the queue into main with commit a907fc3 Apr 22, 2025
14 of 16 checks passed
@ricab ricab deleted the bugfix/daemon-start-mount-unchecked-itr-access branch April 22, 2025 03:22
@ricab ricab added this to the 1.16.0 milestone Jun 13, 2025
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.

4 participants