mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Maurer <mmaurer@google.com>
To: mcgrof@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org,
	 samitolvanen@google.com, Matthew Maurer <mmaurer@google.com>,
	 Petr Pavlu <petr.pavlu@suse.com>,
	Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH 10/12] module: Factor out elf_validity_cache_strtab
Date: Tue, 15 Oct 2024 23:16:44 +0000	[thread overview]
Message-ID: <20241015231651.3851138-11-mmaurer@google.com> (raw)
In-Reply-To: <20241015231651.3851138-1-mmaurer@google.com>

This patch only moves the existing strtab population to a function.
Validation comes in a following patch, this is split out to make the new
validation checks more clearly separated.

Signed-off-by: Matthew Maurer <mmaurer@google.com>
---
 kernel/module/main.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index f352c73b6f40..22aa5eb4e4f4 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2122,6 +2122,23 @@ static int elf_validity_cache_index(struct load_info *info, int flags)
 	return 0;
 }
 
+/**
+ * elf_validity_cache_strtab() - Cache symbol string table
+ * @info: Load info to read from and update.
+ *        Must have &load_info->sechdrs and &load_info->secstrings populated.
+ *        Must have &load_info->index populated.
+ *
+ * Return: 0 on success, negative error code if a check failed.
+ */
+static int elf_validity_cache_strtab(struct load_info *info)
+{
+	Elf_Shdr *str_shdr = &info->sechdrs[info->index.str];
+	char *strtab = (char *)info->hdr + str_shdr->sh_offset;
+
+	info->strtab = strtab;
+	return 0;
+}
+
 /*
  * Check userspace passed ELF module against our expectations, and cache
  * useful variables for further processing as we go.
@@ -2155,9 +2172,9 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
 	err = elf_validity_cache_index(info, flags);
 	if (err < 0)
 		return err;
-
-	/* Sets internal strings. */
-	info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;
+	err = elf_validity_cache_strtab(info);
+	if (err < 0)
+		return err;
 
 	/* This is temporary: point mod into copy of data. */
 	info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset;
-- 
2.47.0.rc1.288.g06298d1525-goog


  parent reply	other threads:[~2024-10-15 23:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 23:16 [PATCH 00/12] Module Validation Refactor Matthew Maurer
2024-10-15 23:16 ` [PATCH 01/12] module: Take const arg in validate_section_offset Matthew Maurer
2024-10-15 23:16 ` [PATCH 02/12] module: Factor out elf_validity_ehdr Matthew Maurer
2024-10-15 23:16 ` [PATCH 03/12] module: Factor out elf_validity_cache_sechdrs Matthew Maurer
2024-10-15 23:16 ` [PATCH 04/12] module: Factor out elf_validity_cache_secstrings Matthew Maurer
2024-10-15 23:16 ` [PATCH 05/12] module: Factor out elf_validity_cache_index_info Matthew Maurer
2024-10-15 23:16 ` [PATCH 06/12] module: Factor out elf_validity_cache_index_mod Matthew Maurer
2024-10-15 23:16 ` [PATCH 07/12] module: Factor out elf_validity_cache_index_sym Matthew Maurer
2024-10-15 23:16 ` [PATCH 08/12] module: Factor out elf_validity_cache_index_str Matthew Maurer
2024-10-15 23:16 ` [PATCH 09/12] module: Group section index calculations together Matthew Maurer
2024-10-15 23:16 ` Matthew Maurer [this message]
2024-10-15 23:16 ` [PATCH 11/12] module: Additional validation in elf_validity_cache_strtab Matthew Maurer
2024-10-15 23:16 ` [PATCH 12/12] module: Reformat struct for code style Matthew Maurer
2024-10-17  0:44 ` [PATCH 00/12] Module Validation Refactor Sami Tolvanen
2024-10-19 22:10 ` Luis Chamberlain

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=20241015231651.3851138-11-mmaurer@google.com \
    --to=mmaurer@google.com \
    --cc=da.gomez@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=petr.pavlu@suse.com \
    --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

all inboxes | Powered by JetHome®