[MONGOCRYPT-481] libmongocrypt needs mcr_dll_path which isn't implemented for all platforms Created: 30/Aug/22  Updated: 04/Dec/23  Resolved: 30/Oct/23

Status: Closed
Project: Libmongocrypt
Component/s: C library
Affects Version/s: 1.6.0-alpha0
Fix Version/s: 1.9.0

Type: Improvement Priority: Unknown
Reporter: Calvin Buckley Assignee: Kevin Albertson
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to MONGOCRYPT-603 Don't return a compile error if dll_p... Closed
Quarter: FY24Q3

 Description   

libmongocrypt wants to know the path for a loaded library, seemingly to compare if a library is already loaded (_validate_csfle_singleton). It has an implementation for Windows, macOS, and Linux (though this uses dlinfo which is also available on Solaris and *BSD, AFAIK). However, if there is no implementation, then it'll fail the build with an error. I'm building for AIX, so this is where I hit it.

I looked into implementing this on AIX myself, but it did seem pretty tricky. dlopen returns an opaque ID that starts from zero and increments. Now, dladdr can be implemented in terms of calling a function that gets all loaded libraries (loadquery with L_GETINFO) and checking if the pointer is in their text/data ranges. However, dlinfo uses the value of dlopen, and the structure returned by loadquery that doesn't contain the IDs that libdl uses internally. I really want to avoid reaching into dynamic linker internals if I don't have to.

An alternative might be to make it so that not having this function doesn't count as a hard error, and if not available, skip the validation logic. It'd be a lot easier than trying to implement it on all platforms, and I don't think it's that critical anyways.



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

Author:

{'name': 'Calvin Buckley', 'email': 'calvin@cmpct.info', 'username': 'NattyNarwhal'}

Message: MONGOCRYPT-603 Don't return a compile error if dll_path unsupported (#708)

This returns an error to the caller instead of a hard compile error.
The 34a6e9d585e4b8fd1c4f18ffa57a08a6f3338546 commit partially addressed
this, but this file wasn't touched by it

This lets mongocrypt work on a platform without dll_path support, like
AIX, but CSFLE is untested.

---------

Co-authored-by: vector-of-bool <vectorofbool@gmail.com>
Branch: master
https://github.com/mongodb/libmongocrypt/commit/4667d6ca888a465348fbc15fda459a652e67f39c

Comment by Calvin Buckley [ 01/Nov/23 ]

I think a simple patch might be:

{{
diff --git a/src/mongocrypt-util.c b/src/mongocrypt-util.c
index 205ce26..958a870 100644
— a/src/mongocrypt-util.c
+++ b/src/mongocrypt-util.c
@@ -90,7 +90,7 @@ current_module_result current_module_path(void)

{ ret_str = mstr_copy_cstr(info.dli_fname); }

#else
-#error "Don't know how to get the module path on this platform"
+ return (current_module_result)

{.path = NULL, .error = ENOSYS}

;
#endif
return (current_module_result)

{.path = ret_str, .error = ret_error}

;
}
}}

...but I don't know the repercussions for the CSFLE subsystem. I don't think it's strictly needed anyways?

Comment by Calvin Buckley [ 31/Oct/23 ]

That patch isn't sufficient; `dladdr` is also called in [`mongo-util.c`](https://github.com/mongodb/libmongocrypt/blob/master/src/mongocrypt-util.c#L85), called by [`_try_replace_dollar_origin`](https://github.com/mongodb/libmongocrypt/blob/master/src/mongocrypt.c#L433C13-L433C39).

Comment by Githook User [ 30/Oct/23 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}

Message: MONGOCRYPT-481 Warn if `mcr_dll_path` not implemented (#705)

  • add `mcr_dll_path_supported`
Comment by Cloud GitHub Webhooks [ 30/Oct/23 ]

kevinAlbs merged a pull request (MONGOCRYPT-481 Warn if `mcr_dll_path` not implemented) into the following branch:
master: 34a6e9d585e4b8fd1c4f18ffa57a08a6f3338546

Comment by Jack Woehr [ 13/Jan/23 ]

This is blocking newer versions of libmongoc.

The Reporter (Calvin Buckley) is the chief maintainer of PHP Community Edition (currently at 8.2) for the IBM i platform.

WIBNI this could bump up a notch in priority thanks.

Generated at Thu Feb 08 09:08:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.