Skip to content

Commit

Permalink
Merge pull request #191 from jpoimboe/revert-dynamic
Browse files Browse the repository at this point in the history
Revert #186 (add dynamic symbol linking support)
  • Loading branch information
jpoimboe committed May 15, 2014
2 parents d349d70 + 5e25365 commit bf4be47
Show file tree
Hide file tree
Showing 12 changed files with 799 additions and 653 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*.swp
.tmp_versions
Module.symvers
kpatch-build/lookup
kpatch-build/add-patches-section
kpatch-build/create-diff-object
kpatch-build/link-vmlinux-syms
man/kpatch.1.gz
man/kpatch-build.1.gz
test/integration/test.log
34 changes: 0 additions & 34 deletions kmod/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <linux/ftrace.h>
#include <linux/hashtable.h>
#include <linux/hardirq.h>
#include <linux/uaccess.h>
#include <asm/stacktrace.h>
#include <asm/cacheflush.h>
#include "kpatch.h"
Expand Down Expand Up @@ -425,10 +424,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
int ret, i;
struct kpatch_func *funcs, *func;
int num_funcs = kpmod->patches_nr;
struct kpatch_dynrela *dynrela;
void *loc;
u64 val;
int size;

if (!kpmod->mod || !kpmod->patches || !num_funcs)
return -EINVAL;
Expand All @@ -453,34 +448,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
goto err_up;
}

for (i = 0; i < kpmod->dynrelas_nr; i++) {
dynrela = &kpmod->dynrelas[i];
switch (dynrela->type) {
case R_X86_64_PC32:
loc = (void *)dynrela->dest;
val = (u32)(dynrela->src - dynrela->dest);
size = 4;
break;
case R_X86_64_32S:
loc = (void *)dynrela->dest;
val = (s32)dynrela->src;
size = 4;
break;
default:
printk("unsupported rela type %ld for "
"0x%lx <- 0x%lx at index %d\n",
dynrela->type, dynrela->dest,
dynrela->src, i);
ret = -EINVAL;
goto err_put;
}
set_memory_rw((unsigned long)loc & PAGE_MASK, 1);
ret = probe_kernel_write(loc, &val, size);
set_memory_ro((unsigned long)loc & PAGE_MASK, 1);
if (ret)
goto err_put;
}

for (i = 0; i < num_funcs; i++) {
func = &funcs[i];

Expand Down Expand Up @@ -597,7 +564,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
kpatch_num_registered--;
err_rollback:
kpatch_remove_funcs_from_filter(funcs, num_funcs);
err_put:
module_put(kpmod->mod);
err_up:
up(&kpatch_mutex);
Expand Down
8 changes: 0 additions & 8 deletions kmod/core/kpatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ struct kpatch_patch {
unsigned long old_size;
};

struct kpatch_dynrela {
unsigned long dest;
unsigned long src;
unsigned long type;
};

#ifdef __KERNEL__

#include <linux/types.h>
Expand All @@ -46,9 +40,7 @@ struct kpatch_internal;
struct kpatch_module {
struct module *mod;
struct kpatch_patch *patches;
struct kpatch_dynrela *dynrelas;
int patches_nr;
int dynrelas_nr;
bool enabled;
struct kpatch_internal *internal; /* used internally by core module */
};
Expand Down
7 changes: 2 additions & 5 deletions kmod/patch/kpatch-patch-hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module_param(replace, bool, S_IRUGO);
MODULE_PARM_DESC(replace, "replace all previously loaded patch modules");

extern char __kpatch_patches, __kpatch_patches_end;
extern char __kpatch_dynrelas, __kpatch_dynrelas_end;

static struct kpatch_module kpmod;
static struct kobject *patch_kobj;
Expand Down Expand Up @@ -72,15 +71,13 @@ static struct kobj_attribute patch_enabled_attr =

static int __init patch_init(void)
{
struct kpatch_patch *patches;
int ret;

kpmod.mod = THIS_MODULE;
kpmod.patches = (struct kpatch_patch *)&__kpatch_patches;
kpmod.patches_nr = (&__kpatch_patches_end - &__kpatch_patches) /
sizeof(*kpmod.patches);
kpmod.dynrelas = (struct kpatch_dynrela *)&__kpatch_dynrelas;
kpmod.dynrelas_nr = (&__kpatch_dynrelas_end - &__kpatch_dynrelas) /
sizeof(*kpmod.dynrelas);
sizeof(*patches);

patch_kobj = kobject_create_and_add(THIS_MODULE->name,
kpatch_patches_kobj);
Expand Down
6 changes: 2 additions & 4 deletions kmod/patch/kpatch.lds
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
__kpatch_patches = ADDR(.kpatch.patches);
__kpatch_patches_end = ADDR(.kpatch.patches) + SIZEOF(.kpatch.patches);
__kpatch_dynrelas = ADDR(.kpatch.dynrelas);
__kpatch_dynrelas_end = ADDR(.kpatch.dynrelas) + SIZEOF(.kpatch.dynrelas);
__kpatch_patches = ADDR(.patches);
__kpatch_patches_end = ADDR(.patches) + SIZEOF(.patches);
10 changes: 7 additions & 3 deletions kpatch-build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ include ../Makefile.inc
CFLAGS += -I../kmod/patch -Wall -g
LDFLAGS = -lelf

TARGETS = create-diff-object
TARGETS = create-diff-object add-patches-section link-vmlinux-syms


all: $(TARGETS)

create-diff-object: create-diff-object.c list.h lookup.c lookup.h
$(CC) $(CFLAGS) create-diff-object.c lookup.c -o $@ $(LDFLAGS)
%: %.c
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)

create-diff-object: create-diff-object.c list.h
$(CC) $(CFLAGS) create-diff-object.c -o $@ $(LDFLAGS)

install: all
$(INSTALL) -d $(LIBEXECDIR)
Expand Down
Loading

0 comments on commit bf4be47

Please sign in to comment.