diff --git a/src/cryptsetup.c b/src/cryptsetup.c index ccacb3d4..ba7435f5 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -1077,6 +1077,17 @@ out: return r; } +static int update_persistent_flags(struct crypt_device *cd, const char *name, uint32_t activation_flags) +{ + struct crypt_active_device cad; + + /* write only flags not filtered by current kernel during activation */ + if (crypt_get_active_device(cd, name, &cad)) + return -EINVAL; + + return crypt_persistent_flags_set(cd, CRYPT_FLAGS_ACTIVATION, cad.flags & activation_flags); +} + static int action_open_luks(void) { struct crypt_device *cd = NULL; @@ -1139,10 +1150,9 @@ static int action_open_luks(void) } out: if (r >= 0 && opt_persistent && - crypt_persistent_flags_set(cd, CRYPT_FLAGS_ACTIVATION, activate_flags)) + update_persistent_flags(cd, activated_name, activate_flags)) log_err(_("Device activated but cannot make flags persistent.\n")); - crypt_safe_free(key); crypt_safe_free(password); crypt_free(cd);