Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1583847 > unrolled thread
| Started by | Eddie Kovsky <ewk@edkovsky.org> |
|---|---|
| First post | 2017-02-18 07:10 +0100 |
| Last post | 2017-02-26 18:50 +0100 |
| Articles | 8 — 5 participants |
Back to article view | Back to linux.kernel
[PATCH v2 0/3] provide check for ro_after_init memory sections Eddie Kovsky <ewk@edkovsky.org> - 2017-02-18 07:10 +0100
[PATCH v2 2/3] extable: verify address is read-only Eddie Kovsky <ewk@edkovsky.org> - 2017-02-18 07:10 +0100
Re: [PATCH v2 2/3] extable: verify address is read-only kbuild test robot <lkp@intel.com> - 2017-02-18 07:40 +0100
[PATCH v2 1/3] module: verify address is read-only Eddie Kovsky <ewk@edkovsky.org> - 2017-02-18 07:10 +0100
Re: [PATCH v2 1/3] module: verify address is read-only Stephen Hemminger <stephen@networkplumber.org> - 2017-02-20 18:20 +0100
Re: [PATCH v2 1/3] module: verify address is read-only Kees Cook <keescook@chromium.org> - 2017-02-21 21:40 +0100
Re: [PATCH v2 1/3] module: verify address is read-only Stephen Hemminger <stephen@networkplumber.org> - 2017-02-21 22:00 +0100
Re: [PATCH v2 1/3] module: verify address is read-only Jessica Yu <jeyu@redhat.com> - 2017-02-26 18:50 +0100
| From | Eddie Kovsky <ewk@edkovsky.org> |
|---|---|
| Date | 2017-02-18 07:10 +0100 |
| Subject | [PATCH v2 0/3] provide check for ro_after_init memory sections |
| Message-ID | <tc6nv-6t9-3@gated-at.bofh.it> |
Provide a mechansim for other functions to verify that their arguments
are read-only. Use this mechansim in the vmbus register functions to
reject arguments that fail this test.
This implements a suggestion made by Kees Cook for the Kernel Self
Protection Project:
* provide mechanism to check for ro_after_init memory areas, and
reject structures not marked ro_after_init in vmbus_register()
http://www.openwall.com/lists/kernel-hardening/2017/02/04/1
I have successfully compiled this series on next-20170215 for x86.
Eddie Kovsky (3):
module: verify address is read-only
extable: verify address is read-only
Make vmbus register arguments read-only
drivers/hv/vmbus_drv.c | 10 ++++++++++
include/linux/kernel.h | 2 ++
include/linux/module.h | 7 +++++++
kernel/extable.c | 29 +++++++++++++++++++++++++++++
kernel/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 92 insertions(+)
--
2.11.1
[toc] | [next] | [standalone]
| From | Eddie Kovsky <ewk@edkovsky.org> |
|---|---|
| Date | 2017-02-18 07:10 +0100 |
| Subject | [PATCH v2 2/3] extable: verify address is read-only |
| Message-ID | <tc6nw-6t9-9@gated-at.bofh.it> |
| In reply to | #1583847 |
Provide a mechanism to check if the address of a variable is
const or ro_after_init. It mimics the existing functions that test if an
address is inside the kernel's text section.
Signed-off-by: Eddie Kovsky <ewk@edkovsky.org>
---
include/linux/kernel.h | 2 ++
kernel/extable.c | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c26dc3a8295..51beea39e6c4 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -444,6 +444,8 @@ extern int core_kernel_data(unsigned long addr);
extern int __kernel_text_address(unsigned long addr);
extern int kernel_text_address(unsigned long addr);
extern int func_ptr_is_kernel_text(void *ptr);
+extern int core_kernel_ro_data(unsigned long addr);
+extern int kernel_ro_address(unsigned long addr);
unsigned long int_sqrt(unsigned long);
diff --git a/kernel/extable.c b/kernel/extable.c
index 6b0d09051efb..e9608f129730 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -149,3 +149,32 @@ int func_ptr_is_kernel_text(void *ptr)
return 1;
return is_module_text_address(addr);
}
+
+/**
+ * core_kernel_ro_data - Verify address points to read-only section
+ * @addr: address to test
+ *
+ */
+int core_kernel_ro_data(unsigned long addr)
+{
+ if (addr >= (unsigned long)__start_rodata &&
+ addr < (unsigned long)__end_rodata)
+ return 1;
+
+ if (addr >= (unsigned long)__start_data_ro_after_init &&
+ addr < (unsigned long)__end_data_ro_after_init)
+ return 1;
+
+ return 0;
+}
+
+/* Verify that address is const or ro_after_init. */
+int kernel_ro_address(unsigned long addr)
+{
+ if (core_kernel_ro_data(addr))
+ return 1;
+ if (is_module_ro_address(addr))
+ return 1;
+
+ return 0;
+}
--
2.11.1
[toc] | [prev] | [next] | [standalone]
| From | kbuild test robot <lkp@intel.com> |
|---|---|
| Date | 2017-02-18 07:40 +0100 |
| Subject | Re: [PATCH v2 2/3] extable: verify address is read-only |
| Message-ID | <tc6Qy-6G5-7@gated-at.bofh.it> |
| In reply to | #1583848 |
[Multipart message — attachments visible in raw view] — view raw
Hi Eddie,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.10-rc8 next-20170217]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Eddie-Kovsky/provide-check-for-ro_after_init-memory-sections/20170218-141040
config: i386-tinyconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All errors (new ones prefixed by >>):
kernel/extable.c: In function 'kernel_ro_address':
>> kernel/extable.c:168:6: error: implicit declaration of function 'is_module_ro_address' [-Werror=implicit-function-declaration]
if (is_module_ro_address(addr))
^~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/is_module_ro_address +168 kernel/extable.c
162
163 /* Verify that address is const or ro_after_init. */
164 int kernel_ro_address(unsigned long addr)
165 {
166 if (core_kernel_ro_data(addr))
167 return 1;
> 168 if (is_module_ro_address(addr))
169 return 1;
170
171 return 0;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[toc] | [prev] | [next] | [standalone]
| From | Eddie Kovsky <ewk@edkovsky.org> |
|---|---|
| Date | 2017-02-18 07:10 +0100 |
| Subject | [PATCH v2 1/3] module: verify address is read-only |
| Message-ID | <tc6nv-6t9-5@gated-at.bofh.it> |
| In reply to | #1583847 |
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
[toc] | [prev] | [next] | [standalone]
| From | Stephen Hemminger <stephen@networkplumber.org> |
|---|---|
| Date | 2017-02-20 18:20 +0100 |
| Subject | Re: [PATCH v2 1/3] module: verify address is read-only |
| Message-ID | <tcZN0-7x5-21@gated-at.bofh.it> |
| In reply to | #1583849 |
On Fri, 17 Feb 2017 21:58:42 -0800 "Eddie Kovsky" <ewk@edkovsky.org> wrote: > 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> I don't see the point of this for many of the hyper-v functions. They are only called from a small number of places, and this can be validated by code inspection. Adding this seems just seems to be code bloat to me.
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-02-21 21:40 +0100 |
| Subject | Re: [PATCH v2 1/3] module: verify address is read-only |
| Message-ID | <tdpo7-7FL-27@gated-at.bofh.it> |
| In reply to | #1584776 |
On Mon, Feb 20, 2017 at 9:14 AM, Stephen Hemminger <stephen@networkplumber.org> wrote: > On Fri, 17 Feb 2017 21:58:42 -0800 > "Eddie Kovsky" <ewk@edkovsky.org> wrote: > >> 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> > > I don't see the point of this for many of the hyper-v functions. > They are only called from a small number of places, and this can be validated > by code inspection. Adding this seems just seems to be code bloat to me. I think it has value in that it effectively blocks any way for non-ro_after_init structures from being passed into these functions. Since there are so few callers now, it's the perfect place to add this. -Kees -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | Stephen Hemminger <stephen@networkplumber.org> |
|---|---|
| Date | 2017-02-21 22:00 +0100 |
| Subject | Re: [PATCH v2 1/3] module: verify address is read-only |
| Message-ID | <tdpHr-7P4-7@gated-at.bofh.it> |
| In reply to | #1585722 |
On Tue, 21 Feb 2017 12:32:16 -0800 Kees Cook <keescook@chromium.org> wrote: > On Mon, Feb 20, 2017 at 9:14 AM, Stephen Hemminger > <stephen@networkplumber.org> wrote: > > On Fri, 17 Feb 2017 21:58:42 -0800 > > "Eddie Kovsky" <ewk@edkovsky.org> wrote: > > > >> 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> > > > > I don't see the point of this for many of the hyper-v functions. > > They are only called from a small number of places, and this can be validated > > by code inspection. Adding this seems just seems to be code bloat to me. > > I think it has value in that it effectively blocks any way for > non-ro_after_init structures from being passed into these functions. > Since there are so few callers now, it's the perfect place to add > this. > > -Kees > Maybe for a more used API, but for such a corner case it is code bloat.
[toc] | [prev] | [next] | [standalone]
| From | Jessica Yu <jeyu@redhat.com> |
|---|---|
| Date | 2017-02-26 18:50 +0100 |
| Subject | Re: [PATCH v2 1/3] module: verify address is read-only |
| Message-ID | <tfb7j-1wJ-1@gated-at.bofh.it> |
| In reply to | #1583849 |
+++ Eddie Kovsky [17/02/17 22:58 -0700]:
>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.
It would be helpful to explain in the changelog the motivation or
reason we're adding to the current api, and why this is needed.
>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;
>+}
>+
There needs to be a corresponding !CONFIG_MODULES stub for
is_module_ro_address() as well, see is_module_address(), etc.
> 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.
s/is_module_text_ro_address/is_module_ro_address/
Although I would slightly prefer the name is_module_rodata_address, or
something similar, because it's unclear to me (without looking at the
code) whether the function covers text addresses. And we already have
is_module_text_address() for that case.
>+ *
>+ */
>+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.
Maybe we should be more specific in the comment and clarify that we're
getting the module whose rodata/ro_after_init sections contain the
given 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 a ro_after_init address gets passed in here, mod will be prematurely
set to NULL here, because it is not within [base, base + ro_size).
See comment above frob_text() in module.c for a module layout "diagram".
Also, starting from layout.base will give us the text region as well,
but we just want to check the rodata/ro_after_init regions, same as
what the kernel counterpart in patch 2/3 does. The rodata region
starts at base + text_size.
So we can just simplify this to just one conditional:
(ugly, but shouldn't look bad when cleaned up with some variables)
if (!within(addr, mod->init_layout.base + mod->init_layout.text_size,
mod->init_layout.ro_after_init_size - mod->init_layout.text_size)
&& !within(addr, mod->core_layout.base + mod->core_layout.text_size,
mod->core_layout.ro_after_init_size - mod->core_layout.text_size))
This is because range [base + text_size, base + ro_after_init_size)
encompasses both the rodata and ro_after_init regions.
Jessica
>+ 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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web