Merge pull request #637 from arges/636

kpatch and patch module builds fail on Ubuntu 16.04 #636
This commit is contained in:
Jessica Yu 2016-12-16 10:55:45 -08:00 committed by GitHub
commit e9fc979712
3 changed files with 34 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) || \
@ -632,7 +637,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
@ -702,7 +710,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;

View File

@ -602,6 +602,14 @@ echo "Building patch module: kpatch-$PATCHNAME.ko"
cp "$OBJDIR/.config" "$SRCDIR"
cd "$SRCDIR"
make prepare >> "$LOGFILE" 2>&1 || die
if [[ $DISTRO == ubuntu ]]; then
# UBUNTU: add UTS_UBUNTU_RELEASE_ABI to utsrelease.h after regenerating it
UBUNTU_ABI=${ARCHVERSION#*-}
UBUNTU_ABI=${UBUNTU_ABI%-*}
echo "#define UTS_UBUNTU_RELEASE_ABI "$UBUNTU_ABI"" >> "$SRCDIR"/include/generated/utsrelease.h
fi
cd "$TEMPDIR/output"
ld -r -o ../patch/output.o $(find . -name "*.o") >> "$LOGFILE" 2>&1 || die
md5sum ../patch/output.o | awk '{printf "%s\0", $1}' > checksum.tmp || die