From: Song Liu <songliubraving@meta.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: "linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Christoph Hellwig <hch@lst.de>,
Kernel Team <kernel-team@meta.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Guenter Roeck <linux@roeck-us.net>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Song Liu <song@kernel.org>
Subject: Re: [PATCH v10] module: replace module_layout with module_memory
Date: Tue, 7 Feb 2023 22:19:30 +0000 [thread overview]
Message-ID: <8972F26D-34FE-4463-83AD-BBCC6F92C952@fb.com> (raw)
In-Reply-To: <20230207002802.2514802-1-song@kernel.org>
Hi Luis
> On Feb 6, 2023, at 4:28 PM, Song Liu <song@kernel.org> wrote:
>
> +static void free_mod_mem(struct module *mod)
> +{
> + /* free the memory in the right order to avoid use-after-free */
> + static enum mod_mem_type mod_mem_free_order[MOD_MEM_NUM_TYPES] = {
> + /* first free init sections */
> + MOD_INIT_TEXT,
> + MOD_INIT_DATA,
> + MOD_INIT_RODATA,
> +
> + /* then core sections, except rw data */
> + MOD_TEXT,
> + MOD_RODATA,
> + MOD_RO_AFTER_INIT,
> +
> + /* last, rw data */
> + MOD_DATA,
> + };
> + int i;
> +
> + BUILD_BUG_ON(ARRAY_SIZE(mod_mem_free_order) != MOD_MEM_NUM_TYPES);
> +
> + for (i = 0; i < MOD_MEM_NUM_TYPES; i++) {
> + enum mod_mem_type type = mod_mem_free_order[i];
> + struct module_memory *mod_mem = &mod->mem[type];
> +
> + /* Free lock-classes; relies on the preceding sync_rcu(). */
> + lockdep_free_key_range(mod_mem->base, mod_mem->size);
> + if (mod_mem->size)
> + module_memory_free(mod_mem->base, type);
> + }
> +}
If there are no other comments, would you mind make the following
change when applying the patch?
Thanks,
Song
diff --git i/kernel/module/main.c w/kernel/module/main.c
index b9617d7e8db2..c598f11e7016 100644
--- i/kernel/module/main.c
+++ w/kernel/module/main.c
@@ -1211,7 +1211,7 @@ static void free_mod_mem(struct module *mod)
MOD_RODATA,
MOD_RO_AFTER_INIT,
- /* last, rw data */
+ /* rw data need to be freed last, as it hosts mod */
MOD_DATA,
};
int i;
next prev parent reply other threads:[~2023-02-07 22:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 0:28 [PATCH v10] module: replace module_layout with module_memory Song Liu
2023-02-07 22:19 ` Song Liu [this message]
2023-02-08 8:37 ` Thomas Gleixner
2023-02-08 16:06 ` Luis Chamberlain
2023-02-08 17:48 ` Christophe Leroy
2023-02-08 21:39 ` Song Liu
2023-02-09 6:32 ` Christophe Leroy
2023-02-09 0:16 ` Song Liu
2023-02-09 6:37 ` Christophe Leroy
2023-02-09 17:28 ` Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8972F26D-34FE-4463-83AD-BBCC6F92C952@fb.com \
--to=songliubraving@meta.com \
--cc=christophe.leroy@csgroup.eu \
--cc=hch@lst.de \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mcgrof@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox