From nobody Sun Feb 8 22:42:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8015F1CDFCD; Tue, 3 Sep 2024 04:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725336030; cv=none; b=ZidGj+jBMIAdxtVLaFgM7xSN8EiVYTaaRD+CXZOAqNl6YdGAtJs89ylrkjFd5V7MYnucs/TtKxQcXT8+jOuM3m4vUi9UDOJFL6gAOpA0UZlrktGZ4Bj9FnzEWK/Jdq7e0YjDWL0iLcksxh0OWrJkw0uVFKIXbKYTqUp8WFp3vQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725336030; c=relaxed/simple; bh=OdbgV1d6SagFMFieLlZ7F3BDtff8ypL3ANe3ldIaiP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=baHn0axhe2l1LQup4VIG/JjMeFAS5zzGezsaYE1UmeAnszXcuRfSrcG9rHUeTABcTdRO6vgEimQWwW4TwdC0Bzh04mdXamft45rIBpgfidxLNZmLEgh+85PlhJiDMuQiiQwvEYfb1uBY1mgRO7boz8uAc5WfsRl2hLKgmURA0kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iLjARiSH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iLjARiSH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A014EC4CECC; Tue, 3 Sep 2024 04:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725336030; bh=OdbgV1d6SagFMFieLlZ7F3BDtff8ypL3ANe3ldIaiP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iLjARiSHag+1IRFGydMoZumBS5I064mp+8QcARiPbQp6p79PuL0YJox2Mcqlf4YxU ne8H9PlSTx7FlVW2A5e2+UWJMw92YBK7er+t2bC0jypAwI4kvRVU/EajhVKUe1s/Uc 1jnKaUZkNUEvBTqiKEgQrdymcx432i5RXNfEeZ5c6tuS+TtKyJCdg74V1q7dCELF2f gOEqgP0rcR7U0i3Pd8PWKqcsd5d0X+6bfN+BlSfaikZZIX5KquLAvL3gzfRytC/MCl O9dzo9Sx9yeQ7ZuOFhx7S5UIHsS53gt39DHNrjREEq5WdwIWBIINobKOfYHIxRrkVQ 44TfmqWLWpsgw== From: Josh Poimboeuf To: live-patching@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Miroslav Benes , Petr Mladek , Joe Lawrence , Jiri Kosina , Peter Zijlstra , Marcos Paulo de Souza , Song Liu Subject: [RFC 02/31] x86/module: Improve relocation error messages Date: Mon, 2 Sep 2024 20:59:45 -0700 Message-ID: <0e89228c265405d9125a3630c127b51d04f80232.1725334260.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" Add the section number and reloc index to relocation error messages to help find the faulty relocation. Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/module.c | 15 +++++++++------ kernel/livepatch/core.c | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 837450b6e882..c09651691dd6 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -96,6 +96,7 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, DEBUGP("%s relocate section %u to %u\n", apply ? "Applying" : "Clearing", relsec, sechdrs[relsec].sh_info); + for (i =3D 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { size_t size; =20 @@ -147,15 +148,17 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, =20 if (apply) { if (memcmp(loc, &zero, size)) { - pr_err("x86/modules: Invalid relocation target, existing value is nonz= ero for type %d, loc %p, val %Lx\n", - (int)ELF64_R_TYPE(rel[i].r_info), loc, val); + pr_err("x86/modules: Invalid relocation target, existing value is nonz= ero for sec %u, idx %u, type %d, loc %lx, val %Lx\n", + relsec, i, (int)ELF64_R_TYPE(rel[i].r_info), + (unsigned long)loc, val); return -ENOEXEC; } write(loc, &val, size); } else { if (memcmp(loc, &val, size)) { - pr_warn("x86/modules: Invalid relocation target, existing value does n= ot match expected value for type %d, loc %p, val %Lx\n", - (int)ELF64_R_TYPE(rel[i].r_info), loc, val); + pr_warn("x86/modules: Invalid relocation target, existing value does n= ot match expected value for sec %u, idx %u, type %d, loc %lx, val %Lx\n", + relsec, i, (int)ELF64_R_TYPE(rel[i].r_info), + (unsigned long)loc, val); return -ENOEXEC; } write(loc, &zero, size); @@ -164,8 +167,8 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, return 0; =20 overflow: - pr_err("overflow in relocation type %d val %Lx\n", - (int)ELF64_R_TYPE(rel[i].r_info), val); + pr_err("overflow in relocation type %d val %Lx sec %u idx %d\n", + (int)ELF64_R_TYPE(rel[i].r_info), val, relsec, i); pr_err("`%s' likely not compiled with -mcmodel=3Dkernel\n", me->name); return -ENOEXEC; diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 52426665eecc..76ffe29934d4 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -219,8 +219,8 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const= char *strtab, for (i =3D 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) { sym =3D (Elf_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info); if (sym->st_shndx !=3D SHN_LIVEPATCH) { - pr_err("symbol %s is not marked as a livepatch symbol\n", - strtab + sym->st_name); + pr_err("symbol %s at rela sec %u idx %d is not marked as a livepatch sy= mbol\n", + strtab + sym->st_name, symndx, i); return -EINVAL; } =20 --=20 2.45.2