From mboxrd@z Thu Jan 1 00:00:00 1970 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 EFA2D33120E; Tue, 31 Mar 2026 16:47:11 +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=1774975632; cv=none; b=KV0a1keZQU3fRXwqWrn0V/1DnfC2ctQplsz3GD9wfjzDMl5q4RlzGlrY3yjy73rKYpVVRhPTGsHUcRRqnIQl4CMtz/sCTy1yImyHVCSPVKNm5j+MrA9WgiQkACS/qzoG19Mv9NbVqX8zu3SAK3NvdOs7tfHT629Eruxjlc5+aIk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774975632; c=relaxed/simple; bh=ET6rNQfOtwF5cFDSkUn/yXjXL7xu3zWrWOW7pJxYZyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HUu1AcKb+1uT6R+TWfaeuCOWxr28/hMO9vWzJqYvHdnUd0SK2/htGts4m5ZdHE7klt9nLbgpxdoX5ZWqcyq+aGIIi3ez3JJS/RCyvnysHEcKBkNu9WF8U1fQMKq0aF5dwmIe2LoPyZ6mHtQX7YlBW67tguhXxdELBfKaazL46IM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Iwp2Kvfh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Iwp2Kvfh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84D0AC19423; Tue, 31 Mar 2026 16:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774975631; bh=ET6rNQfOtwF5cFDSkUn/yXjXL7xu3zWrWOW7pJxYZyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iwp2Kvfh1fATGGkCuRvAKb87DrML04Dq/KNkCqMgTy0dmTg+EVvx0GRvkUjuXceK0 QlPNwTuYG7a4ChB73Kfx/oInTkdJFHoXUnhil4LEd1waR1UojjjVsA+KTGIgP6lmVA VfwWj1aTNIaWsH+CwZt5fNEThTv2GiXAxpPN0LAI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ihor Solodrai , Daniel Gomez , Petr Pavlu , Sami Tolvanen , Sasha Levin Subject: [PATCH 6.12 026/244] module: Fix kernel panic when a symbol st_shndx is out of bounds Date: Tue, 31 Mar 2026 18:19:36 +0200 Message-ID: <20260331161742.669236182@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331161741.651718120@linuxfoundation.org> References: <20260331161741.651718120@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ihor Solodrai [ Upstream commit f9d69d5e7bde2295eb7488a56f094ac8f5383b92 ] The module loader doesn't check for bounds of the ELF section index in simplify_symbols(): for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { const char *name = info->strtab + sym[i].st_name; switch (sym[i].st_shndx) { case SHN_COMMON: [...] default: /* Divert to percpu allocation if a percpu var. */ if (sym[i].st_shndx == info->index.pcpu) secbase = (unsigned long)mod_percpu(mod); else /** HERE --> **/ secbase = info->sechdrs[sym[i].st_shndx].sh_addr; sym[i].st_value += secbase; break; } } A symbol with an out-of-bounds st_shndx value, for example 0xffff (known as SHN_XINDEX or SHN_HIRESERVE), may cause a kernel panic: BUG: unable to handle page fault for address: ... RIP: 0010:simplify_symbols+0x2b2/0x480 ... Kernel panic - not syncing: Fatal exception This can happen when module ELF is legitimately using SHN_XINDEX or when it is corrupted. Add a bounds check in simplify_symbols() to validate that st_shndx is within the valid range before using it. This issue was discovered due to a bug in llvm-objcopy, see relevant discussion for details [1]. [1] https://lore.kernel.org/linux-modules/20251224005752.201911-1-ihor.solodrai@linux.dev/ Signed-off-by: Ihor Solodrai Reviewed-by: Daniel Gomez Reviewed-by: Petr Pavlu Signed-off-by: Sami Tolvanen Signed-off-by: Sasha Levin --- kernel/module/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/module/main.c b/kernel/module/main.c index 4511d0a4762a2..915a9cf33dd0d 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1449,6 +1449,13 @@ static int simplify_symbols(struct module *mod, const struct load_info *info) break; default: + if (sym[i].st_shndx >= info->hdr->e_shnum) { + pr_err("%s: Symbol %s has an invalid section index %u (max %u)\n", + mod->name, name, sym[i].st_shndx, info->hdr->e_shnum - 1); + ret = -ENOEXEC; + break; + } + /* Divert to percpu allocation if a percpu var. */ if (sym[i].st_shndx == info->index.pcpu) secbase = (unsigned long)mod_percpu(mod); -- 2.51.0