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

mon: fix iterator mishandling in PGMap::apply_incremental #49480

Merged
merged 1 commit into from Jul 19, 2023

Conversation

ctheune
Copy link
Contributor

@ctheune ctheune commented Dec 16, 2022

Contribution Guidelines

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows

@ctheune ctheune requested a review from a team as a code owner December 16, 2022 11:43
@ctheune ctheune marked this pull request as draft December 16, 2022 11:44
@ctheune
Copy link
Contributor Author

ctheune commented Dec 16, 2022

This is a draft to wire it up with the issue tracker. Happy to fill in the template and clean up after discussion about this fix.

if (i->first.second == *p) {
pg_pool_sum[i->first.first].sub(i->second);
pool_statfs.erase(i);
i = pool_statfs.erase(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

From core PR scrub: this looks like a valid issue. We have a tracker for that?

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, @osnyx! I linked these tickets.

Would you mind to rework the commit description by:

  1. putting the Fixes: https://tracker.ceph.com/issues/58303 line just before the Signed-off-by,
  2. changing the title to: mon: fix iterator mishandling in PGMap::apply_incremental?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's take a look on the pool_statfs member:

  typedef mempool::pgmap::map<
    std::pair<int64_t, int>,  // <pool, osd>
    store_statfs_t>
      per_osd_pool_statfs_t;

  per_osd_pool_statfs_t pool_statfs;

The underlying type is std::map. From the doc:

References and iterators to the erased elements are invalidated. Other references and iterators are not affected.

My understanding is that we shall not i++ if the i-pointed element has been erased. This stays coherent with the API design (returning new iterator) and even with the example there:

    // erase all odd numbers from c
    for (auto it = c.begin(); it != c.end();)
    {
        if (it->first % 2 != 0)
            it = c.erase(it);
        else
            ++it;
    }

@amathuria amathuria self-requested a review June 27, 2023 16:50
Copy link
Contributor

@rzarzynski rzarzynski left a comment

Choose a reason for hiding this comment

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

The core change LGTM! Putting DNM only b/c of the commit description.

if (i->first.second == *p) {
pg_pool_sum[i->first.first].sub(i->second);
pool_statfs.erase(i);
i = pool_statfs.erase(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's take a look on the pool_statfs member:

  typedef mempool::pgmap::map<
    std::pair<int64_t, int>,  // <pool, osd>
    store_statfs_t>
      per_osd_pool_statfs_t;

  per_osd_pool_statfs_t pool_statfs;

The underlying type is std::map. From the doc:

References and iterators to the erased elements are invalidated. Other references and iterators are not affected.

My understanding is that we shall not i++ if the i-pointed element has been erased. This stays coherent with the API design (returning new iterator) and even with the example there:

    // erase all odd numbers from c
    for (auto it = c.begin(); it != c.end();)
    {
        if (it->first % 2 != 0)
            it = c.erase(it);
        else
            ++it;
    }

@rzarzynski rzarzynski marked this pull request as ready for review July 7, 2023 13:49
@rzarzynski rzarzynski added the DNM label Jul 7, 2023
Fixes: https://tracker.ceph.com/issues/58303
Signed-off-by: Oliver Schmidt <os@flyingcircus.io>, Christian Theune <ct@flyingcircus.io>
@osnyx
Copy link

osnyx commented Jul 7, 2023

@rzarzynski Requested changes are done. Thanks for taking care of this.

@rzarzynski
Copy link
Contributor

 Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/g/git/git_2.34.1-1ubuntu1.6_arm64.deb  Temporary failure resolving 'us.ports.ubuntu.com'

@rzarzynski
Copy link
Contributor

jenkins retest this please

@rzarzynski rzarzynski changed the title mon: fix deletion in iterator while updating the osd map mon: fix iterator mishandling in PGMap::apply_incremental Jul 9, 2023
@rzarzynski
Copy link
Contributor

Thanks for fixing this, @ctheune & @osnyx!

@neha-ojha
Copy link
Member

jenkins test make check

@taodd
Copy link
Contributor

taodd commented Jul 11, 2023

Hit the same flaw code, see https://tracker.ceph.com/issues/61912.
In my case, the loop just keeps iterating on the invalid iterator without crashing.

@ctheune
Copy link
Contributor Author

ctheune commented Jul 11, 2023

Thanks for fixing this, @ctheune & @osnyx!

Happy to! Glad this got picked up eventually - I was a bit worried that this didn't get any attention at all.

Getting it merged does increase motivation for future patches. ;)

@ljflores
Copy link
Contributor

Hey @ctheune can you fill out the checklist in #49480 (comment)?

@ctheune
Copy link
Contributor Author

ctheune commented Jul 13, 2023

Hey @ctheune can you fill out the checklist in #49480 (comment)?

Sure - done!

@yuriw yuriw merged commit ad569f6 into ceph:main Jul 19, 2023
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants