From nobody Mon Feb 9 19:31:46 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5F0842316D for ; Tue, 20 Jan 2026 12:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768912875; cv=pass; b=sDLfYcxpk8Klsc0K7dthONj6dhU6Yv9ZeARmft0Ut66M/D669s8bO3NjT0DuhMSakPjWHmSAIzwSIoI3YJ49rXkEP3KISEk6krvc3VAFdeLV8ItYEuIBzDB/pQb9AZVIuaVxovt1kTrV57iOSkhe4S8NNekIB+/trKml5SjbeZ4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768912875; c=relaxed/simple; bh=IRD513n1auc6ExnwRb91lNxrD1Vm5MrwOtyt6VdW0mE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BcGyEFlgS3rIqOiXADIrlJ4qIwOxdaeyllUhdFF4seooWEHkHny3ZD2Tw98j0QWtz4AFU1QG8+6nOPO1GEuaof3AIRetp/FtKmzdIdrUDFiFKbgDtXONdYLuz0BEiZe5/RXqPNY3ZQPrpnkSY8eGepLuwEEiQ8EQQRZ0RIkFDn4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=Sx6gfn3J; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="Sx6gfn3J" ARC-Seal: i=1; a=rsa-sha256; t=1768912826; cv=none; d=zohomail.com; s=zohoarc; b=ZnjLHik5x00fADycem+PT+TfqtIcsDimnHqkXxTM6EK1gZoGN9lFg9mgARM9u5I405RmeiJ/ZOaSJMLixkkweLh2GYtVcpyJQtzOpQ7Vl68cwOwieCZw1gEyasPe5z9fXzeHFZrHOKQcAU5LUZYudveDmpBneyTvmYmjFW4QbDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768912826; h=Content-Transfer-Encoding:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=RsbdtOmIV/sS2UcajTt/rwz3vGSUI4SRa4q2OoUAI2Y=; b=AoIfl2nS3aPx0d7fK8abAUDy54RYgBdnveYcg6ddil924EfC0qgVmdaGv/9Z2RFuFv/+MTRt5el4h+4jEGNi1aZWK5cuLrbR/WQottVNQ1xoxnzAaJ7wuBrEJHIBPJYcPfZ1ApFn1RyF3XBsCsmjxZK6r0eAY7rcL5hiaIVYKQ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1768912826; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=RsbdtOmIV/sS2UcajTt/rwz3vGSUI4SRa4q2OoUAI2Y=; b=Sx6gfn3J3dVI5pJsTBe+0e4tUY2befYeCcqqQNp6BFLIJi7NpmRwnvKOW7xACyyQ Z8+EeDwPfCnBj/jDAPEv5TMsyz3Jw/jy8eYgPVGjZAVwDWV4ab/pPxImzunLd5AG3zX KKGgwxQGl0IwgqeVoVvfW6OXGsa3PXIVCYTdQ7XQ= Received: by mx.zohomail.com with SMTPS id 1768912824593109.50412840274407; Tue, 20 Jan 2026 04:40:24 -0800 (PST) From: Li Chen To: Andrew Morton , Baoquan He , Eric Biggers , Steven Chen , Alexander Graf , Sourabh Jain , Li Chen , Philipp Rudo , "Steven Rostedt (Google)" , Ricardo Ribalda , Ross Zwisler , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] kexec: derive purgatory entry from symbol Date: Tue, 20 Jan 2026 20:40:04 +0800 Message-ID: <20260120124005.148381-1-me@linux.beauty> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" kexec_load_purgatory() derives image->start by locating e_entry inside an SHF_EXECINSTR section. If the purgatory object contains multiple executable sections with overlapping sh_addr, the entrypoint check can match more than once and trigger a WARN. Derive the entry section from the purgatory_start symbol when present and compute image->start from its final placement. Keep the existing e_entry fallback for purgatories that do not expose the symbol. WARNING: kernel/kexec_file.c:1009 at kexec_load_purgatory+0x395/0x3c0, CPU#= 10: kexec/1784 Call Trace: bzImage64_load+0x133/0xa00 __do_sys_kexec_file_load+0x2b3/0x5c0 do_syscall_64+0x81/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e Fixes: 8652d44f466a ("kexec: support purgatories with .text.hot sections") Signed-off-by: Li Chen --- kernel/kexec_file.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 3f1d6c4e8ff2..d3c68c6b4bbc 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -880,6 +880,8 @@ static int kexec_calculate_store_digests(struct kimage = *image) } =20 #ifdef CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY +static const Elf_Sym * kexec_purgatory_find_symbol(struct purgatory_info *= pi, + const char *name); /* * kexec_purgatory_setup_kbuf - prepare buffer to load purgatory. * @pi: Purgatory to be loaded. @@ -958,6 +960,10 @@ static int kexec_purgatory_setup_sechdrs(struct purgat= ory_info *pi, unsigned long offset; size_t sechdrs_size; Elf_Shdr *sechdrs; + const Elf_Sym *entry_sym; + u16 entry_shndx =3D 0; + unsigned long entry_off =3D 0; + bool start_fixed =3D false; int i; =20 /* @@ -975,6 +981,12 @@ static int kexec_purgatory_setup_sechdrs(struct purgat= ory_info *pi, bss_addr =3D kbuf->mem + kbuf->bufsz; kbuf->image->start =3D pi->ehdr->e_entry; =20 + entry_sym =3D kexec_purgatory_find_symbol(pi, "purgatory_start"); + if (entry_sym) { + entry_shndx =3D entry_sym->st_shndx; + entry_off =3D entry_sym->st_value; + } + for (i =3D 0; i < pi->ehdr->e_shnum; i++) { unsigned long align; void *src, *dst; @@ -992,6 +1004,13 @@ static int kexec_purgatory_setup_sechdrs(struct purga= tory_info *pi, =20 offset =3D ALIGN(offset, align); =20 + if (!start_fixed && entry_sym && i =3D=3D entry_shndx && + (sechdrs[i].sh_flags & SHF_EXECINSTR) && + entry_off < sechdrs[i].sh_size) { + kbuf->image->start =3D kbuf->mem + offset + entry_off; + start_fixed =3D true; + } + /* * Check if the segment contains the entry point, if so, * calculate the value of image->start based on it. @@ -1002,13 +1021,14 @@ static int kexec_purgatory_setup_sechdrs(struct pur= gatory_info *pi, * is not set to the initial value, and warn the user so they * have a chance to fix their purgatory's linker script. */ - if (sechdrs[i].sh_flags & SHF_EXECINSTR && + if (!start_fixed && sechdrs[i].sh_flags & SHF_EXECINSTR && pi->ehdr->e_entry >=3D sechdrs[i].sh_addr && pi->ehdr->e_entry < (sechdrs[i].sh_addr + sechdrs[i].sh_size) && - !WARN_ON(kbuf->image->start !=3D pi->ehdr->e_entry)) { + kbuf->image->start =3D=3D pi->ehdr->e_entry) { kbuf->image->start -=3D sechdrs[i].sh_addr; kbuf->image->start +=3D kbuf->mem + offset; + start_fixed =3D true; } =20 src =3D (void *)pi->ehdr + sechdrs[i].sh_offset; --=20 2.52.0