2 * livepatch.c - x86-specific Kernel Live Patching Core
4 * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
5 * Copyright (C) 2014 SUSE
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <linux/module.h>
22 #include <linux/uaccess.h>
24 #include <asm/livepatch.h>
27 * klp_write_module_reloc() - write a relocation in a module
28 * @mod: module in which the section to be modified is found
29 * @type: ELF relocation type (see asm/elf.h)
30 * @loc: address that the relocation should be written to
31 * @value: relocation value (sym address + addend)
33 * This function writes a relocation to the specified location for
34 * a particular module.
36 int klp_write_module_reloc(struct module *mod, unsigned long type,
37 unsigned long loc, unsigned long value)
41 unsigned long core = (unsigned long)mod->core_layout.base;
42 unsigned long core_size = mod->core_layout.size;
58 val = (u32)(value - loc);
61 /* unsupported relocation type */
65 if (loc < core || loc >= core + core_size)
66 /* loc does not point to any symbol inside the module */
69 return probe_kernel_write((void *)loc, &val, size);