]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
module: Factor out elf_validity_cache_strtab
authorMatthew Maurer <mmaurer@google.com>
Tue, 15 Oct 2024 23:16:44 +0000 (23:16 +0000)
committerLuis Chamberlain <mcgrof@kernel.org>
Sat, 19 Oct 2024 21:35:07 +0000 (14:35 -0700)
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>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
kernel/module/main.c

index e04a228c694a2289597a5408e7cee8f14e7d334e..c082d5d41a8d1c6b160d569fccf948a84c748653 100644 (file)
@@ -2089,6 +2089,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.
@@ -2122,9 +2139,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;