From b2de4ba059df0a3d09d6148ef0c2292211699945 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Mon, 26 Oct 2015 08:19:25 -0500 Subject: [PATCH] kmod/core: call unexported set_memory_[ro|rw] In recent kernels, set_memory_ro() and set_memory_rw() are no longer exported. Call them anyway :-) Fixes #496. --- kmod/core/core.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kmod/core/core.c b/kmod/core/core.c index 7803e55..7c16c79 100644 --- a/kmod/core/core.c +++ b/kmod/core/core.c @@ -129,6 +129,9 @@ enum { }; static atomic_t kpatch_state; +static int (*kpatch_set_memory_rw)(unsigned long addr, int numpages); +static int (*kpatch_set_memory_ro)(unsigned long addr, int numpages); + static inline void kpatch_state_idle(void) { int state = atomic_read(&kpatch_state); @@ -649,12 +652,12 @@ static int kpatch_write_relocations(struct kpatch_module *kpmod, numpages = (PAGE_SIZE - (loc & ~PAGE_MASK) >= size) ? 1 : 2; if (readonly) - set_memory_rw(loc & PAGE_MASK, numpages); + kpatch_set_memory_rw(loc & PAGE_MASK, numpages); ret = probe_kernel_write((void *)loc, &val, size); if (readonly) - set_memory_ro(loc & PAGE_MASK, numpages); + kpatch_set_memory_ro(loc & PAGE_MASK, numpages); if (ret) { pr_err("write to 0x%llx failed for symbol %s\n", @@ -1058,6 +1061,18 @@ static int kpatch_init(void) { int ret; + kpatch_set_memory_rw = (void *)kallsyms_lookup_name("set_memory_rw"); + if (!kpatch_set_memory_rw) { + pr_err("can't find set_memory_rw symbol\n"); + return -ENXIO; + } + + kpatch_set_memory_ro = (void *)kallsyms_lookup_name("set_memory_ro"); + if (!kpatch_set_memory_ro) { + pr_err("can't find set_memory_ro symbol\n"); + return -ENXIO; + } + kpatch_root_kobj = kobject_create_and_add("kpatch", kernel_kobj); if (!kpatch_root_kobj) return -ENOMEM;