Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Benes <mbenes@suse.cz>2019-03-08 13:12:01 +0100
committerMiroslav Benes <mbenes@suse.cz>2019-03-08 13:12:01 +0100
commit831b4fae21eed0d1a42ac05b668ef33056bca684 (patch)
treed97299f94a00f6621c503db2342aa24ab8fa122c
parentcf0082ec9e1b6c219098092d72680a65e8efc30b (diff)
parent060163bd26b9dfff93989de95ba0fa4f29d9744c (diff)
Merge branch 'master-livepatch' into SLE15-SP1_Update_0SLE15-SP1_Update_0
-rw-r--r--klp_convert.h16
-rw-r--r--livepatch_main.c6
-rw-r--r--rpm/kernel-livepatch.spec14
-rwxr-xr-xscripts/register-patches.sh4
-rwxr-xr-xscripts/tar-up.sh16
-rw-r--r--uname_patch/livepatch_uname.c34
-rw-r--r--uname_patch/livepatch_uname.h5
7 files changed, 78 insertions, 17 deletions
diff --git a/klp_convert.h b/klp_convert.h
new file mode 100644
index 0000000..587c775
--- /dev/null
+++ b/klp_convert.h
@@ -0,0 +1,16 @@
+#ifndef _KLP_KLPCONVERT_H
+#define _KLP_KLPCONVERT_H
+
+#ifdef USE_KLP_CONVERT
+
+#define KLP_SYM_LINKAGE extern
+#define KLP_SYM(sym) sym
+
+#else
+
+#define KLP_SYM_LINKAGE static
+#define KLP_SYM(sym) (*klp_##sym)
+
+#endif
+
+#endif
diff --git a/livepatch_main.c b/livepatch_main.c
index a6262cb..990e5fe 100644
--- a/livepatch_main.c
+++ b/livepatch_main.c
@@ -48,14 +48,18 @@ static int __init klp_patch_init(void)
@@KLP_PATCHES_INIT_CALLS@@;
+#ifndef KLP_NOREG_API
retval = klp_register_patch(&patch);
if (retval)
goto err_patches_cleanup;
+#endif
retval = klp_enable_patch(&patch);
if (!retval)
return retval;
+#ifndef KLP_NOREG_API
WARN_ON(klp_unregister_patch(&patch));
+#endif
err_patches_cleanup:
@@KLP_PATCHES_INIT_ERR_HANDLERS@@;
@@ -68,7 +72,9 @@ static void __exit klp_patch_cleanup(void)
@@KLP_PATCHES_CLEANUP_CALLS@@;
+#ifndef KLP_NOREG_API
WARN_ON(klp_unregister_patch(&patch));
+#endif
}
module_init(klp_patch_init);
diff --git a/rpm/kernel-livepatch.spec b/rpm/kernel-livepatch.spec
index 11efeb9..3ba0652 100644
--- a/rpm/kernel-livepatch.spec
+++ b/rpm/kernel-livepatch.spec
@@ -17,6 +17,8 @@
# needssslcertforbuild
+@@USE_KLP_CONVERT@@
+
Name: kernel-livepatch-@@RELEASE@@
Version: 1
Release: 1
@@ -32,8 +34,12 @@ Source4: source-timestamp
Source5: shadow.h
Source6: kallsyms_relocs.h
Source7: kallsyms_relocs.c
+Source8: klp_convert.h
@@KLP_PATCHES_SOURCES@@
BuildRequires: kernel-syms kernel-livepatch-tools-devel libelf-devel
+%if 0%{?use_klp_convert}
+BuildRequires: kernel-default-livepatch-devel
+%endif
ExclusiveArch: ppc64le x86_64
%klp_module_package
@@ -50,6 +56,7 @@ cp %_sourcedir/shadow.h .
cp %_sourcedir/kallsyms_relocs.h .
cp %_sourcedir/kallsyms_relocs.c .
cp %_sourcedir/Makefile .
+cp %_sourcedir/klp_convert.h .
%build
sed -i 's/@@RPMRELEASE@@/%module_num/g' Makefile
@@ -64,6 +71,13 @@ for flavor in %flavors_to_build; do
mkdir -p "obj/$flavor"
cp -r "$@" "obj/$flavor"
make -C %{kernel_source $flavor} M="$PWD/obj/$flavor" modules
+
+ %if 0%{?use_klp_convert}
+ module=$(find "obj/$flavor" -name 'livepatch*.ko' -printf '%f')
+ klp-convert /usr/src/linux-obj/%_target_cpu/$flavor/Symbols.list \
+ obj/$flavor/$module obj/$flavor/${module}_converted
+ mv obj/$flavor/${module}_converted obj/$flavor/$module
+ %endif
done
%install
diff --git a/scripts/register-patches.sh b/scripts/register-patches.sh
index 1a53baa..ada6c7c 100755
--- a/scripts/register-patches.sh
+++ b/scripts/register-patches.sh
@@ -264,8 +264,8 @@ EOF
# Finish kernel-livepatch.spec:
## Enumerate the per subpatch source *.tar.bz2.
-## Note: Start with Source8
-S=8
+## Note: Start with Source9
+S=9
## First check that none of the to be occupied Source<n> slots has
## been used already.
for i in "${!livepatches[@]}"; do
diff --git a/scripts/tar-up.sh b/scripts/tar-up.sh
index 92fe7b4..fa3c328 100755
--- a/scripts/tar-up.sh
+++ b/scripts/tar-up.sh
@@ -76,6 +76,7 @@ install -m 644 livepatch_main.c $build_dir
install -m 644 shadow.h $build_dir
install -m 644 kallsyms_relocs.h $build_dir
install -m 644 kallsyms_relocs.c $build_dir
+install -m 644 klp_convert.h $build_dir
install -m 644 rpm/kernel-livepatch.spec $build_dir/kernel-livepatch-"$RELEASE".spec
scripts/register-patches.sh $build_dir/livepatch_main.c $build_dir/kernel-livepatch-"$RELEASE".spec
install -m 644 rpm/config.sh $build_dir/config.sh
@@ -104,3 +105,18 @@ sed -i \
# changelog
changelog=$build_dir/kernel-livepatch-"$RELEASE".changes
scripts/gitlog2changes.pl HEAD -- > "$changelog"
+
+# klp-convert
+parse_release() {
+ echo "$1" | \
+ sed 's/SLE\([0-9]\+\)\(-SP\([0-9]\+\)\)\?_Update_\([0-9]\+\)/\1,\3,\4/' | \
+ awk -F, '{ print $1 " " ($2 ? $2 : 0) " " $3 }'
+}
+
+rel=($(parse_release $RELEASE))
+if [[ -n "${rel[0]##*Test*}" && ${rel[0]} -eq 15 && ${rel[1]} -eq 1 ]]; then
+ sed -i "s/@@USE_KLP_CONVERT@@/%define use_klp_convert 1/" $build_dir/kernel-livepatch-"$RELEASE".spec
+ sed -i "/^KDIR/a ccflags-y := -DUSE_KLP_CONVERT" $build_dir/Makefile
+else
+ sed -i "s/@@USE_KLP_CONVERT@@//" $build_dir/kernel-livepatch-"$RELEASE".spec
+fi
diff --git a/uname_patch/livepatch_uname.c b/uname_patch/livepatch_uname.c
index fdd11cc..84a12f4 100644
--- a/uname_patch/livepatch_uname.c
+++ b/uname_patch/livepatch_uname.c
@@ -33,6 +33,8 @@
#include <linux/string.h>
#include <asm/uaccess.h>
+#include "klp_convert.h"
+
#ifdef COMPAT_UTS_MACHINE
#define override_architecture(name) \
(personality(current->personality) == PER_LINUX32 && \
@@ -76,7 +78,7 @@ static int override_release(char __user *release, size_t len)
char *klp_tag="/lp-@@GITREV@@";
-static struct rw_semaphore *klp_uts_sem;
+KLP_SYM_LINKAGE struct rw_semaphore KLP_SYM(uts_sem);
static int override_version(char __user *version, size_t len, char *klp_version)
{
@@ -108,25 +110,26 @@ out:
asmlinkage long klp_sys_newuname(struct new_utsname __user *name)
{
- int errno = 0;
+ struct new_utsname tmp;
char klp_version[65] = { 0 };
- down_read(klp_uts_sem);
- if (copy_to_user(name, utsname(), sizeof *name))
- errno = -EFAULT;
+ down_read(&KLP_SYM(uts_sem));
+ memcpy(&tmp, utsname(), sizeof(tmp));
memcpy(klp_version, utsname()->version, sizeof(utsname()->version));
- up_read(klp_uts_sem);
-
- if (!errno && override_release(name->release, sizeof(name->release)))
- errno = -EFAULT;
- if (!errno && override_architecture(name))
- errno = -EFAULT;
- if (!errno && override_version(name->version, sizeof(name->version),
- klp_version))
- errno = -EFAULT;
- return errno;
+ up_read(&KLP_SYM(uts_sem));
+ if (copy_to_user(name, &tmp, sizeof(tmp)))
+ return -EFAULT;
+
+ if (override_release(name->release, sizeof(name->release)))
+ return -EFAULT;
+ if (override_architecture(name))
+ return -EFAULT;
+ if (override_version(name->version, sizeof(name->version), klp_version))
+ return -EFAULT;
+ return 0;
}
+#ifndef USE_KLP_CONVERT
int klp_patch_uname_init(void)
{
unsigned long addr;
@@ -140,3 +143,4 @@ int klp_patch_uname_init(void)
return 0;
}
+#endif
diff --git a/uname_patch/livepatch_uname.h b/uname_patch/livepatch_uname.h
index ccfd6c5..eecbcac 100644
--- a/uname_patch/livepatch_uname.h
+++ b/uname_patch/livepatch_uname.h
@@ -3,7 +3,12 @@
#include <linux/utsname.h>
+#ifdef USE_KLP_CONVERT
+static inline int klp_patch_uname_init(void) { return 0; }
+#else
extern int klp_patch_uname_init(void);
+#endif
+
extern asmlinkage long klp_sys_newuname(struct new_utsname __user *name);
#endif