From: Eddie Kovsky <ewk@edkovsky.org>
To: jeyu@redhat.com, rusty@rustcorp.com.au, keescook@chromium.org,
kys@microsoft.com, haiyangz@microsoft.com,
sthemmin@microsoft.com
Cc: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com
Subject: [PATCH v2 1/3] module: verify address is read-only
Date: Fri, 17 Feb 2017 22:58:42 -0700 [thread overview]
Message-ID: <20170218055844.1457-2-ewk@edkovsky.org> (raw)
In-Reply-To: <20170218055844.1457-1-ewk@edkovsky.org>
Implement a mechanism to check if a module's address is in
the rodata or ro_after_init sections. It mimics the exsiting functions
that test if an address is inside a module's text section.
Signed-off-by: Eddie Kovsky <ewk@edkovsky.org>
---
include/linux/module.h | 7 +++++++
kernel/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/linux/module.h b/include/linux/module.h
index 0297c5cd7cdf..1608d3570ee2 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -492,7 +492,9 @@ static inline int module_is_live(struct module *mod)
struct module *__module_text_address(unsigned long addr);
struct module *__module_address(unsigned long addr);
+struct module *__module_ro_address(unsigned long addr);
bool is_module_address(unsigned long addr);
+bool is_module_ro_address(unsigned long addr);
bool is_module_percpu_address(unsigned long addr);
bool is_module_text_address(unsigned long addr);
@@ -645,6 +647,11 @@ static inline struct module *__module_address(unsigned long addr)
return NULL;
}
+static inline struct module *__module_ro_address(unsigned long addr)
+{
+ return NULL;
+}
+
static inline struct module *__module_text_address(unsigned long addr)
{
return NULL;
diff --git a/kernel/module.c b/kernel/module.c
index 7eba6dea4f41..298cfe4645b1 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -4275,6 +4275,50 @@ struct module *__module_text_address(unsigned long addr)
}
EXPORT_SYMBOL_GPL(__module_text_address);
+/**
+ * is_module_text_ro_address - is this address inside read-only module code?
+ * @addr: the address to check.
+ *
+ */
+bool is_module_ro_address(unsigned long addr)
+{
+ bool ret;
+
+ preempt_disable();
+ ret = __module_ro_address(addr) != NULL;
+ preempt_enable();
+
+ return ret;
+}
+
+/*
+ * __module_ro_address - get the module whose code contains a read-only address.
+ * @addr: the address.
+ *
+ * Must be called with preempt disabled or module mutex held so that
+ * module doesn't get freed during this.
+ */
+struct module *__module_ro_address(unsigned long addr)
+{
+ struct module *mod = __module_address(addr);
+
+ if (mod) {
+ /* Make sure it's within the read-only section. */
+ if (!within(addr, mod->init_layout.base,
+ mod->init_layout.ro_size)
+ && !within(addr, mod->core_layout.base,
+ mod->core_layout.ro_size))
+ mod = NULL;
+ if (!within(addr, mod->init_layout.base,
+ mod->init_layout.ro_after_init_size)
+ && !within(addr, mod->core_layout.base,
+ mod->core_layout.ro_after_init_size))
+ mod = NULL;
+ }
+ return mod;
+}
+EXPORT_SYMBOL_GPL(__module_ro_address);
+
/* Don't grab lock, we're oopsing. */
void print_modules(void)
{
--
2.11.1
next prev parent reply other threads:[~2017-02-18 6:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 5:58 [PATCH v2 0/3] provide check for ro_after_init memory sections Eddie Kovsky
2017-02-18 5:58 ` Eddie Kovsky [this message]
2017-02-20 17:14 ` [PATCH v2 1/3] module: verify address is read-only Stephen Hemminger
2017-02-21 20:32 ` Kees Cook
2017-02-21 20:51 ` Stephen Hemminger
2017-02-26 17:42 ` Jessica Yu
2017-02-18 5:58 ` [PATCH v2 2/3] extable: " Eddie Kovsky
2017-02-18 6:33 ` kbuild test robot
2017-02-18 6:49 ` kbuild test robot
2017-02-18 5:58 ` [PATCH v2 3/3] Make vmbus register arguments read-only Eddie Kovsky
2017-02-18 6:30 ` kbuild test robot
2017-02-18 8:55 ` kbuild test robot
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=20170218055844.1457-2-ewk@edkovsky.org \
--to=ewk@edkovsky.org \
--cc=haiyangz@microsoft.com \
--cc=jeyu@redhat.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=sthemmin@microsoft.com \
/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
all inboxes | Powered by JetHome®