[SERVER-78828] LDAP host timing data can be inconsistent during sorting Created: 10/Jul/23  Updated: 29/Oct/23  Resolved: 17/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.0-rc8, 4.4.24, 5.0.20, 6.0.9

Type: Bug Priority: Major - P3
Reporter: Varun Ravichandran Assignee: Varun Ravichandran
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
Backwards Compatibility: Fully Compatible
Backport Requested:
v7.0, v6.0, v5.0, v4.4
Sprint: Security 2023-07-24
Participants:

 Description   

When LDAP connection pooling is enabled, the server tracks the average latency for operations on each LDAP host and stores it in a struct called LDAPHostTimingData. This structure is shared between all PooledLDAPConnections that are connected to that particular host and a global LDAPPoolTimingData struct that maintains an unordered map of shared_ptrs to this timing data.

When these shared_ptrs are accessed via the LDAPPoolTimingData map, they are synchronized via a mutex. They are only used in this context for reads. However, writes to each LDAPHostTimingData occur from within the PooledLDAPConnections themselves, which do not use that mutex to synchronize their writes with reads.

As a result, it is possible for the comparator used in this stable sort to become inconsistent as values are updated while the comparator is being called by the sorting algorithm. std::stable_sort causes undefined behavior if the comparator does not return deterministic answers throughout the lifetime of the sort, and it's very possible that this is responsible for some crashes that have been seen during this sort in HELP tickets.



 Comments   
Comment by Githook User [ 04/Aug/23 ]

Author:

{'name': 'Varun Ravichandran', 'email': 'varun.ravichandran@mongodb.com', 'username': 'varunravi98'}

Message: SERVER-78828: Take snapshot of LDAP host timing data before sorting
Branch: v4.4
https://github.com/mongodb/mongo/commit/0b86b9b7b42ad9970c5f818c527dd86c0634243a

Comment by Githook User [ 04/Aug/23 ]

Author:

{'name': 'Varun Ravichandran', 'email': 'varun.ravichandran@mongodb.com', 'username': 'varunravi98'}

Message: SERVER-78828: Take snapshot of LDAP host timing data before sorting
Branch: v5.0
https://github.com/mongodb/mongo/commit/2cd626d8148120319d7dca5824e760fe220cb0de

Comment by Githook User [ 03/Aug/23 ]

Author:

{'name': 'Tausif Rahman', 'email': 'tausif.rahman@mongodb.com', 'username': 'trahman1318'}

Message: Revert "SERVER-78828: Take snapshot of LDAP host timing data before sorting"

This reverts commit 07f47daf292c10a2d4d8a9fe00e98e4746aada7a.
Branch: v4.4
https://github.com/mongodb/mongo/commit/0908ac15cc460a8227fd7da5b6dc5886226bdd94

Comment by Githook User [ 03/Aug/23 ]

Author:

{'name': 'Tausif Rahman', 'email': 'tausif.rahman@mongodb.com', 'username': 'trahman1318'}

Message: Revert "SERVER-78828: Take snapshot of LDAP host timing data before sorting"

This reverts commit 1addd9c7be2438b6357254d2b50a69be113ccb60.
Branch: v5.0
https://github.com/mongodb/mongo/commit/7e3b7ea42e01a7d5b9ec350a753ce2d4ff0e9229

Comment by Githook User [ 26/Jul/23 ]

Author:

{'name': 'Varun Ravichandran', 'email': 'varun.ravichandran@mongodb.com', 'username': 'varunravi98'}

Message: SERVER-78828: Take snapshot of LDAP host timing data before sorting
Branch: v4.4
https://github.com/mongodb/mongo/commit/07f47daf292c10a2d4d8a9fe00e98e4746aada7a

Comment by Githook User [ 25/Jul/23 ]

Author:

{'name': 'Varun Ravichandran', 'email': 'varun.ravichandran@mongodb.com', 'username': 'varunravi98'}

Message: SERVER-78828: Take snapshot of LDAP host timing data before sorting
Branch: v5.0
https://github.com/mongodb/mongo/commit/1addd9c7be2438b6357254d2b50a69be113ccb60

Generated at Thu Feb 08 06:39:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.