Re: [PATCH v5 12/37] lib: prevent module unloading if memory is not freed

From: Luis Chamberlain
Date: Tue Mar 12 2024 - 14:22:58 EST


On Wed, Mar 06, 2024 at 10:24:10AM -0800, Suren Baghdasaryan wrote:
> Skip freeing module's data section if there are non-zero allocation tags
> because otherwise, once these allocations are freed, the access to their
> code tag would cause UAF.

So you just let them linger?

> Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>


> /* Free a module, remove from lists, etc. */
> static void free_module(struct module *mod)
> {
> + bool unload_codetags;
> +
> trace_module_free(mod);
>
> - codetag_unload_module(mod);
> + unload_codetags = codetag_unload_module(mod);
> + if (!unload_codetags)
> + pr_warn("%s: memory allocation(s) from the module still alive, cannot unload cleanly\n",
> + mod->name);
> +

Because this is not unwinding anything. Should'd we check if we can
free all tags first, if we can't then we can't free the module. If we
can then ensure we don't enter a state where we can't later?

Luis