From: Kees Cook <keescook@chromium.org> To: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Kees Cook <keescook@chromium.org>, Arnd Bergmann <arnd@arndb.de>, Jessica Yu <jeyu@kernel.org>, Peter Zijlstra <peterz@infradead.org>, linux-arch@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>, Vasily Gorbik <gor@linux.ibm.com>, Christian Borntraeger <borntraeger@de.ibm.com>, Alexander Egorenkov <egorenar@linux.ibm.com>, Sven Schnelle <svens@linux.ibm.com>, Ilya Leoshkevich <iii@linux.ibm.com>, "Steven Rostedt (VMware)" <rostedt@goodmis.org>, Ingo Molnar <mingo@kernel.org>, Sami Tolvanen <samitolvanen@google.com>, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 3/4] module: Use a list of strings for ro_after_init sections Date: Wed, 1 Sep 2021 16:37:56 -0700 [thread overview] Message-ID: <20210901233757.2571878-4-keescook@chromium.org> (raw) In-Reply-To: <20210901233757.2571878-1-keescook@chromium.org> Instead of open-coding the section names, use a list for the sections that need to be marked read-only after init. Unfortunately, it seems we can't do normal section merging with scripts/module.lds.S as ld.bfd doesn't correctly update symbol tables. For more details, see commit 6a3193cdd5e5 ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG is enabled"). Cc: Arnd Bergmann <arnd@arndb.de> Cc: Jessica Yu <jeyu@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: linux-arch@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> --- include/asm-generic/vmlinux.lds.h | 4 +++- kernel/module.c | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 4781a8154254..d532baadaeae 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -418,7 +418,9 @@ /* * Allow architectures to handle ro_after_init data on their - * own by defining an empty RO_AFTER_INIT_DATA. + * own by defining an empty RO_AFTER_INIT_DATA. Any sections + * added here must be explicitly marked SHF_RO_AFTER_INIT + * via module_sections_ro_after_init[] in kernel/module.c. */ #ifndef RO_AFTER_INIT_DATA #define RO_AFTER_INIT_DATA \ diff --git a/kernel/module.c b/kernel/module.c index ed13917ea5f3..b0ff82cc48fe 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3514,10 +3514,21 @@ static bool blacklisted(const char *module_name) } core_param(module_blacklist, module_blacklist, charp, 0400); +/* + * List of sections to be marked read-only after init. This should match + * the RO_AFTER_INIT_DATA macro in include/asm-generic/vmlinux.lds.h. + */ +static const char * const module_sections_ro_after_init[] = { + ".data..ro_after_init", + "__jump_table", + NULL +}; + static struct module *layout_and_allocate(struct load_info *info, int flags) { struct module *mod; unsigned int ndx; + const char * const *section; int err; err = check_modinfo(info->mod, info, flags); @@ -3543,18 +3554,11 @@ static struct module *layout_and_allocate(struct load_info *info, int flags) * layout_sections() can put it in the right place. * Note: ro_after_init sections also have SHF_{WRITE,ALLOC} set. */ - ndx = find_sec(info, ".data..ro_after_init"); - if (ndx) - info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; - /* - * Mark the __jump_table section as ro_after_init as well: these data - * structures are never modified, with the exception of entries that - * refer to code in the __init section, which are annotated as such - * at module load time. - */ - ndx = find_sec(info, "__jump_table"); - if (ndx) - info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; + for (section = module_sections_ro_after_init; *section; section++) { + ndx = find_sec(info, *section); + if (ndx) + info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT; + } /* * Determine total sizes, and put offsets in sh_entsize. For now -- 2.30.2
next prev parent reply other threads:[~2021-09-01 23:38 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-01 23:37 [PATCH 0/4] Fix ro_after_init vs static_call Kees Cook 2021-09-01 23:37 ` [PATCH 1/4] vmlinux.lds.h: Use regular *RODATA and *RO_AFTER_INIT_DATA suffixes Kees Cook 2021-09-03 5:55 ` Josh Poimboeuf 2021-09-03 8:17 ` Heiko Carstens 2021-09-01 23:37 ` [PATCH 2/4] vmlinux.lds.h: Split .static_call_sites from .static_call_tramp_key Kees Cook 2021-09-03 5:55 ` Josh Poimboeuf 2021-09-01 23:37 ` Kees Cook [this message] 2021-09-03 6:49 ` [PATCH 3/4] module: Use a list of strings for ro_after_init sections Josh Poimboeuf 2021-09-03 16:38 ` Kees Cook 2021-09-04 4:09 ` Josh Poimboeuf 2021-09-04 14:40 ` Kees Cook 2021-09-01 23:37 ` [PATCH 4/4] module: Include .static_call_sites in module ro_after_init Kees Cook
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=20210901233757.2571878-4-keescook@chromium.org \ --to=keescook@chromium.org \ --cc=arnd@arndb.de \ --cc=borntraeger@de.ibm.com \ --cc=egorenar@linux.ibm.com \ --cc=gor@linux.ibm.com \ --cc=hca@linux.ibm.com \ --cc=iii@linux.ibm.com \ --cc=jeyu@kernel.org \ --cc=jpoimboe@redhat.com \ --cc=linux-arch@vger.kernel.org \ --cc=linux-hardening@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-s390@vger.kernel.org \ --cc=mingo@kernel.org \ --cc=peterz@infradead.org \ --cc=rostedt@goodmis.org \ --cc=samitolvanen@google.com \ --cc=svens@linux.ibm.com \ --subject='Re: [PATCH 3/4] module: Use a list of strings for ro_after_init sections' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).