Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches from Photon OS #1428

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kmod/patch/kpatch-patch-hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/slab.h>
#include <linux/kallsyms.h>
#include "kpatch.h"
#include <linux/livepatch.h>
#include "kpatch-patch.h"

static bool replace;
Expand Down
37 changes: 33 additions & 4 deletions kmod/patch/kpatch-patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@
#ifndef _KPATCH_PATCH_H_
#define _KPATCH_PATCH_H_

#include <linux/version.h>

/* Support for livepatch callbacks? */
#ifdef RHEL_RELEASE_CODE
# if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)
# define HAVE_CALLBACKS
# endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
# define HAVE_CALLBACKS
#endif

#ifdef HAVE_CALLBACKS
/* IMPORTANT: include ordering is critical! */
# ifdef _LINUX_LIVEPATCH_H_
typedef struct klp_object klp_obj;
# else
/*
* Basically just a placeholder for when we can't include linux/livepatch.h.
* The correct type, which is what gets packed in the section, is
* struct klp_object.
*/
typedef void klp_obj;
# endif /* _LINUX_LIVEPATCH_H_ */
#else
#include "kpatch.h"
typedef struct kpatch_object klp_obj;
#endif /* HAVE_CALLBACKS */

struct kpatch_patch_func {
unsigned long new_addr;
unsigned long new_size;
Expand All @@ -43,20 +71,21 @@ struct kpatch_patch_dynrela {
long addend;
};


struct kpatch_pre_patch_callback {
int (*callback)(void *obj);
int (*callback)(klp_obj *obj);
char *objname;
};
struct kpatch_post_patch_callback {
void (*callback)(void *obj);
void (*callback)(klp_obj *obj);
char *objname;
};
struct kpatch_pre_unpatch_callback {
void (*callback)(void *obj);
void (*callback)(klp_obj *obj);
char *objname;
};
struct kpatch_post_unpatch_callback {
void (*callback)(void *obj);
void (*callback)(klp_obj *obj);
char *objname;
};

Expand Down
22 changes: 5 additions & 17 deletions kmod/patch/livepatch-patch-hook.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Josh Poimboeuf <[email protected]>
* Copyright (C) 2014 Seth Jennings <[email protected]>
* Copyright (C) 2014 Seth Jennings <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -56,14 +56,6 @@
# define HAVE_IMMEDIATE
#endif

#ifdef RHEL_RELEASE_CODE
# if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)
# define HAVE_CALLBACKS
# endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
# define HAVE_CALLBACKS
#endif

#ifdef RHEL_RELEASE_CODE
# if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 8) && \
RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)) || \
Expand Down Expand Up @@ -356,8 +348,7 @@ static int add_callbacks_to_patch_objects(void)
object->name ? object->name : "vmlinux");
return -EINVAL;
}
object->callbacks.pre_patch = (int (*)(struct klp_object *))
p_pre_patch_callback->callback;
object->callbacks.pre_patch = p_pre_patch_callback->callback;
}

for (p_post_patch_callback = __kpatch_callbacks_post_patch;
Expand All @@ -371,8 +362,7 @@ static int add_callbacks_to_patch_objects(void)
object->name ? object->name : "vmlinux");
return -EINVAL;
}
object->callbacks.post_patch = (void (*)(struct klp_object *))
p_post_patch_callback->callback;
object->callbacks.post_patch = p_post_patch_callback->callback;
}

for (p_pre_unpatch_callback = __kpatch_callbacks_pre_unpatch;
Expand All @@ -386,8 +376,7 @@ static int add_callbacks_to_patch_objects(void)
object->name ? object->name : "vmlinux");
return -EINVAL;
}
object->callbacks.pre_unpatch = (void (*)(struct klp_object *))
p_pre_unpatch_callback->callback;
object->callbacks.pre_unpatch = p_pre_unpatch_callback->callback;
}

for (p_post_unpatch_callback = __kpatch_callbacks_post_unpatch;
Expand All @@ -401,8 +390,7 @@ static int add_callbacks_to_patch_objects(void)
object->name ? object->name : "vmlinux");
return -EINVAL;
}
object->callbacks.post_unpatch = (void (*)(struct klp_object *))
p_post_unpatch_callback->callback;
object->callbacks.post_unpatch = p_post_unpatch_callback->callback;
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,19 @@ static struct rela *toc_rela(const struct rela *rela)
static void kpatch_bundle_symbols(struct kpatch_elf *kelf)
{
struct symbol *sym;
unsigned int expected_offset;
uint64_t expected_offset;

list_for_each_entry(sym, &kelf->symbols, list) {
if (is_bundleable(sym)) {
if (sym->pfx)
expected_offset = 16;
expected_offset = sym->pfx->sym.st_size;
else if (is_gcc6_localentry_bundled_sym(kelf, sym))
expected_offset = 8;
else
expected_offset = 0;

if (sym->sym.st_value != expected_offset) {
ERROR("symbol %s at offset %lu within section %s, expected %u",
ERROR("symbol %s at offset %lu within section %s, expected %lu",
sym->name, sym->sym.st_value,
sym->sec->name, expected_offset);
}
Expand Down
2 changes: 1 addition & 1 deletion kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static void kpatch_link_prefixed_functions(struct kpatch_elf *kelf)

list_for_each_entry(func, &kelf->symbols, list) {
if (func->type == STT_FUNC && func->sec == pfx->sec &&
func->sym.st_value == pfx->sym.st_value + 16) {
func->sym.st_value == pfx->sym.st_value + pfx->sym.st_size) {

/*
* If a func has aliases, it's possible for
Expand Down
Loading