aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/livepatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/kernel/livepatch.c')
-rw-r--r--arch/x86/kernel/livepatch.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c
index d1d35ccffed3..92fc1a51f994 100644
--- a/arch/x86/kernel/livepatch.c
+++ b/arch/x86/kernel/livepatch.c
@@ -20,8 +20,6 @@
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/uaccess.h> 22#include <linux/uaccess.h>
23#include <asm/cacheflush.h>
24#include <asm/page_types.h>
25#include <asm/elf.h> 23#include <asm/elf.h>
26#include <asm/livepatch.h> 24#include <asm/livepatch.h>
27 25
@@ -38,11 +36,10 @@
38int klp_write_module_reloc(struct module *mod, unsigned long type, 36int klp_write_module_reloc(struct module *mod, unsigned long type,
39 unsigned long loc, unsigned long value) 37 unsigned long loc, unsigned long value)
40{ 38{
41 int ret, numpages, size = 4; 39 size_t size = 4;
42 bool readonly;
43 unsigned long val; 40 unsigned long val;
44 unsigned long core = (unsigned long)mod->module_core; 41 unsigned long core = (unsigned long)mod->core_layout.base;
45 unsigned long core_size = mod->core_size; 42 unsigned long core_size = mod->core_layout.size;
46 43
47 switch (type) { 44 switch (type) {
48 case R_X86_64_NONE: 45 case R_X86_64_NONE:
@@ -69,23 +66,5 @@ int klp_write_module_reloc(struct module *mod, unsigned long type,
69 /* loc does not point to any symbol inside the module */ 66 /* loc does not point to any symbol inside the module */
70 return -EINVAL; 67 return -EINVAL;
71 68
72 readonly = false; 69 return probe_kernel_write((void *)loc, &val, size);
73
74#ifdef CONFIG_DEBUG_SET_MODULE_RONX
75 if (loc < core + mod->core_ro_size)
76 readonly = true;
77#endif
78
79 /* determine if the relocation spans a page boundary */
80 numpages = ((loc & PAGE_MASK) == ((loc + size) & PAGE_MASK)) ? 1 : 2;
81
82 if (readonly)
83 set_memory_rw(loc & PAGE_MASK, numpages);
84
85 ret = probe_kernel_write((void *)loc, &val, size);
86
87 if (readonly)
88 set_memory_ro(loc & PAGE_MASK, numpages);
89
90 return ret;
91} 70}