From: Suren Baghdasaryan Date: Fri, 1 Nov 2024 00:00:17 +0000 (-0700) Subject: alloc_tag: fix empty codetag module section handling X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d53a736ac11dbc88ebad6ab2c51715abac32c4ed;p=users%2Fjedix%2Flinux-maple.git alloc_tag: fix empty codetag module section handling 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 Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/50f12fa1-17c1-4940-a6bf-beaf61f6b17a@stanley.mountain/ Cc: Ard Biesheuvel Cc: Arnd Bergmann Cc: Borislav Petkov (AMD) Cc: Christoph Hellwig Cc: Daniel Gomez Cc: David Hildenbrand Cc: Davidlohr Bueso Cc: David Rientjes Cc: Dennis Zhou Cc: Johannes Weiner Cc: John Hubbard Cc: Jonathan Corbet Cc: Joonsoo Kim Cc: Kalesh Singh Cc: Kees Cook Cc: Kent Overstreet Cc: Liam R. Howlett Cc: Luis Chamberlain Cc: Matthew Wilcox Cc: Michal Hocko Cc: Mike Rapoport (Microsoft) Cc: Minchan Kim Cc: Pasha Tatashin Cc: Paul E. McKenney Cc: Petr Pavlu Cc: Roman Gushchin Cc: Sami Tolvanen Cc: Sourav Panda Cc: Steven Rostedt (Google) Cc: Thomas Gleixner Cc: Thomas Huth Cc: Uladzislau Rezki (Sony) Cc: Vlastimil Babka Cc: Xiongwei Song Cc: Yu Zhao Signed-off-by: Andrew Morton --- diff --git a/kernel/module/main.c b/kernel/module/main.c index 129c98e6380d..00c16f5c5568 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -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; diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index d9f51169ffeb..36f0c04e22c4 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -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. diff --git a/lib/codetag.c b/lib/codetag.c index 654496952f86..7455b966cae4 100644 --- a/lib/codetag.c +++ b/lib/codetag.c @@ -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) {