From nobody Sun Feb 8 17:37:47 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 43F9D1DD525; Tue, 30 Dec 2025 18:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767119571; cv=none; b=IoggKmdOk/wcwGdsLZBECIjyWHEA8/iVyBE+3csCYY8CwrHt36/n1M2s1epcPtCFNZ2/Zg8HDDjrv4kMJcsJVupOei86auCv+ifykpkTbgydDnipqn/64rAH2m6rNqZuUzjJQRnrlRXBgaAJYpOlhtw2k679r24nVAERDVhz1IU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767119571; c=relaxed/simple; bh=7tOkvUuh/6GiISbyLheGU4///m4131Mud4EO3Yo/+h8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EAtVoq39RF9gxGpfp/QCMA8RRX0rbgdmf+FiR/v8LJ1Ha9KHVrpi/I4K/2txKumPE2g/u5HoSxFLnWdWOXJNYb7sm56CX+clP9D52JHzQ0Y7t4ZD75DWAa7XdAIa6A6Qw1JYcKAE047pgLEUttR/u6WsTkH8WSxeOZLKWRHbVw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ljkaMa7g; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ljkaMa7g" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767119557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DCQNXUyI4+4dxZcbehNgpALRC5lYnrYiYesNBz6jLuo=; b=ljkaMa7g+vz0DJtiPRobYhg5W1nIKDxVIbF6J/hF5dmMLV3OmjVt9m5W1Dm9ZXkL/4H8lI 0SDYaYqx+RHkkflqjEdd3wDL7hoLnSiptCQvIkZWHG+pRyEcOtr0LhKnxE0Zu4Xq1dKt2c 3GOoS7NI44N7E8aVFuSaOB+Zvy9fghs= From: Ihor Solodrai To: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Nathan Chancellor , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, bpf@vger.kernel.org, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] module: Fix kernel panic when a symbol st_shndx is out of bounds Date: Tue, 30 Dec 2025 10:32:08 -0800 Message-ID: <20251230183208.1317279-1-ihor.solodrai@linux.dev> 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-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The module loader doesn't check for bounds of the ELF section index in simplify_symbols(): for (i =3D 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { const char *name =3D 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 =3D=3D info->index.pcpu) secbase =3D (unsigned long)mod_percpu(mod); else /** HERE --> **/ secbase =3D info->sechdrs[sym[i].st_shndx].sh_addr; sym[i].st_value +=3D 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.solo= drai@linux.dev/ Signed-off-by: Ihor Solodrai Reviewed-by: Petr Pavlu --- kernel/module/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/module/main.c b/kernel/module/main.c index 710ee30b3bea..5bf456fad63e 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1568,6 +1568,13 @@ static int simplify_symbols(struct module *mod, cons= t struct load_info *info) break; =20 default: + if (sym[i].st_shndx >=3D 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 =3D -ENOEXEC; + break; + } + /* Divert to percpu allocation if a percpu var. */ if (sym[i].st_shndx =3D=3D info->index.pcpu) secbase =3D (unsigned long)mod_percpu(mod); --=20 2.52.0