diff --git a/src/hibernate-resume/hibernate-resume-config.c b/src/hibernate-resume/hibernate-resume-config.c index 4aac6234d0..6d0987eedd 100644 --- a/src/hibernate-resume/hibernate-resume-config.c +++ b/src/hibernate-resume/hibernate-resume-config.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "device-nodes.h" #include "fstab-util.h" @@ -110,33 +108,29 @@ static int get_kernel_hibernate_location(KernelHibernateLocation **ret) { #if ENABLE_EFI static bool validate_efi_hibernate_location(EFIHibernateLocation *e) { - _cleanup_free_ char *id = NULL, *image_id = NULL, *version_id = NULL, *image_version = NULL; - struct utsname uts = {}; + _cleanup_free_ char *id = NULL, *image_id = NULL; int r; assert(e); - if (uname(&uts) < 0) - log_warning_errno(errno, "Failed to get kernel info, ignoring: %m"); - r = parse_os_release(NULL, "ID", &id, - "IMAGE_ID", &image_id, - "VERSION_ID", &version_id, - "IMAGE_VERSION", &image_version); + "IMAGE_ID", &image_id); if (r < 0) - log_warning_errno(r, "Failed to parse os-release, ignoring: %m"); + log_warning_errno(r, "Failed to parse os-release: %m"); - if (!streq(uts.release, strempty(e->kernel_version)) || - !streq_ptr(id, e->id) || - !streq_ptr(image_id, e->image_id) || - !streq_ptr(version_id, e->version_id) || - !streq_ptr(image_version, e->image_version)) { - - log_notice("HibernateLocation system info doesn't match with current running system, not resuming from it."); + if (!streq_ptr(id, e->id) || + !streq_ptr(image_id, e->image_id)) { + log_notice("HibernateLocation system identifier doesn't match currently running system, not resuming from it."); return false; } + /* + * Note that we accept kernel version mismatches. Linux writes the old kernel to disk as part of the + * hibernation image, and thus resuming means the short-lived kernel that reads the image from the + * disk will be replaced by the original kernel and effectively removed from memory as part of that. + */ + return true; } @@ -183,6 +177,15 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) { if (r < 0) return r; + log_info("Reported hibernation image:%s%s%s%s%s%s%s%s%s%s UUID="SD_ID128_UUID_FORMAT_STR" offset=%"PRIu64, + e->id ? " ID=" : "", strempty(e->id), + e->image_id ? " IMAGE_ID=" : "", strempty(e->image_id), + e->version_id ? " VERSION_ID=" : "", strempty(e->version_id), + e->image_version ? " IMAGE_VERSION=" : "", strempty(e->image_version), + e->kernel_version ? " kernel=" : "", strempty(e->kernel_version), + SD_ID128_FORMAT_VAL(e->uuid), + e->offset); + if (!validate_efi_hibernate_location(e)) goto skip;