From: Petr Pavlu <petr.pavlu@suse.com>
To: Laxman Acharya Padhya <acharyalaxman8848@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Luis Chamberlain <mcgrof@kernel.org>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Aaron Tomlin <atomlin@atomlin.com>,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/bug: ignore non-allocated module bug tables
Date: Mon, 3 Aug 2026 18:16:11 +0200 [thread overview]
Message-ID: <9979198f-95f8-4fa7-8f24-ef74585e2798@suse.com> (raw)
In-Reply-To: <20260729174234.86242-1-acharyalaxman8848@gmail.com>
On 7/29/26 7:42 PM, Laxman Acharya Padhya wrote:
> rewrite_section_headers() initially sets sh_addr for every section to its
> address in the temporary module image. Only SHF_ALLOC sections are later
> copied to module memory and have sh_addr updated.
>
> module_bug_finalize() accepts any section named __bug_table. A malformed
> module can therefore leave mod->bug_table pointing into the temporary
> image, which is freed after loading. A later BUG/WARN lookup would then
> scan freed memory.
>
> Require the bug table section to be allocated before retaining its
> address. Valid modules are unchanged because __bug_table is allocated.
>
> Fixes: 7664c5a1da47 ("[PATCH] Generic BUG implementation")
> Signed-off-by: Laxman Acharya Padhya <acharyalaxman8848@gmail.com>
> ---
> lib/bug.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/bug.c b/lib/bug.c
> index 7c1c2c27f..44966ead1 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -94,7 +94,8 @@ void module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
> /* Find the __bug_table section, if present */
> secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
> for (i = 1; i < hdr->e_shnum; i++) {
> - if (strcmp(secstrings+sechdrs[i].sh_name, "__bug_table"))
> + if (strcmp(secstrings + sechdrs[i].sh_name, "__bug_table") ||
> + !(sechdrs[i].sh_flags & SHF_ALLOC))
> continue;
> mod->bug_table = (void *) sechdrs[i].sh_addr;
> mod->num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
This change looks ok to me but I think it is not strictly necessary.
Loading a module should normally at least get through the signature and
blacklist checks without crashing due to a corrupted module ELF file.
After that point, I believe the ELF data should be trusted, similar to
how the actual module code is expected to be correct.
module_bug_finalize() is called fairly late in the module-loading
process, after the signature and blacklist checks.
--
Thanks,
Petr
prev parent reply other threads:[~2026-08-03 16:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 17:42 [PATCH] lib/bug: ignore non-allocated module bug tables Laxman Acharya Padhya
2026-07-29 17:58 ` sashiko-bot
2026-08-03 16:16 ` Petr Pavlu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9979198f-95f8-4fa7-8f24-ef74585e2798@suse.com \
--to=petr.pavlu@suse.com \
--cc=acharyalaxman8848@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=atomlin@atomlin.com \
--cc=da.gomez@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=samitolvanen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox