Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Benes <mbenes@suse.cz>2019-09-24 13:50:40 +0200
committerMiroslav Benes <mbenes@suse.cz>2019-09-24 13:50:40 +0200
commitec6ce60989bfd2b4b77fa2b8138807a1ebb011fa (patch)
treef233d61b8ed1a1050cf81fc7ce75d3bb92ba42a8
parent9e8341f61166de6936ab65e4a58d2abfe3d3c3e9 (diff)
parentb5af38e1d9936a18754518939823262facb4dc76 (diff)
Merge branch 'master-livepatch' into master-livepatch-sle12
-rw-r--r--klp_syscalls.h79
-rw-r--r--rpm/kgraft-patch.spec2
-rwxr-xr-xscripts/create-makefile.sh2
-rwxr-xr-xscripts/register-patches.sh17
-rwxr-xr-xscripts/tar-up.sh1
-rw-r--r--uname_patch/livepatch_uname.c2
-rw-r--r--uname_patch/livepatch_uname.h9
7 files changed, 105 insertions, 7 deletions
diff --git a/klp_syscalls.h b/klp_syscalls.h
new file mode 100644
index 0000000..4cb1e7e
--- /dev/null
+++ b/klp_syscalls.h
@@ -0,0 +1,79 @@
+#ifndef _KLP_SYSCALLS_H
+#define _KLP_SYSCALLS_H
+
+#include <linux/version.h>
+#include <linux/syscalls.h>
+
+/*
+ * For kernels after 4.17.0, syscalls' symbol names as constructed by
+ * the kernel's __SYSCALL_DEFINEx macro depend on kernel version and
+ * architecture.
+*/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0)
+/* C.f. include/linux/syscalls.h */
+
+#define KLP_SYSCALL_SYM(name) SyS_ ## name
+
+#ifdef CONFIG_COMPAT
+/* What comes out of COMPAT_SYSCALL_DEFINEx(). */
+#define KLP_COMPAT_SYSCALL_SYM(name) compat_SyS_ ## name
+
+#define KLP_SYSCALL_DECLx(x, sym, ...) \
+ asmlinkage long sym(__MAP(x,__SC_LONG,__VA_ARGS__))
+
+#endif /* CONFIG_COMPAT */
+
+
+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0) */
+
+
+#if defined(CONFIG_X86_64)
+/* C.f. arch/x86/include/asm/syscall_wrapper.h */
+#define KLP_SYSCALL_SYM(name) __x64_sys_ ## name
+
+#ifdef CONFIG_IA32_EMULATION
+#define KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS 1
+/* Compat stub for common syscalls. */
+#define KLP_SYSCALL_COMPAT_STUB_SYM(name) __ia32_sys_ ## name
+#endif /* CONFIG_IA32_EMULATION */
+
+#ifdef CONFIG_COMPAT
+/* What comes out of COMPAT_SYSCALL_DEFINEx(). */
+#define KLP_COMPAT_SYSCALL_SYM(name) __ia32_compat_sys_ ## name
+#endif /* CONFIG_COMPAT */
+
+#define KLP_SYSCALL_DECLx(x, sym, ...) \
+ asmlinkage long sym(const struct pt_regs *)
+
+
+#elif defined(CONFIG_S390)
+/* C.f. arch/s390/include/asm/syscall_wrapper.h */
+#define KLP_SYSCALL_SYM(name) __s390x_sys_ ## name
+
+#ifdef CONFIG_COMPAT
+#define KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS 1
+/* Compat stub for common syscalls. */
+#define KLP_SYSCALL_COMPAT_STUB_SYM(name) __s390_sys_ ## name
+#define KLP_COMPAT_SYSCALL_SYM(name) __s390_compat_sys_ ## name
+#endif /* CONFIG_COMPAT */
+
+#define KLP_SYSCALL_DECLx(x, sym, ...) \
+ asmlinkage long sym(__MAP(x,__SC_LONG,__VA_ARGS__))
+
+
+#else
+/* C.f. include/linux/syscalls.h */
+#define KLP_SYSCALL_SYM(name) __se_sys_ ## name
+
+#ifdef CONFIG_COMPAT
+#define KLP_COMPAT_SYSCALL_SYM(name) __se_compat_sys_ ## name
+#endif /* CONFIG_COMPAT */
+
+#define KLP_SYSCALL_DECLx(x, sym, ...) \
+ asmlinkage long sym(__MAP(x,__SC_LONG,__VA_ARGS__))
+
+
+#endif
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0) */
+#endif /* _KLP_SYSCALLS_H */
diff --git a/rpm/kgraft-patch.spec b/rpm/kgraft-patch.spec
index d2c4e47..379cae1 100644
--- a/rpm/kgraft-patch.spec
+++ b/rpm/kgraft-patch.spec
@@ -35,6 +35,7 @@ Source5: shadow.h
Source6: kallsyms_relocs.h
Source7: kallsyms_relocs.c
Source8: klp_convert.h
+Source9: klp_syscalls.h
@@KLP_PATCHES_SOURCES@@
BuildRequires: kernel-syms kgraft-devel libelf-devel
%if 0%{?use_klp_convert}
@@ -57,6 +58,7 @@ cp %_sourcedir/kallsyms_relocs.h .
cp %_sourcedir/kallsyms_relocs.c .
cp %_sourcedir/Makefile .
cp %_sourcedir/klp_convert.h .
+cp %_sourcedir/klp_syscalls.h .
%build
sed -i 's/@@RPMRELEASE@@/%module_num/g' Makefile
diff --git a/scripts/create-makefile.sh b/scripts/create-makefile.sh
index 25bab16..a6acaa1 100755
--- a/scripts/create-makefile.sh
+++ b/scripts/create-makefile.sh
@@ -13,6 +13,8 @@ objects=$(find . -type f -name "*.c" -o -iname "*.s" | sed "s/^\.\/\(.*\)\.[csS]
cat << EOF > $1/Makefile
KDIR ?= /lib/modules/\`uname -r\`/build
+ccflags-y += -I\$(obj)
+
obj-m := kgraft-patch-@@RPMRELEASE@@.o
kgraft-patch-@@RPMRELEASE@@-y := $objects
diff --git a/scripts/register-patches.sh b/scripts/register-patches.sh
index a827068..191979d 100755
--- a/scripts/register-patches.sh
+++ b/scripts/register-patches.sh
@@ -155,9 +155,16 @@ KLP_PATCHES_OBJS=$(
echo -n '\t\t.funcs = (struct klp_func[]) {\n'
if [ x"$o" = xvmlinux ]; then
- echo -n '\t\t\t{ .old_name = "SyS_newuname", '
- echo -n '.new_func = klp_sys_newuname, '
- echo -n '},\n'
+ echo -n '\t\t\t{\n'
+ echo -n '\t\t\t .old_name = __stringify(KLP_SYSCALL_SYM(newuname)),\n'
+ echo -n '\t\t\t .new_func = KLP_SYSCALL_SYM(klp_newuname),\n'
+ echo -n '\t\t\t},\n'
+ echo -n '#ifdef KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS\n'
+ echo -n '\t\t\t{\n'
+ echo -n '\t\t\t .old_name = __stringify(KLP_SYSCALL_COMPAT_STUB_SYM(newuname)),\n'
+ echo -n '\t\t\t .new_func = KLP_SYSCALL_COMPAT_STUB_SYM(klp_newuname),\n'
+ echo -n '\t\t\t},\n'
+ echo -n '#endif\n'
fi
last_cond=
@@ -264,8 +271,8 @@ EOF
# Finish kgraft-patch.spec:
## Enumerate the per subpatch source *.tar.bz2.
-## Note: Start with Source9
-S=9
+## Note: Start with Source10
+S=10
## 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 6c7a0ed..e17b638 100755
--- a/scripts/tar-up.sh
+++ b/scripts/tar-up.sh
@@ -77,6 +77,7 @@ 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 klp_syscalls.h $build_dir
install -m 644 rpm/kgraft-patch.spec $build_dir/kgraft-patch-"$RELEASE".spec
scripts/register-patches.sh $build_dir/livepatch_main.c $build_dir/kgraft-patch-"$RELEASE".spec
install -m 644 rpm/config.sh $build_dir/config.sh
diff --git a/uname_patch/livepatch_uname.c b/uname_patch/livepatch_uname.c
index 84a12f4..4d13421 100644
--- a/uname_patch/livepatch_uname.c
+++ b/uname_patch/livepatch_uname.c
@@ -108,7 +108,7 @@ out:
return ret;
}
-asmlinkage long klp_sys_newuname(struct new_utsname __user *name)
+__SYSCALL_DEFINEx(1, _klp_newuname, struct new_utsname __user *, name)
{
struct new_utsname tmp;
char klp_version[65] = { 0 };
diff --git a/uname_patch/livepatch_uname.h b/uname_patch/livepatch_uname.h
index eecbcac..5a5c468 100644
--- a/uname_patch/livepatch_uname.h
+++ b/uname_patch/livepatch_uname.h
@@ -2,6 +2,7 @@
#define _LIVEPATCH_UNAME_H
#include <linux/utsname.h>
+#include "../klp_syscalls.h"
#ifdef USE_KLP_CONVERT
static inline int klp_patch_uname_init(void) { return 0; }
@@ -9,6 +10,12 @@ static inline int klp_patch_uname_init(void) { return 0; }
extern int klp_patch_uname_init(void);
#endif
-extern asmlinkage long klp_sys_newuname(struct new_utsname __user *name);
+extern KLP_SYSCALL_DECLx(1, KLP_SYSCALL_SYM(klp_newuname),
+ struct new_utsname __user *, name);
+
+#ifdef KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS
+extern KLP_SYSCALL_DECLx(1, KLP_SYSCALL_COMPAT_STUB_SYM(klp_newuname),
+ struct new_utsname __user *, name);
+#endif /* KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS */
#endif