Skip to content

Commit 052a45c

Browse files
surenbaghdasaryanakpm00
authored andcommitted
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/[email protected] Fixes: 916cc51 ("lib: code tagging framework") Signed-off-by: Suren Baghdasaryan <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Sourav Panda <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: <[email protected]> [6.10+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 409faf8 commit 052a45c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/codetag.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ static inline size_t range_size(const struct codetag_type *cttype,
125125
cttype->desc.tag_size;
126126
}
127127

128-
#ifdef CONFIG_MODULES
129128
static void *get_symbol(struct module *mod, const char *prefix, const char *name)
130129
{
131130
DECLARE_SEQ_BUF(sb, KSYM_NAME_LEN);
@@ -155,6 +154,15 @@ static struct codetag_range get_section_range(struct module *mod,
155154
};
156155
}
157156

157+
static const char *get_mod_name(__maybe_unused struct module *mod)
158+
{
159+
#ifdef CONFIG_MODULES
160+
if (mod)
161+
return mod->name;
162+
#endif
163+
return "(built-in)";
164+
}
165+
158166
static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
159167
{
160168
struct codetag_range range;
@@ -164,8 +172,7 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
164172
range = get_section_range(mod, cttype->desc.section);
165173
if (!range.start || !range.stop) {
166174
pr_warn("Failed to load code tags of type %s from the module %s\n",
167-
cttype->desc.section,
168-
mod ? mod->name : "(built-in)");
175+
cttype->desc.section, get_mod_name(mod));
169176
return -EINVAL;
170177
}
171178

@@ -199,6 +206,7 @@ static int codetag_module_init(struct codetag_type *cttype, struct module *mod)
199206
return 0;
200207
}
201208

209+
#ifdef CONFIG_MODULES
202210
void codetag_load_module(struct module *mod)
203211
{
204212
struct codetag_type *cttype;
@@ -248,9 +256,6 @@ bool codetag_unload_module(struct module *mod)
248256

249257
return unload_ok;
250258
}
251-
252-
#else /* CONFIG_MODULES */
253-
static int codetag_module_init(struct codetag_type *cttype, struct module *mod) { return 0; }
254259
#endif /* CONFIG_MODULES */
255260

256261
struct codetag_type *

0 commit comments

Comments
 (0)