hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/kernel/kexec_file.c
....@@ -343,7 +343,7 @@
343343
344344 image = NULL;
345345
346
- if (!mutex_trylock(&kexec_mutex))
346
+ if (!kexec_trylock())
347347 return -EBUSY;
348348
349349 dest_image = &kexec_image;
....@@ -415,7 +415,7 @@
415415 if ((flags & KEXEC_FILE_ON_CRASH) && kexec_crash_image)
416416 arch_kexec_protect_crashkres();
417417
418
- mutex_unlock(&kexec_mutex);
418
+ kexec_unlock();
419419 kimage_free(image);
420420 return ret;
421421 }
....@@ -910,10 +910,22 @@
910910 }
911911
912912 offset = ALIGN(offset, align);
913
+
914
+ /*
915
+ * Check if the segment contains the entry point, if so,
916
+ * calculate the value of image->start based on it.
917
+ * If the compiler has produced more than one .text section
918
+ * (Eg: .text.hot), they are generally after the main .text
919
+ * section, and they shall not be used to calculate
920
+ * image->start. So do not re-calculate image->start if it
921
+ * is not set to the initial value, and warn the user so they
922
+ * have a chance to fix their purgatory's linker script.
923
+ */
913924 if (sechdrs[i].sh_flags & SHF_EXECINSTR &&
914925 pi->ehdr->e_entry >= sechdrs[i].sh_addr &&
915926 pi->ehdr->e_entry < (sechdrs[i].sh_addr
916
- + sechdrs[i].sh_size)) {
927
+ + sechdrs[i].sh_size) &&
928
+ !WARN_ON(kbuf->image->start != pi->ehdr->e_entry)) {
917929 kbuf->image->start -= sechdrs[i].sh_addr;
918930 kbuf->image->start += kbuf->mem + offset;
919931 }