-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: 8.0.9
-
Component/s: None
-
Storage Execution
-
Fully Compatible
-
ALL
-
Storage Execution 2026-11-23
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I found a potential null pointer dereference in getRetryableWriteTransactionParticipantCatalog() in MongoDB 8.0.9:
In this method, the return value of OperationContextSession::get(opCtx) is passed to another overload of getRetryableWriteTransactionParticipantCatalog() without a prior null check:
{{auto session = OperationContextSession::get(opCtx);
return getRetryableWriteTransactionParticipantCatalog(session);}}
According to the documentation of OperationContextSession::get(), this method may return nullptr if the operation context has no checked-out session:
https://github.com/mongodb/mongo/blob/r8.0.9/src/mongo/db/session/session_catalog.h
"Returns the session currently checked out by 'opCtx', or nullptr if the opCtx has no checked out session."
If OperationContextSession::get(opCtx) returns nullptr, the null pointer is passed to getRetryableWriteTransactionParticipantCatalog(Session* session), where it is dereferenced without a prior check:
{{if (const auto parentSession = session->getParentSession()) {
return retryableWriteTransactionParticipantCatalogDecoration(parentSession);
}}}
This may lead to undefined behavior.
Although the comment above getRetryableWriteTransactionParticipantCatalog(OperationContext*) mentions a checked-out session, the function does not explicitly enforce this precondition.
It is recommended to add an explicit check before passing the session pointer to the overloaded function:
{{auto session = OperationContextSession::get(opCtx);
invariant(session);
return getRetryableWriteTransactionParticipantCatalog(session);}}
This would explicitly enforce the expected precondition and prevent an unchecked null pointer dereference.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Reporter: Grebennikov Aleksandr (grebennikov@bmstu.ru
)