public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robertus Diawan Chris <robertusdchris@gmail.com>
To: jpoimboe@kernel.org, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	skhan@linuxfoundation.org, me@brighamcampbell.com
Subject: [PATCH RFT] objtool: Validate find symtab in elf_create_rela_section()
Date: Tue, 28 Apr 2026 11:30:26 +0700	[thread overview]
Message-ID: <20260428043026.160465-1-robertusdchris@gmail.com> (raw)

find_section_by_name() will return NULL if the section is not found. If
the symtab section is not found, using the return value of
find_section_by_name() directly will cause null pointer dereference. So
check the return value from find_section_by_name() when finding symtab
section before using the information.

This is reported by Coverity Scan with CID 1445573 as NULL_RETURNS.

Fixes: 627fce14809b ("objtool: Add ORC unwind table generation")
Signed-off-by: Robertus Diawan Chris <robertusdchris@gmail.com>
---
Currently still not sure _when_ symtab section is not found. This is
reported by static analysis tool, which can be wrong. I apologize if
this turns out to be false positive.

 tools/objtool/elf.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index f3df2bde119f..ce7246d3b302 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1625,7 +1625,7 @@ static int elf_alloc_reloc(struct elf *elf, struct section *rsec)
 struct section *elf_create_rela_section(struct elf *elf, struct section *sec,
 					unsigned int nr_relocs)
 {
-	struct section *rsec;
+	struct section *rsec, *symtab;
 	char *rsec_name;
 
 	rsec_name = malloc(strlen(sec->name) + strlen(".rela") + 1);
@@ -1654,7 +1654,13 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *sec,
 		}
 	}
 
-	rsec->sh.sh_link = find_section_by_name(elf, ".symtab")->idx;
+	symtab = find_section_by_name(elf, ".symtab");
+	if (!symtab) {
+		ERROR("can't find .symtab");
+		return NULL;
+	}
+
+	rsec->sh.sh_link = symtab->idx;
 	rsec->sh.sh_info = sec->idx;
 
 	sec->rsec = rsec;

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
-- 
2.54.0


                 reply	other threads:[~2026-04-28  4:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260428043026.160465-1-robertusdchris@gmail.com \
    --to=robertusdchris@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@brighamcampbell.com \
    --cc=peterz@infradead.org \
    --cc=skhan@linuxfoundation.org \
    /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