diff --git a/src/cryptsetup.c b/src/cryptsetup.c index d5cca488..32dad91f 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -1567,6 +1567,7 @@ static int action_open_luks(void) int r, keysize, tries; char *password = NULL; size_t passwordLen; + struct stat st; if (ARG_SET(OPT_REFRESH_ID)) { activated_name = action_argc > 1 ? action_argv[1] : action_argv[0]; @@ -1593,6 +1594,14 @@ static int action_open_luks(void) r = -EINVAL; goto out; } + + if (activated_name && !stat(crypt_get_device_name(cd), &st) && S_ISREG(st.st_mode) && + crypt_get_data_offset(cd) >= ((uint64_t)st.st_size / SECTOR_SIZE)) { + log_err(_("LUKS file container %s is too small for activation, there is no remaining space for data."), + crypt_get_device_name(cd)); + r = -EINVAL; + goto out; + } } set_activation_flags(&activate_flags);