libmount (verity): plug libcryptsetup logger into our logging system
Allows logs from the library to be printed by our system: 731814: libmount: VERITY: crypsetup: Device libmnt_img.raw already exists. If the mount context is in verbose mode, enable all debug logs from libcrypsetup as well. Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
This commit is contained in:
parent
edb088ffbe
commit
e0b6f5a7c8
|
@ -37,6 +37,13 @@ static void *get_symbol(struct libmnt_context *cxt, void *dl, const char *name,
|
|||
}
|
||||
#endif
|
||||
|
||||
static void libcryptsetup_log(int level __attribute__((__unused__)), const char *msg, void *data)
|
||||
{
|
||||
struct libmnt_context *cxt = (struct libmnt_context *)data;
|
||||
|
||||
DBG(VERITY, ul_debugobj(cxt, "cryptsetup: %s", msg));
|
||||
}
|
||||
|
||||
/* Taken from https://gitlab.com/cryptsetup/cryptsetup/blob/master/lib/utils_crypt.c#L225 */
|
||||
static size_t crypt_hex_to_bytes(const char *hex, char **result)
|
||||
{
|
||||
|
@ -81,6 +88,8 @@ int mnt_context_setup_veritydev(struct libmnt_context *cxt)
|
|||
#ifdef CRYPTSETUP_VIA_DLOPEN
|
||||
/* To avoid linking libmount to libcryptsetup, and keep the default dependencies list down, use dlopen */
|
||||
void *dl = NULL;
|
||||
void (*sym_crypt_set_debug_level)(int) = NULL;
|
||||
void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = NULL;
|
||||
int (*sym_crypt_init_data_device)(struct crypt_device **, const char *, const char *) = NULL;
|
||||
int (*sym_crypt_load)(struct crypt_device *, const char *, void *) = NULL;
|
||||
int (*sym_crypt_get_volume_key_size)(struct crypt_device *) = NULL;
|
||||
|
@ -93,6 +102,8 @@ int mnt_context_setup_veritydev(struct libmnt_context *cxt)
|
|||
int (*sym_crypt_get_verity_info)(struct crypt_device *, struct crypt_params_verity *) = NULL;
|
||||
int (*sym_crypt_volume_key_get)(struct crypt_device *, int, char *, size_t *, const char *, size_t) = NULL;
|
||||
#else
|
||||
void (*sym_crypt_set_debug_level)(int) = &crypt_set_debug_level;
|
||||
void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = &crypt_set_log_callback;
|
||||
int (*sym_crypt_init_data_device)(struct crypt_device **, const char *, const char *) = &crypt_init_data_device;
|
||||
int (*sym_crypt_load)(struct crypt_device *, const char *, void *) = &crypt_load;
|
||||
int (*sym_crypt_get_volume_key_size)(struct crypt_device *) = &crypt_get_volume_key_size;
|
||||
|
@ -254,6 +265,10 @@ int mnt_context_setup_veritydev(struct libmnt_context *cxt)
|
|||
/* clear errors first, then load all the libcryptsetup symbols */
|
||||
dlerror();
|
||||
|
||||
if (rc == 0)
|
||||
*(void **)(&sym_crypt_set_debug_level) = get_symbol(cxt, dl, "crypt_set_debug_level", &rc);
|
||||
if (rc == 0)
|
||||
*(void **)(&sym_crypt_set_log_callback) = get_symbol(cxt, dl, "crypt_set_log_callback", &rc);
|
||||
if (rc == 0)
|
||||
*(void **)(&sym_crypt_init_data_device) = get_symbol(cxt, dl, "crypt_init_data_device", &rc);
|
||||
if (rc == 0)
|
||||
|
@ -278,6 +293,10 @@ int mnt_context_setup_veritydev(struct libmnt_context *cxt)
|
|||
if (rc)
|
||||
goto done;
|
||||
|
||||
if (mnt_context_is_verbose(cxt))
|
||||
(*sym_crypt_set_debug_level)(CRYPT_DEBUG_ALL);
|
||||
(*sym_crypt_set_log_callback)(NULL, libcryptsetup_log, cxt);
|
||||
|
||||
rc = (*sym_crypt_init_data_device)(&crypt_dev, hash_device, backing_file);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
@ -410,10 +429,14 @@ int mnt_context_deferred_delete_veritydev(struct libmnt_context *cxt)
|
|||
#ifdef RTLD_DEEPBIND
|
||||
dl_flags |= RTLD_DEEPBIND;
|
||||
#endif
|
||||
void (*sym_crypt_set_debug_level)(int) = NULL;
|
||||
void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = NULL;
|
||||
int (*sym_crypt_init_by_name)(struct crypt_device **, const char *) = NULL;
|
||||
int (*sym_crypt_deactivate_by_name)(struct crypt_device *, const char *, uint32_t) = NULL;
|
||||
void (*sym_crypt_free)(struct crypt_device *) = NULL;
|
||||
#else
|
||||
void (*sym_crypt_set_debug_level)(int) = &crypt_set_debug_level;
|
||||
void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = &crypt_set_log_callback;
|
||||
int (*sym_crypt_init_by_name)(struct crypt_device **, const char *) = &crypt_init_by_name;
|
||||
int (*sym_crypt_deactivate_by_name)(struct crypt_device *, const char *, uint32_t) = &crypt_deactivate_by_name;
|
||||
void (*sym_crypt_free)(struct crypt_device *) = &crypt_free;
|
||||
|
@ -440,6 +463,10 @@ int mnt_context_deferred_delete_veritydev(struct libmnt_context *cxt)
|
|||
/* clear errors first */
|
||||
dlerror();
|
||||
|
||||
if (!rc)
|
||||
*(void **)(&sym_crypt_set_debug_level) = get_symbol(cxt, dl, "crypt_set_debug_level", &rc);
|
||||
if (!rc)
|
||||
*(void **)(&sym_crypt_set_log_callback) = get_symbol(cxt, dl, "crypt_set_log_callback", &rc);
|
||||
if (!rc)
|
||||
*(void **)(&sym_crypt_init_by_name) = get_symbol(cxt, dl, "crypt_init_by_name", &rc);
|
||||
if (!rc)
|
||||
|
@ -448,6 +475,9 @@ int mnt_context_deferred_delete_veritydev(struct libmnt_context *cxt)
|
|||
*(void **)(&sym_crypt_free) = get_symbol(cxt, dl, "crypt_free", &rc);
|
||||
#endif
|
||||
if (!rc) {
|
||||
if (mnt_context_is_verbose(cxt))
|
||||
(*sym_crypt_set_debug_level)(CRYPT_DEBUG_ALL);
|
||||
(*sym_crypt_set_log_callback)(NULL, libcryptsetup_log, cxt);
|
||||
rc = (*sym_crypt_init_by_name)(&crypt_dev, src);
|
||||
if (!rc) {
|
||||
rc = (*sym_crypt_deactivate_by_name)(crypt_dev, src, flags);
|
||||
|
|
Loading…
Reference in New Issue