lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed,  1 Sep 2021 16:37:56 -0700
From:   Kees Cook <keescook@...omium.org>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     Kees Cook <keescook@...omium.org>, Arnd Bergmann <arnd@...db.de>,
        Jessica Yu <jeyu@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        linux-arch@...r.kernel.org, Heiko Carstens <hca@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ibm.com>,
        Alexander Egorenkov <egorenar@...ux.ibm.com>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Ilya Leoshkevich <iii@...ux.ibm.com>,
        "Steven Rostedt (VMware)" <rostedt@...dmis.org>,
        Ingo Molnar <mingo@...nel.org>,
        Sami Tolvanen <samitolvanen@...gle.com>,
        linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org,
        linux-hardening@...r.kernel.org
Subject: [PATCH 3/4] module: Use a list of strings for ro_after_init sections

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@...db.de>
Cc: Jessica Yu <jeyu@...nel.org>
Cc: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Peter Zijlstra (Intel) <peterz@...radead.org>
Cc: linux-arch@...r.kernel.org
Signed-off-by: Kees Cook <keescook@...omium.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

Powered by blists - more mailing lists