]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
alloc_tag: fix empty codetag module section handling
authorSuren Baghdasaryan <surenb@google.com>
Fri, 1 Nov 2024 00:00:17 +0000 (17:00 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 1 Nov 2024 04:29:19 +0000 (21:29 -0700)
When a module does not have any allocations, it's allocation tag section
is empty and codetag_alloc_module_section() returns NULL.  However this
condition should never happen because codetag_needs_module_section() will
detect an empty section and avoid calling codetag_alloc_module_section().
Change codetag_alloc_module_section() to never return NULL, which should
prevent static checker warnings.  Add a WARN_ON() and a proper error
reporting in case codetag_alloc_module_section() returns NULL, to prevent
future codetag type implementations from returning NULL from their
cttype->desc.alloc_section_mem() operation.

Link: https://lkml.kernel.org/r/20241101000017.3856204-1-surenb@google.com
Fixes: 61c9e58f3a10 ("alloc_tag: load module tags into separate contiguous memory")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/50f12fa1-17c1-4940-a6bf-beaf61f6b17a@stanley.mountain/
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Daniel Gomez <da.gomez@samsung.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: David Rientjes <rientjes@google.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Minchan Kim <minchan@google.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Petr Pavlu <petr.pavlu@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Sourav Panda <souravpanda@google.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Xiongwei Song <xiongwei.song@windriver.com>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/module/main.c
lib/alloc_tag.c
lib/codetag.c

index 129c98e6380dff57b8dafe3eac3905091e0c6863..00c16f5c55683139c654119f2fe99d0d291af393 100644 (file)
@@ -2316,6 +2316,10 @@ static int move_module(struct module *mod, struct load_info *info)
                if (codetag_needs_module_section(mod, sname, shdr->sh_size)) {
                        dest = codetag_alloc_module_section(mod, sname, shdr->sh_size,
                                        arch_mod_section_prepend(mod, i), shdr->sh_addralign);
+                       if (WARN_ON(!dest)) {
+                               ret = -EINVAL;
+                               goto out_err;
+                       }
                        if (IS_ERR(dest)) {
                                ret = PTR_ERR(dest);
                                goto out_err;
index d9f51169ffeb2ed4c93ef9229ac25f1dd0d47a1d..36f0c04e22c44b50f3065c9cd9fe54f37f5cf975 100644 (file)
@@ -262,7 +262,7 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,
 
        /* If no tags return NULL */
        if (size < sizeof(struct alloc_tag))
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        /*
         * align is always power of 2, so we can use IS_ALIGNED and ALIGN.
index 654496952f8682fd41aa3c58b6c455199aa8130d..7455b966cae4355bb918a322e7afe9520d9f0cac 100644 (file)
@@ -244,7 +244,7 @@ void *codetag_alloc_module_section(struct module *mod, const char *name,
 {
        const char *type_name = name + strlen(CODETAG_SECTION_PREFIX);
        struct codetag_type *cttype;
-       void *ret = NULL;
+       void *ret = ERR_PTR(-EINVAL);
 
        mutex_lock(&codetag_lock);
        list_for_each_entry(cttype, &codetag_types, link) {