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 4029B3D4134; Wed, 8 Apr 2026 18:09:18 +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=1775671758; cv=none; b=IRL5qcdHDwQVkP8Cu1YK1meSTuUKqpUMDk+Sn/Bvg7Xc72EWJBjV/ZNUvcfo3+Vmyf5DUUFYSpjqZ5kKtMlNZOlDt1ftSOLpOmTgXMeHVrbfgP7lEge1hBpO3C6zpVanzqLX40+hTyx+LiuGPq/fVedIgGDHMjD14puS3cljhZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775671758; c=relaxed/simple; bh=P8WURBACfR6ZCCapAbixuSY0qp6BAWFHzr+MEwhmPbY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EuXlr/AFiiLJC7He9ML04l6kdm9/9BLNMQa/9QMcWnUN/bJSe358me6KNVYCyR3nVxEsl4eO+msCtRKbSGpDt+aM6W/HIvOfcN/jCfWx97gK2M2eBKbnFICrpR5rl3tytm91VnOfvIUl9tSA6mkE6Wv5IaFWy8r/4v3Q7OYB5pw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NaYyPm+d; 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="NaYyPm+d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAED0C19421; Wed, 8 Apr 2026 18:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775671758; bh=P8WURBACfR6ZCCapAbixuSY0qp6BAWFHzr+MEwhmPbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NaYyPm+ddb/byKSwD7Kg0BuwVh8mRP62dkDgjpcQdtUgMdO+miDZ7kf6xsQ14oRHr hE++yaHxs2hRUnsYTqFeTS/XwscFJqPFQ9ovY4ZVTKLU11ysFkbV3sTiWVEezWHq0m Cg5TIz0Vp89lLA0ik3uqxhIhEV3xE9e7H+geaqJc= 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.1 014/312] module: Fix kernel panic when a symbol st_shndx is out of bounds Date: Wed, 8 Apr 2026 19:58:51 +0200 Message-ID: <20260408175934.263543540@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.715315542@linuxfoundation.org> References: <20260408175933.715315542@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.1-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 3269f6c468145..6b3cffd9f8a8a 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1343,6 +1343,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