use livepatch 4.5 features in Ubuntu Xenial kernel

Some features were backported into the 4.4 kernel which change the fields
of the livepatch structures. Ensure we can work with either v4.5 or greater,
or Ubuntu 4.4.0-7 or greater.
This commit is contained in:
Chris J Arges 2016-12-16 07:05:53 -06:00
parent 254e8bbe8d
commit eb55adc52d
2 changed files with 26 additions and 4 deletions

View File

@ -46,8 +46,13 @@
#include <linux/string.h>
#include <asm/stacktrace.h>
#include <asm/cacheflush.h>
#include <generated/utsrelease.h>
#include "kpatch.h"
#ifndef UTS_UBUNTU_RELEASE_ABI
#define UTS_UBUNTU_RELEASE_ABI 0
#endif
#if !defined(CONFIG_FUNCTION_TRACER) || \
!defined(CONFIG_HAVE_FENTRY) || \
!defined(CONFIG_MODULES) || \
@ -676,7 +681,10 @@ static int kpatch_write_relocations(struct kpatch_module *kpmod,
int ret, size, readonly = 0, numpages;
struct kpatch_dynrela *dynrela;
u64 loc, val;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
)
unsigned long core = (unsigned long)kpmod->mod->core_layout.base;
unsigned long core_size = kpmod->mod->core_layout.size;
#else
@ -746,7 +754,10 @@ static int kpatch_write_relocations(struct kpatch_module *kpmod,
}
#ifdef CONFIG_DEBUG_SET_MODULE_RONX
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
)
if (loc < core + kpmod->mod->core_layout.ro_size)
#else
if (loc < core + kpmod->mod->core_ro_size)

View File

@ -25,11 +25,16 @@
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/version.h>
#include <generated/utsrelease.h>
#include <linux/livepatch.h>
#include "kpatch-patch.h"
#ifndef UTS_UBUNTU_RELEASE_ABI
#define UTS_UBUNTU_RELEASE_ABI 0
#endif
/*
* There are quite a few similar structures at play in this file:
* - livepatch.h structs prefixed with klp_*
@ -238,7 +243,10 @@ static int __init patch_init(void)
lfunc = &lfuncs[j];
lfunc->old_name = func->kfunc->name;
lfunc->new_func = (void *)func->kfunc->new_addr;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
)
lfunc->old_sympos = func->kfunc->sympos;
#else
lfunc->old_addr = func->kfunc->old_addr;
@ -255,7 +263,10 @@ static int __init patch_init(void)
list_for_each_entry(reloc, &object->relocs, list) {
lreloc = &lrelocs[j];
lreloc->loc = reloc->kdynrela->dest;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
#if (( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) ) || \
( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
UTS_UBUNTU_RELEASE_ABI >= 7 ) \
)
lreloc->sympos = reloc->kdynrela->sympos;
#else
lreloc->val = reloc->kdynrela->src;