alloc_tag: fix allocation tag reporting when CONFIG_MODULES=n

codetag_module_init() is used to initialize sections containing allocation
tags.  This function is used to initialize module sections as well as core
kernel sections, in which case the module parameter is set to NULL.  This
function has to be called even when CONFIG_MODULES=n to initialize core
kernel allocation tag sections.  When CONFIG_MODULES=n, this function is a
NOP, which is wrong.  This leads to /proc/allocinfo reported as empty. 
Fix this by making it independent of CONFIG_MODULES.

Link: https://lkml.kernel.org/r/20240828231536.1770519-1-surenb@google.com
Fixes: 916cc5167c ("lib: code tagging framework")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Sourav Panda <souravpanda@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: <stable@vger.kernel.org>	[6.10+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Suren Baghdasaryan 2024-08-28 16:15:36 -07:00 committed by Andrew Morton
parent 409faf8c97
commit 052a45c1cb

View File

@ -125,7 +125,6 @@ static inline size_t range_size(const struct codetag_type *cttype,
cttype->desc.tag_size; cttype->desc.tag_size;
} }
#ifdef CONFIG_MODULES
static void *get_symbol(struct module *mod, const char *prefix, const char *name) static void *get_symbol(struct module *mod, const char *prefix, const char *name)
{ {
DECLARE_SEQ_BUF(sb, KSYM_NAME_LEN); DECLARE_SEQ_BUF(sb, KSYM_NAME_LEN);
@ -155,6 +154,15 @@ static struct codetag_range get_section_range(struct module *mod,
}; };
} }
static const char *get_mod_name(__maybe_unused struct module *mod)
{
#ifdef CONFIG_MODULES
if (mod)
return mod->name;
#endif
return "(built-in)";
}
static int codetag_module_init(struct codetag_type *cttype, struct module *mod) static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
{ {
struct codetag_range range; struct codetag_range range;
@ -164,8 +172,7 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
range = get_section_range(mod, cttype->desc.section); range = get_section_range(mod, cttype->desc.section);
if (!range.start || !range.stop) { if (!range.start || !range.stop) {
pr_warn("Failed to load code tags of type %s from the module %s\n", pr_warn("Failed to load code tags of type %s from the module %s\n",
cttype->desc.section, cttype->desc.section, get_mod_name(mod));
mod ? mod->name : "(built-in)");
return -EINVAL; return -EINVAL;
} }
@ -199,6 +206,7 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
return 0; return 0;
} }
#ifdef CONFIG_MODULES
void codetag_load_module(struct module *mod) void codetag_load_module(struct module *mod)
{ {
struct codetag_type *cttype; struct codetag_type *cttype;
@ -248,9 +256,6 @@ bool codetag_unload_module(struct module *mod)
return unload_ok; return unload_ok;
} }
#else /* CONFIG_MODULES */
static int codetag_module_init(struct codetag_type *cttype, struct module *mod) { return 0; }
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
struct codetag_type * struct codetag_type *