From 176f1368a5bd9099637e72b4585ae44374d9b6e1 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Thu, 31 Aug 2017 14:59:29 +0300 Subject: [PATCH 01/16] Add baselibs for repacking aarch64 to armv7l Change-Id: Ic5bed2e632983f985ddd25e1da85627c3977ee53 Signed-off-by: Alexander Aksenov --- packaging/baselibs.conf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packaging/baselibs.conf diff --git a/packaging/baselibs.conf b/packaging/baselibs.conf new file mode 100644 index 0000000..8e94d5f --- /dev/null +++ b/packaging/baselibs.conf @@ -0,0 +1,3 @@ +arch aarch64 targets armv7l:aarch64 +swap-modules + +/ -- 2.7.4 From 17192226ff0dc0bcdc728b0256633c5c2a9870fe Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Fri, 1 Sep 2017 11:15:37 +0300 Subject: [PATCH 02/16] Fix deploy script - add unused *.ko deletion - cleanup after installation - add support TM2 device - fix rpi3 model name Change-Id: Ia7dfd8ab46a69148febcef8d816af325db14c7bc Signed-off-by: Alexander Aksenov --- deploy.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index 5e1c538..5274d58 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,20 +4,40 @@ model=$(sed -n "s|.*tizen.org/system/model_name[^>]*>\([^<]*\)<.*|\1|p" /etc/co modpath=/opt/swap/sdk case $model in +# armv7l "TM1") mv $modpath/tm1_swap_modules/* $modpath + rm -r $modpath/tm1_swap_modules + rm -rf $modpath/odroid_swap_modules ;; + "xu3") + mv $modpath/odroid_swap_modules/* $modpath + rm -r $modpath/odroid_swap_modules + rm -rf $modpath/tm1_swap_modules + ;; +# x86 "Emulator") mv $modpath/emul_swap_modules/* $modpath + rm -r $modpath/emul_swap_modules + ;; +# aarch64 + "TM2") + mv $modpath/tm2_swap_modules/* $modpath + rm -r $modpath/tm2_swap_modules + rm -rf $modpath/rpi3_swap_modules + rm -rf $modpath/tw2_swap_modules ;; "TW2") mv $modpath/tw2_swap_modules/* $modpath + rm -r $modpath/tw2_swap_modules + rm -rf $modpath/rpi3_swap_modules + rm -rf $modpath/tm2_swap_modules ;; - "xu3") - mv $modpath/odroid_swap_modules/* $modpath - ;; - "Generic") + "rpi3") mv $modpath/rpi3_swap_modules/* $modpath + rm -r $modpath/rpi3_swap_modules + rm -rf $modpath/tw2_swap_modules + rm -rf $modpath/tm2_swap_modules ;; *) echo "Device isn't supported" > /tmp/swap-modules_install.log -- 2.7.4 From 7d7940c09a42b8cf844d47df7751d39b025bb621 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Fri, 1 Sep 2017 11:16:12 +0300 Subject: [PATCH 03/16] Add TW1 support Change-Id: I1621784c3b9d5e8e10f9f788b822abce9d8efaba Signed-off-by: Alexander Aksenov --- deploy.sh | 8 ++++++++ packaging/swap-modules.spec | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/deploy.sh b/deploy.sh index 5274d58..5309f27 100755 --- a/deploy.sh +++ b/deploy.sh @@ -9,11 +9,19 @@ case $model in mv $modpath/tm1_swap_modules/* $modpath rm -r $modpath/tm1_swap_modules rm -rf $modpath/odroid_swap_modules + rm -rf $modpath/tw1_swap_modules ;; "xu3") mv $modpath/odroid_swap_modules/* $modpath rm -r $modpath/odroid_swap_modules rm -rf $modpath/tm1_swap_modules + rm -rf $modpath/tw1_swap_modules + ;; + "TW1") + mv $modpath/tw1_swap_modules/* $modpath + rm -r $modpath/tw1_swap_modules + rm -rf $modpath/odroid_swap_modules + rm -rf $modpath/tm1_swap_modules ;; # x86 "Emulator") diff --git a/packaging/swap-modules.spec b/packaging/swap-modules.spec index 23b90d3..1702a9a 100755 --- a/packaging/swap-modules.spec +++ b/packaging/swap-modules.spec @@ -16,6 +16,8 @@ Provides: swap-modules BuildRequires: kernel-devel-3.10-sc7730 # Odroid BuildRequires: arm-odroidxu3-linux-kernel-devel +# TW1 +BuildRequires: kernel-devel-3.4-exynos3250 %else %ifarch aarch64 # RPI3 @@ -53,6 +55,10 @@ Kernel modules for SWAP ./build.sh --kernel /boot/kernel/devel/kernel-devel-arm-odroidxu3 --arch arm clean ./build.sh --kernel /boot/kernel/devel/kernel-devel-arm-odroidxu3 --arch arm compile ./pack.sh /tmp/odroid_swap_modules/ +# TW1 +./build.sh --kernel /boot/kernel/devel/kernel-devel-tizen_wc1 --arch arm clean +./build.sh --kernel /boot/kernel/devel/kernel-devel-tizen_wc1 --arch arm compile +./pack.sh /tmp/tw1_swap_modules/ %else %ifarch aarch64 # RPI3 @@ -82,6 +88,7 @@ mkdir -p %{buildroot}/opt/swap/sdk/ %ifarch armv7l mv /tmp/tm1_swap_modules %{buildroot}/opt/swap/sdk/ mv /tmp/odroid_swap_modules %{buildroot}/opt/swap/sdk/ +mv /tmp/tw1_swap_modules %{buildroot}/opt/swap/sdk/ %else %ifarch aarch64 mv /tmp/rpi3_swap_modules %{buildroot}/opt/swap/sdk/ @@ -108,6 +115,7 @@ install -m 770 deploy.sh -t %{buildroot}/opt/swap/sdk %ifarch armv7l /opt/swap/sdk/tm1_swap_modules /opt/swap/sdk/odroid_swap_modules +/opt/swap/sdk/tw1_swap_modules %else %ifarch aarch64 /opt/swap/sdk/rpi3_swap_modules -- 2.7.4 From b1c5ebfe97e375f8a850cba49e4fbf1cbaa0d6a4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 12 Sep 2017 18:56:39 +0300 Subject: [PATCH 04/16] energy: fix wlan0 checking Change-Id: I0ef6d699127a3279bc7d3da5ca4b1bb09434154d Signed-off-by: Vyacheslav Cherkashin --- energy/energy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/energy/energy.c b/energy/energy.c index 32e4680..49ac721 100644 --- a/energy/energy.c +++ b/energy/energy.c @@ -640,7 +640,7 @@ static void calc_wifi_recv_energy(struct socket *sock, int len) { struct energy_data *ed; - if (len <= 0 || check_wlan0(sock)); + if (len <= 0 || !check_wlan0(sock)) return; ed = get_energy_data_by_socket(current, sock); @@ -653,7 +653,7 @@ static void calc_wifi_send_energy(struct socket *sock, int len) { struct energy_data *ed; - if (len <= 0 || check_wlan0(sock)); + if (len <= 0 || !check_wlan0(sock)) return; ed = get_energy_data_by_socket(current, sock); -- 2.7.4 From 09e4e447325a30c34b4841e2342cbcdce7c7c637 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 12 Sep 2017 19:52:41 +0300 Subject: [PATCH 05/16] preload: add variable initialization Change-Id: Ic2d4c74c4ff120a8940987026ce3d9f7cf4fc9ef Signed-off-by: Vyacheslav Cherkashin --- preload/preload_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preload/preload_module.c b/preload/preload_module.c index a16094c..f3e29f6 100644 --- a/preload/preload_module.c +++ b/preload/preload_module.c @@ -513,7 +513,7 @@ void pm_uprobe_exit(struct sspt_ip *ip) int pm_switch(enum preload_status stat) { - int ret; + int ret = 0; mutex_lock(&status_change); switch (stat) { -- 2.7.4 From 1c13e078bfb46763cf4ec29149a783b4a1183f5a Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 12 Sep 2017 19:00:25 +0300 Subject: [PATCH 06/16] Fix build for Tizen 4.0 Change-Id: Ie2b8140d19658038862b085e66299b9ae12a1338 Signed-off-by: Vyacheslav Cherkashin --- arch/arm/uprobe/swap_uprobe.h | 1 + kprobe/swap_kprobes_deps.h | 1 + ks_features/file_ops.c | 1 + loader/loader_module.c | 1 + master/swap_debugfs.c | 12 ++++++++++-- master/swap_debugfs.h | 1 + nsp/nsp.c | 1 + parser/msg_parser.c | 1 + preload/preload_control.c | 2 ++ preload/preload_module.c | 1 + preload/preload_process.c | 1 + uprobe/swap_uprobes.c | 1 + us_manager/img/img_proc.c | 1 + us_manager/probes/probe_info_new.c | 1 + us_manager/usm_hook.c | 4 +++- 15 files changed, 27 insertions(+), 3 deletions(-) diff --git a/arch/arm/uprobe/swap_uprobe.h b/arch/arm/uprobe/swap_uprobe.h index 86941d0..19c84f1 100644 --- a/arch/arm/uprobe/swap_uprobe.h +++ b/arch/arm/uprobe/swap_uprobe.h @@ -24,6 +24,7 @@ #define _SWAP_ASM_ARM_UPROBE_H +#include #include #include "../probes/compat_arm64.h" diff --git a/kprobe/swap_kprobes_deps.h b/kprobe/swap_kprobes_deps.h index f9b7e1c..e40d39e 100644 --- a/kprobe/swap_kprobes_deps.h +++ b/kprobe/swap_kprobes_deps.h @@ -33,6 +33,7 @@ #define _SWAP_KPROBES_DEPS_H #include /* LINUX_VERSION_CODE, KERNEL_VERSION() */ +#include #include #include #include diff --git a/ks_features/file_ops.c b/ks_features/file_ops.c index db05683..7954528 100644 --- a/ks_features/file_ops.c +++ b/ks_features/file_ops.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "ks_map.h" #include "ksf_msg.h" diff --git a/loader/loader_module.c b/loader/loader_module.c index 5d00cdb..e262c99 100644 --- a/loader/loader_module.c +++ b/loader/loader_module.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/master/swap_debugfs.c b/master/swap_debugfs.c index 2f999d0..661305b 100644 --- a/master/swap_debugfs.c +++ b/master/swap_debugfs.c @@ -23,15 +23,23 @@ #include #include #include +#include #include "swap_initializer.h" #include "swap_debugfs.h" static int change_permission(struct dentry *dentry) { + const int system_fw = 202; + /* set UNIX permissions */ - dentry->d_inode->i_uid.val = 202; /* system_fw */ - dentry->d_inode->i_gid.val = 202; /* system_fw */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) + dentry->d_inode->i_uid = KUIDT_INIT(system_fw); + dentry->d_inode->i_gid = KGIDT_INIT(system_fw); +#else + dentry->d_inode->i_uid = system_fw; + dentry->d_inode->i_gid = system_fw; +#endif return 0; } diff --git a/master/swap_debugfs.h b/master/swap_debugfs.h index 39c1e50..2717db9 100644 --- a/master/swap_debugfs.h +++ b/master/swap_debugfs.h @@ -39,6 +39,7 @@ struct dfs_setget_64 { }; struct dentry; +struct file_operations; struct dentry *swap_debugfs_create_setget_u64(const char *name, umode_t mode, struct dentry *parent, diff --git a/nsp/nsp.c b/nsp/nsp.c index e03cd2c..39d8d29 100644 --- a/nsp/nsp.c +++ b/nsp/nsp.c @@ -20,6 +20,7 @@ */ +#include #include #include #include diff --git a/parser/msg_parser.c b/parser/msg_parser.c index 98b9d30..d35952d 100644 --- a/parser/msg_parser.c +++ b/parser/msg_parser.c @@ -30,6 +30,7 @@ */ +#include #include #include #include diff --git a/preload/preload_control.c b/preload/preload_control.c index 43b92d0..7d6567e 100644 --- a/preload/preload_control.c +++ b/preload/preload_control.c @@ -1,8 +1,10 @@ #include +#include #include #include #include #include +#include #include #include diff --git a/preload/preload_module.c b/preload/preload_module.c index f3e29f6..fd63bdf 100644 --- a/preload/preload_module.c +++ b/preload/preload_module.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/preload/preload_process.c b/preload/preload_process.c index d4dd3a7..1b777b1 100644 --- a/preload/preload_process.c +++ b/preload/preload_process.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/uprobe/swap_uprobes.c b/uprobe/swap_uprobes.c index fe6429e..d25b2d7 100644 --- a/uprobe/swap_uprobes.c +++ b/uprobe/swap_uprobes.c @@ -32,6 +32,7 @@ #include +#include #include #include diff --git a/us_manager/img/img_proc.c b/us_manager/img/img_proc.c index 1d4db97..40f6470 100644 --- a/us_manager/img/img_proc.c +++ b/us_manager/img/img_proc.c @@ -23,6 +23,7 @@ */ +#include #include #include #include diff --git a/us_manager/probes/probe_info_new.c b/us_manager/probes/probe_info_new.c index 701b61a..303f332 100644 --- a/us_manager/probes/probe_info_new.c +++ b/us_manager/probes/probe_info_new.c @@ -20,6 +20,7 @@ */ +#include #include #include #include diff --git a/us_manager/usm_hook.c b/us_manager/usm_hook.c index 830c114..c41fd94 100644 --- a/us_manager/usm_hook.c +++ b/us_manager/usm_hook.c @@ -23,6 +23,7 @@ #include #include #include +#include // for swap_hlist_for_each_entry #include "usm_hook.h" @@ -58,9 +59,10 @@ EXPORT_SYMBOL_GPL(usm_hook_unreg); void usm_hook_mmap(struct sspt_proc *proc, struct vm_area_struct *vma) { struct usm_hook *hook; + DECLARE_NODE_PTR_FOR_HLIST(node); down_read(&hook_sem); - hlist_for_each_entry(hook, &hook_head, node) { + swap_hlist_for_each_entry(hook, node, &hook_head, node) { if (hook->mmap) hook->mmap(proc, vma); } -- 2.7.4 From f7ea2bac3acfd5b813feb27a1424e48f7e21d0ad Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Mon, 18 Sep 2017 18:48:12 +0300 Subject: [PATCH 07/16] Fix name collisions Linux kernel Kprobes had name collisions with SWAP kprobes Change-Id: Ie69d28976fb6f8d9b18fa3b152109b6be940027f Signed-off-by: Alexander Aksenov --- kprobe/arch/arm/swap-asm/swap_kprobes.h | 6 +++--- kprobe/arch/arm64/swap-asm/kprobes-arm64.c | 17 ++++++++++------- kprobe/arch/arm64/swap-asm/kprobes-arm64.h | 2 +- kprobe/arch/arm64/swap-asm/swap_kprobes.h | 7 ++++--- kprobe/arch/x86/swap-asm/swap_kprobes.h | 10 +++++----- kprobe/swap_kprobes.h | 2 +- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/kprobe/arch/arm/swap-asm/swap_kprobes.h b/kprobe/arch/arm/swap-asm/swap_kprobes.h index 183cba8..0ef86f2 100644 --- a/kprobe/arch/arm/swap-asm/swap_kprobes.h +++ b/kprobe/arch/arm/swap-asm/swap_kprobes.h @@ -191,12 +191,12 @@ struct kp_core_ctlblk { }; /** - * @struct arch_specific_insn + * @struct swap_arch_specific_insn * @brief Architecture specific copy of original instruction. - * @var arch_specific_insn::insn + * @var swap_arch_specific_insn::insn * Copy of the original instruction. */ -struct arch_specific_insn { +struct swap_arch_specific_insn { kprobe_opcode_t *insn; }; diff --git a/kprobe/arch/arm64/swap-asm/kprobes-arm64.c b/kprobe/arch/arm64/swap-asm/kprobes-arm64.c index f715938..14aff81 100644 --- a/kprobe/arch/arm64/swap-asm/kprobes-arm64.c +++ b/kprobe/arch/arm64/swap-asm/kprobes-arm64.c @@ -31,7 +31,7 @@ */ static unsigned long __check_pstate(struct kp_core *p, struct pt_regs *regs) { - struct arch_specific_insn *asi = &p->ainsn; + struct swap_arch_specific_insn *asi = &p->ainsn; unsigned long pstate = regs->pstate & 0xffffffff; return asi->pstate_cc(pstate); @@ -60,11 +60,12 @@ static unsigned long __check_tbnz(struct kp_core *p, struct pt_regs *regs) /* * prepare functions for instruction simulation */ -static void prepare_none(struct kp_core *p, struct arch_specific_insn *asi) +static void prepare_none(struct kp_core *p, struct swap_arch_specific_insn *asi) { } -static void prepare_bcond(struct kp_core *p, struct arch_specific_insn *asi) +static void prepare_bcond(struct kp_core *p, + struct swap_arch_specific_insn *asi) { kprobe_opcode_t insn = p->opcode; @@ -72,14 +73,16 @@ static void prepare_bcond(struct kp_core *p, struct arch_specific_insn *asi) asi->pstate_cc = probe_condition_checks[insn & 0xf]; } -static void prepare_cbz_cbnz(struct kp_core *p, struct arch_specific_insn *asi) +static void prepare_cbz_cbnz(struct kp_core *p, + struct swap_arch_specific_insn *asi) { kprobe_opcode_t insn = p->opcode; asi->check_condn = (insn & (1 << 24)) ? __check_cbnz : __check_cbz; } -static void prepare_tbz_tbnz(struct kp_core *p, struct arch_specific_insn *asi) +static void prepare_tbz_tbnz(struct kp_core *p, + struct swap_arch_specific_insn *asi) { kprobe_opcode_t insn = p->opcode; @@ -261,7 +264,7 @@ static const struct aarch64_decode_item aarch64_decode_table[] = { }; static int kp_core_decode_insn(kprobe_opcode_t insn, - struct arch_specific_insn *asi, + struct swap_arch_specific_insn *asi, const struct aarch64_decode_item *tbl) { unsigned int entry, ret = INSN_REJECTED; @@ -303,7 +306,7 @@ static int kp_core_decode_insn(kprobe_opcode_t insn, * INSN_GOOD_NO_SLOT If instruction is supported but doesn't use its slot. */ enum kp_core_insn arm_kp_core_decode_insn(kprobe_opcode_t insn, - struct arch_specific_insn *asi) + struct swap_arch_specific_insn *asi) { return kp_core_decode_insn(insn, asi, aarch64_decode_table); } diff --git a/kprobe/arch/arm64/swap-asm/kprobes-arm64.h b/kprobe/arch/arm64/swap-asm/kprobes-arm64.h index 410a9c0..db7480a 100644 --- a/kprobe/arch/arm64/swap-asm/kprobes-arm64.h +++ b/kprobe/arch/arm64/swap-asm/kprobes-arm64.h @@ -27,6 +27,6 @@ enum kp_core_insn { extern kp_core_pstate_check_t * const kp_core_condition_checks[16]; enum kp_core_insn arm_kp_core_decode_insn(kprobe_opcode_t insn, - struct arch_specific_insn *asi); + struct swap_arch_specific_insn *asi); #endif /* _ARM_KERNEL_KPROBES_ARM64_H */ diff --git a/kprobe/arch/arm64/swap-asm/swap_kprobes.h b/kprobe/arch/arm64/swap-asm/swap_kprobes.h index a2ee3f1..7975938 100644 --- a/kprobe/arch/arm64/swap-asm/swap_kprobes.h +++ b/kprobe/arch/arm64/swap-asm/swap_kprobes.h @@ -37,7 +37,7 @@ struct kprobe; struct kp_core; struct slot_manager; -struct arch_specific_insn; +struct swap_arch_specific_insn; struct kretprobe_instance; @@ -45,12 +45,13 @@ typedef u32 kprobe_opcode_t; typedef unsigned long (kp_core_pstate_check_t)(unsigned long); typedef unsigned long (kp_core_condition_check_t)(struct kp_core *, struct pt_regs *); -typedef void (kp_core_prepare_t)(struct kp_core *, struct arch_specific_insn *); +typedef void (kp_core_prepare_t)(struct kp_core *, + struct swap_arch_specific_insn *); typedef void (kp_core_handler_t)(u32 opcode, long addr, struct pt_regs *); /* architecture specific copy of original instruction */ -struct arch_specific_insn { +struct swap_arch_specific_insn { kprobe_opcode_t *insn; kp_core_pstate_check_t *pstate_cc; kp_core_condition_check_t *check_condn; diff --git a/kprobe/arch/x86/swap-asm/swap_kprobes.h b/kprobe/arch/x86/swap-asm/swap_kprobes.h index 68f0f4c..7aed0bb 100644 --- a/kprobe/arch/x86/swap-asm/swap_kprobes.h +++ b/kprobe/arch/x86/swap-asm/swap_kprobes.h @@ -177,15 +177,15 @@ struct kp_core_ctlblk { /** - * @struct arch_specific_insn + * @struct swap_arch_specific_insn * @brief Architecture specific copy of original instruction. - * @var arch_specific_insn::insn + * @var swap_arch_specific_insn::insn * Copy of the original instruction. - * @var arch_specific_insn::boostable + * @var swap_arch_specific_insn::boostable * If this flag is not 0, this kp_core can be boost when its * post_handler and break_handler is not set. */ -struct arch_specific_insn { +struct swap_arch_specific_insn { kprobe_opcode_t *insn; int boostable; }; @@ -214,7 +214,7 @@ void swap_kretprobe_trampoline(void); void restore_previous_kp_core(struct kp_core_ctlblk *kcb); int swap_can_boost(kprobe_opcode_t *opcodes); -static inline int arch_check_insn(struct arch_specific_insn *ainsn) +static inline int arch_check_insn(struct swap_arch_specific_insn *ainsn) { return 0; } diff --git a/kprobe/swap_kprobes.h b/kprobe/swap_kprobes.h index 3fae497..646a368 100644 --- a/kprobe/swap_kprobes.h +++ b/kprobe/swap_kprobes.h @@ -132,7 +132,7 @@ struct kp_core { unsigned long addr; kprobe_opcode_t opcode; - struct arch_specific_insn ainsn; + struct swap_arch_specific_insn ainsn; }; /** -- 2.7.4 From d910ead60e8cfb11829644c8c20eee4e7d1bee8a Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Tue, 19 Sep 2017 18:47:55 +0300 Subject: [PATCH 08/16] Add calling patch app memory area after lib map Change-Id: Iafa451d395b76c9bc8c6e85b75c3189820c6207d Signed-off-by: Alexander Aksenov --- got_patcher/gt_debugfs.c | 21 ++++++++++++++++ got_patcher/gt_module.c | 62 +++++++++++++++++++++++++++++------------------- got_patcher/gt_module.h | 1 + 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/got_patcher/gt_debugfs.c b/got_patcher/gt_debugfs.c index 628c264..362c5d1 100644 --- a/got_patcher/gt_debugfs.c +++ b/got_patcher/gt_debugfs.c @@ -26,6 +26,7 @@ static const char GT_LIST_TARGETS[] = "list_targets"; static const char GT_HANDLER[] = "handler"; static const char GT_HANDLER_FIXUP_OFF[] = "fixup_handler_off"; static const char GT_HANDLER_RELOC_OFF[] = "reloc_handler_off"; +static const char GT_PROC_FEATURES_OFF[] = "proc_features_off"; static const char GT_PTHREAD[] = "pthread"; static const char GT_MINIMAL_INIT[] = "minimal_init_off"; @@ -156,6 +157,13 @@ static ssize_t handler_reloc_off_write(struct file *file, return get_ul_and_call(buf, len, gtm_set_handler_reloc_off); } +static ssize_t proc_features_off_write(struct file *file, + const char __user *buf, size_t len, + loff_t *ppos) +{ + return get_ul_and_call(buf, len, gtm_set_proc_features_off); +} + static const struct file_operations handler_path_fops = { .owner = THIS_MODULE, .write = handler_path_write, @@ -171,6 +179,11 @@ static const struct file_operations handler_reloc_off_fops = { .write = handler_reloc_off_write, }; +static const struct file_operations proc_features_off_fops = { + .owner = THIS_MODULE, + .write = proc_features_off_write, +}; + /* =========================================================================== * = TARGETS = * =========================================================================== @@ -557,6 +570,14 @@ int gtd_init(void) goto remove; } + dentry = swap_debugfs_create_file(GT_PROC_FEATURES_OFF, + GT_DEFAULT_PERMS, handler, NULL, + &proc_features_off_fops); + if (IS_ERR_OR_NULL(dentry)) { + ret = -ENOMEM; + goto remove; + } + pthread = swap_debugfs_create_dir(GT_PTHREAD, root); if (IS_ERR_OR_NULL(pthread)) { ret = -ENOMEM; diff --git a/got_patcher/gt_module.c b/got_patcher/gt_module.c index 7125cc6..0779177 100644 --- a/got_patcher/gt_module.c +++ b/got_patcher/gt_module.c @@ -60,6 +60,7 @@ static struct bin_data_t _linker_fixup; static struct bin_data_t _linker_reloc; static struct bin_data_t _handler_fixup; static struct bin_data_t _handler_reloc; +static struct bin_data_t _proc_features; static struct bin_data_t _pthread_init; @@ -92,7 +93,8 @@ static inline bool _is_linker_data_available(void) static inline bool _is_handler_data_available(void) { return _is_bin_data_available(&_handler_fixup) && - _is_bin_data_available(&_handler_reloc); + _is_bin_data_available(&_handler_reloc) && + _is_bin_data_available(&_proc_features); } static inline bool _is_pthread_data_available(void) @@ -191,7 +193,6 @@ static unsigned long _redirect_to_handler(struct uretprobe_instance *ri, vaddr = base + off; loader_module_prepare_ujump(ri, regs, vaddr); - _set_in_handler(true); return vaddr; } @@ -210,6 +211,13 @@ static unsigned long _redirect_to_reloc_handler(struct uretprobe_instance *ri, return _redirect_to_handler(ri, regs, hd, _handler_reloc.off); } +static unsigned long _redirect_to_proc_features(struct uretprobe_instance *ri, + struct pt_regs *regs, + struct hd_t *hd) +{ + return _redirect_to_handler(ri, regs, hd, _proc_features.off); +} + static int _process_eh(struct uretprobe_instance *ri, struct pt_regs *regs, @@ -228,10 +236,12 @@ static int _process_eh(struct uretprobe_instance *ri, struct pt_regs *regs, goto out_set_orig; if ((lpd_get_state(hd) == NOT_LOADED || lpd_get_state(hd) == FAILED) && - lpd_get_init_state(pd)) + lpd_get_init_state(pd)) { vaddr = loader_not_loaded_entry(ri, regs, pd, hd); - else if (lpd_get_state(hd) == LOADED) + } else if (lpd_get_state(hd) == LOADED) { + _set_in_handler(true); vaddr = rh(ri, regs, hd); + } out_set_orig: loader_set_priv_origin(ri, vaddr); @@ -272,8 +282,9 @@ static int _process_rh(struct uretprobe_instance *ri, struct pt_regs *regs, break; case LOADING: loader_loading_ret(ri, regs, pd, hd); - rh(ri, regs, hd); /* TODO Think about: Possible only if we - * do not need _set_in_handler() */ + /* Patch all binaries */ + if (lpd_get_state(hd)) + rh(ri, regs, hd); break; case LOADED: /* TODO Check does we need this if library is loaded @@ -291,15 +302,15 @@ static int _process_rh(struct uretprobe_instance *ri, struct pt_regs *regs, return 0; } -static int dl_fixup_rh(struct uretprobe_instance *ri, struct pt_regs *regs) +static int common_rh(struct uretprobe_instance *ri, struct pt_regs *regs) { - return _process_rh(ri, regs, &_redirect_to_fixup_handler, - _handler_fixup.dentry); + return _process_rh(ri, regs, &_redirect_to_proc_features, + _proc_features.dentry); } /* TODO Make ordinary interface. Now real data_size is set in init, because * it is unknown in this module during compile time. */ -static struct probe_desc pin_fixup = MAKE_URPROBE(dl_fixup_eh, dl_fixup_rh, 0); +static struct probe_desc pin_fixup = MAKE_URPROBE(dl_fixup_eh, common_rh, 0); static int dl_reloc_eh(struct uretprobe_instance *ri, struct pt_regs *regs) @@ -308,15 +319,9 @@ static int dl_reloc_eh(struct uretprobe_instance *ri, struct pt_regs *regs) _handler_reloc.dentry); } -static int dl_reloc_rh(struct uretprobe_instance *ri, struct pt_regs *regs) -{ - return _process_rh(ri, regs, &_redirect_to_reloc_handler, - _handler_reloc.dentry); -} - /* TODO Make ordinary interface. Now real data_size is set in init, because * it is unknown in this module during compile time. */ -static struct probe_desc pin_reloc = MAKE_URPROBE(dl_reloc_eh, dl_reloc_rh, 0); +static struct probe_desc pin_reloc = MAKE_URPROBE(dl_reloc_eh, common_rh, 0); static int pthread_init_eh(struct uretprobe_instance *ri, struct pt_regs *regs) @@ -952,16 +957,18 @@ int gtm_set_handler_path(char *path) if (dentry == NULL) return -EINVAL; - if (_handler_fixup.dentry != NULL || - _handler_reloc.dentry != NULL) { - if (_handler_fixup.dentry != NULL) - swap_put_dentry(_handler_fixup.dentry); - else - swap_put_dentry(_handler_reloc.dentry); - } + if (_handler_fixup.dentry) + swap_put_dentry(_handler_fixup.dentry); + + if (_handler_reloc.dentry) + swap_put_dentry(_handler_reloc.dentry); + + if (_proc_features.dentry) + swap_put_dentry(_proc_features.dentry); _handler_fixup.dentry = dentry; _handler_reloc.dentry = dentry; + _proc_features.dentry = dentry; /* TODO Do smth with this: * make interface for loader to remove handlers @@ -986,6 +993,13 @@ int gtm_set_handler_reloc_off(unsigned long offset) return 0; } +int gtm_set_proc_features_off(unsigned long offset) +{ + _proc_features.off = offset; + + return 0; +} + int gtm_set_pthread_path(char *path) { struct dentry *dentry; diff --git a/got_patcher/gt_module.h b/got_patcher/gt_module.h index a89dbee..7e1b151 100644 --- a/got_patcher/gt_module.h +++ b/got_patcher/gt_module.h @@ -31,6 +31,7 @@ ssize_t gtm_get_targets(char **targets); int gtm_set_handler_path(char *path); int gtm_set_handler_fixup_off(unsigned long offset); int gtm_set_handler_reloc_off(unsigned long offset); +int gtm_set_proc_features_off(unsigned long offset); /* Pthread data */ int gtm_set_pthread_path(char *path); -- 2.7.4 From 18ce8b5ea256e0e2f34cd9c6e5c194df9dbbd7a1 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Thu, 21 Sep 2017 08:20:02 +0300 Subject: [PATCH 09/16] Add model-config to requires (fix install sequence) Change-Id: I5d9b77adaf6d7bc80cd60274af71b0683b662e35 --- packaging/swap-modules.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/swap-modules.spec b/packaging/swap-modules.spec index 1702a9a..f5a4ab0 100755 --- a/packaging/swap-modules.spec +++ b/packaging/swap-modules.spec @@ -7,6 +7,8 @@ Group: System Environment/Kernel Vendor: Samsung Source: swap-modules-3.0.tar.gz +Requires: model-config + BuildRequires: perl BuildRequires: python Provides: swap-modules -- 2.7.4 From ff319ebd51727dd020586d9671aad6c0565673cf Mon Sep 17 00:00:00 2001 From: Vitaliy Cherepanov Date: Wed, 27 Sep 2017 20:08:33 +0300 Subject: [PATCH 10/16] Fix build for i686 arch Change-Id: I63cb3e2e88261dbb957bb030bd89a94c83127e5c Signed-off-by: Vitaliy Cherepanov --- packaging/swap-modules.spec | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packaging/swap-modules.spec b/packaging/swap-modules.spec index f5a4ab0..a7074d8 100755 --- a/packaging/swap-modules.spec +++ b/packaging/swap-modules.spec @@ -29,7 +29,7 @@ BuildRequires: arm64-tm2-linux-kernel-devel # TW2 BuildRequires: kernel-devel-exynos7270-tw2 %else - %ifarch i586 + %ifarch i586 i686 BuildRequires: emulator-kernel-devel %endif %endif @@ -76,8 +76,7 @@ Kernel modules for SWAP ./build.sh --kernel /boot/kernel/devel/kernel-devel-tw2 --arch arm64 compile ./pack.sh /tmp/tw2_swap_modules/ %else - %ifarch i586 -BuildRequires: emulator-kernel-devel + %ifarch i586 i686 ./build.sh --kernel /usr/src/kernel-devel-tizen_emulator --arch i386 clean ./build.sh --kernel /usr/src/kernel-devel-tizen_emulator --arch i386 compile ./pack.sh /tmp/emul_swap_modules/ @@ -97,7 +96,7 @@ mv /tmp/rpi3_swap_modules %{buildroot}/opt/swap/sdk/ mv /tmp/tm2_swap_modules %{buildroot}/opt/swap/sdk/ mv /tmp/tw2_swap_modules %{buildroot}/opt/swap/sdk/ %else - %ifarch i586 + %ifarch i586 i686 mv /tmp/emul_swap_modules %{buildroot}/opt/swap/sdk/ %endif %endif @@ -124,7 +123,7 @@ install -m 770 deploy.sh -t %{buildroot}/opt/swap/sdk /opt/swap/sdk/tm2_swap_modules /opt/swap/sdk/tw2_swap_modules %else - %ifarch i586 + %ifarch i586 i686 /opt/swap/sdk/emul_swap_modules %endif %endif -- 2.7.4 From 561d77c2b6b47ac196d41035f98b5fe236ea5ba2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 3 Oct 2017 10:33:56 +0300 Subject: [PATCH 11/16] wsi: remove feature Change-Id: I9d28a5af96efbdeb40f26cdd22258337e45c39ab Signed-off-by: Vyacheslav Cherkashin --- Kbuild | 1 - pack.sh | 1 - parser/msg_parser.c | 27 ----- us_manager/probes/probes.h | 1 - webprobe/Kbuild | 6 - webprobe/web_msg.c | 137 ---------------------- webprobe/web_msg.h | 35 ------ webprobe/webprobe.c | 275 -------------------------------------------- webprobe/webprobe.h | 40 ------- webprobe/webprobe_debugfs.c | 210 --------------------------------- webprobe/webprobe_debugfs.h | 32 ------ 11 files changed, 765 deletions(-) delete mode 100644 webprobe/Kbuild delete mode 100644 webprobe/web_msg.c delete mode 100644 webprobe/web_msg.h delete mode 100644 webprobe/webprobe.c delete mode 100644 webprobe/webprobe.h delete mode 100644 webprobe/webprobe_debugfs.c delete mode 100644 webprobe/webprobe_debugfs.h diff --git a/Kbuild b/Kbuild index b1a0574..007e021 100644 --- a/Kbuild +++ b/Kbuild @@ -17,7 +17,6 @@ obj-m := master/ \ energy/ \ parser/ \ retprobe/ \ - webprobe/ \ preload/ \ fbiprobe/ \ wsp/ \ diff --git a/pack.sh b/pack.sh index 9bf0875..3186cbc 100755 --- a/pack.sh +++ b/pack.sh @@ -26,7 +26,6 @@ modules="master/swap_master.ko energy/swap_energy.ko parser/swap_message_parser.ko retprobe/swap_retprobe.ko - webprobe/swap_webprobe.ko loader/swap_loader.ko preload/swap_preload.ko uihv/swap_uihv.ko diff --git a/parser/msg_parser.c b/parser/msg_parser.c index d35952d..285da4d 100644 --- a/parser/msg_parser.c +++ b/parser/msg_parser.c @@ -308,25 +308,6 @@ static int cmp_retprobe(struct probe_info *p0, struct probe_info *p1) } /** - * @brief Gets webprobe data and puts it to the probe_info struct. - * - * @param mb Pointer to the message buffer. - * @param pd Pointer to the probe_desc struct. - * @return 0 on success, error code on error. - */ -int get_webprobe(struct msg_buf *mb, struct probe_desc *pd) -{ - pd->type = SWAP_WEBPROBE; - - return 0; -} - -static int cmp_webprobe(struct probe_info *p0, struct probe_info *p1) -{ - return 0; -} - -/** * @brief Gets preload data and puts it to the probe_info struct. * * @param mb Pointer to the message buffer. @@ -656,9 +637,6 @@ struct pr_probe_desc *pr_probe_desc_create(struct msg_buf *mb) case SWAP_RETPROBE: get_probe = get_retprobe; break; - case SWAP_WEBPROBE: - get_probe = get_webprobe; - break; case SWAP_PRELOAD_PROBE: get_probe = get_preload_probe; break; @@ -706,8 +684,6 @@ void pr_probe_desc_free(struct pr_probe_desc *probe) case SWAP_RETPROBE: put_retprobe(&(probe->p_desc.info)); break; - case SWAP_WEBPROBE: - break; case SWAP_PRELOAD_PROBE: put_preload_probe(&(probe->p_desc.info)); break; @@ -745,9 +721,6 @@ int probe_inst_info_cmp(struct pr_probe_desc *p0, struct pr_probe_desc *p1) case SWAP_RETPROBE: cmp_probe = cmp_retprobe; break; - case SWAP_WEBPROBE: - cmp_probe = cmp_webprobe; - break; case SWAP_PRELOAD_PROBE: cmp_probe = cmp_preload_probe; break; diff --git a/us_manager/probes/probes.h b/us_manager/probes/probes.h index f6dec06..8683006 100644 --- a/us_manager/probes/probes.h +++ b/us_manager/probes/probes.h @@ -50,7 +50,6 @@ enum probe_t { SWAP_RETPROBE = 0, /* Retprobe */ SWAP_FBIPROBE = 1, /* FBI probe */ SWAP_PRELOAD_PROBE = 2, /* Preload probe */ - SWAP_WEBPROBE = 3, /* Webprobe */ SWAP_GET_CALLER = 4, /* Get caller probe. Supports preload */ SWAP_GET_CALL_TYPE = 5, /* Get call type probe. Supports preload */ SWAP_WRITE_MSG = 6, /* Write messages from user space directly to diff --git a/webprobe/Kbuild b/webprobe/Kbuild deleted file mode 100644 index fd39693..0000000 --- a/webprobe/Kbuild +++ /dev/null @@ -1,6 +0,0 @@ -EXTRA_CFLAGS := $(extra_cflags) - -obj-m := swap_webprobe.o -swap_webprobe-y := webprobe.o \ - webprobe_debugfs.o \ - web_msg.o diff --git a/webprobe/web_msg.c b/webprobe/web_msg.c deleted file mode 100644 index e94b895..0000000 --- a/webprobe/web_msg.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * Copyright (C) Samsung Electronics, 2015 - * - * 2015 Vyacheslav Cherkashin - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "web_msg.h" - -#define WEB_PREFIX KERN_INFO "[WEB_PROF] " -/* TODO: develop method for obtaining this data during build... */ -#define LINE_NUMBER_OFFSET 16 -#define FUNCTION_NAME_OFFSET 8 -#define SOURCE_FILE_NAME_OFFSET 12 - -static long pack_str_form_user(void *data, size_t size, const char __user *s) -{ - long ret, len; - - if (!size) - return -ENOMEM; - - ret = strncpy_from_user(data, s, size); - if (ret < 0) { - pr_err(WEB_PREFIX "failed to get userspace string s=%p\n", s); - return ret; - - } else if (ret == size) { - pr_warn(WEB_PREFIX "user string is very long ret=%ld\n", ret); - len = ret; - } else { - len = ret + 1; - } - - ((char *)data)[len - 1] = '\0'; - - return len; -} - -void web_sample_msg(struct pt_regs *regs) -{ - struct task_struct *task = current; - struct swap_msg *m; - void *p; - size_t old_size, size; - long ret; - void __user *obj_ptr; - int line; - int __user *line_number_ptr; - const char __user **func_name_ptr; - const char __user *func_name; - const char __user **file_name_ptr; - const char __user *file_name; - - if (!check_event(task)) - return; - - /* Get opbject pointer */ - obj_ptr = (void __user *)swap_get_uarg(regs, 1); - - m = swap_msg_get(MSG_WEB_PROFILING); - p = swap_msg_payload(m); - old_size = size = swap_msg_size(m); - - /* Type */ - *(u8 *)p = WEB_MSG_SAMPLING; - p += sizeof(u8); - size -= sizeof(u8); - - /* PID */ - *(u32 *)p = task->tgid; - p += sizeof(u32); - size -= sizeof(u32); - - /* TID */ - *(u32 *)p = task->pid; - p += sizeof(u32); - size -= sizeof(u32); - - /* Line number (in source file) */ - line_number_ptr = obj_ptr + LINE_NUMBER_OFFSET; - if (get_user(line, line_number_ptr)) { - pr_err("failed to get line number\n"); - goto out; - } - *(u32 *)p = (u32)line; - p += sizeof(u32); - size -= sizeof(u32); - - /* Get function name string pointer */ - func_name_ptr = obj_ptr + FUNCTION_NAME_OFFSET; - if (get_user(func_name, func_name_ptr)) { - pr_err("failed to get function name\n"); - goto out; - } - ret = pack_str_form_user(p, size, func_name); - if (ret < 0) - goto out; - p += ret; - size -= ret; - - /* Get source file name string pointer */ - file_name_ptr = obj_ptr + SOURCE_FILE_NAME_OFFSET; - if (get_user(file_name, file_name_ptr)) { - pr_err("failed to get file name\n"); - goto out; - } - ret = pack_str_form_user(p, size, file_name); - if (ret < 0) - goto out; - size -= ret; - - swap_msg_flush(m, old_size - size); - -out: - swap_msg_put(m); -} diff --git a/webprobe/web_msg.h b/webprobe/web_msg.h deleted file mode 100644 index 9170854..0000000 --- a/webprobe/web_msg.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * Copyright (C) Samsung Electronics, 2015 - * - * 2015 Vyacheslav Cherkashin - * - */ - -#ifndef _WEB_MSG_H -#define _WEB_MSG_H - -struct pt_regs; - -/* Web messages subtype */ -enum web_msg_type { - WEB_MSG_SAMPLING = 0x00, -}; - -void web_msg_entry(struct pt_regs *regs); -void web_msg_exit(struct pt_regs *regs); -void web_sample_msg(struct pt_regs *regs); - -#endif /* _WEB_MSG_H */ diff --git a/webprobe/webprobe.c b/webprobe/webprobe.c deleted file mode 100644 index c88dbf6..0000000 --- a/webprobe/webprobe.c +++ /dev/null @@ -1,275 +0,0 @@ -/** - * webprobe/webprobe.c - * @author Ruslan Soloviev - * - * @section LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * @section COPYRIGHT - * - * Copyright (C) Samsung Electronics, 2014 - * - * @section DESCRIPTION - * - * Web application profiling - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "webprobe.h" -#include "webprobe_debugfs.h" -#include "web_msg.h" - -struct web_prof_data { - struct dentry *app_dentry; - struct dentry *lib_dentry; - struct pf_group *pfg; - u64 inspserver_addr; - u64 tick_addr; - - struct probe_new inspserver_probe; - struct probe_new tick_probe; - - bool enable; -}; - -static DEFINE_MUTEX(web_mutex); -static const char *CHROMIUM_EWK = "/usr/lib/libchromium-ewk.so"; -static struct web_prof_data *web_data; - -/* function tick handler */ -static int tick_handler(struct uprobe *p, struct pt_regs *regs); -static struct probe_desc pin_tick_handler = MAKE_UPROBE(tick_handler); - -/* function inspector port */ -static int insport_rhandler(struct uretprobe_instance *ri, - struct pt_regs *regs); -static struct probe_desc pin_insport_rhandler = - MAKE_URPROBE(NULL, insport_rhandler, 0); - -static int insport_rhandler(struct uretprobe_instance *ri, - struct pt_regs *regs) -{ - set_wrt_launcher_port((int)regs_return_value(regs)); - - return 0; -} - -static int tick_handler(struct uprobe *p, struct pt_regs *regs) -{ - web_sample_msg(regs); - - return 0; -} - -u64 *web_prof_addr_ptr(enum web_prof_addr_t type) -{ - u64 *addr_ptr; - - mutex_lock(&web_mutex); - switch (type) { - case INSPSERVER_START: - addr_ptr = &web_data->inspserver_addr; - break; - case TICK_PROBE: - addr_ptr = &web_data->tick_addr; - break; - default: - pr_err("ERROR: WEB_PROF_ADDR_PTR_TYPE=0x%x\n", type); - addr_ptr = NULL; - } - mutex_unlock(&web_mutex); - - return addr_ptr; -} - -int web_prof_data_set(char *app_path, char *app_id) -{ - int ret = 0; - - mutex_lock(&web_mutex); - web_data->app_dentry = dentry_by_path(app_path); - if (!web_data->app_dentry) { - ret = -EFAULT; - goto out; - } - - web_data->lib_dentry = dentry_by_path(CHROMIUM_EWK); - if (!web_data->lib_dentry) { - ret = -EFAULT; - goto out; - } - - if (web_data->pfg) { - put_pf_group(web_data->pfg); - web_data->pfg = NULL; - } - - web_data->pfg = get_pf_group_by_comm(app_id, web_data->app_dentry); - if (!web_data->pfg) { - ret = -EFAULT; - goto out; - } - -out: - mutex_unlock(&web_mutex); - - return 0; -} - -bool web_prof_enabled(void) -{ - bool ret; - - mutex_lock(&web_mutex); - ret = web_data->enable; - mutex_unlock(&web_mutex); - - return ret; -} - -static void __web_prof_disable(struct web_prof_data *data) -{ - pin_unregister(&data->tick_probe, data->pfg); - pin_unregister(&data->inspserver_probe, data->pfg); -} - -static int __web_prof_enable(struct web_prof_data *data) -{ - int ret; - - data->tick_probe.offset = (unsigned long)data->tick_addr; - data->tick_probe.desc = &pin_tick_handler; - ret = pin_register(&data->tick_probe, data->pfg, data->lib_dentry); - if (ret) - goto fail0; - - data->inspserver_probe.offset = (unsigned long)data->inspserver_addr; - data->inspserver_probe.desc = &pin_insport_rhandler; - ret = pin_register(&data->inspserver_probe, data->pfg, - data->lib_dentry); - if (ret) - goto fail1; - - return 0; - -fail1: - pin_unregister(&data->tick_probe, data->pfg); -fail0: - return ret; -} - -int web_prof_enable(void) -{ - int ret = 0; - - mutex_lock(&web_mutex); - if (web_data->enable) { - pr_err("ERROR: Web profiling is already enabled\n"); - ret = -EBUSY; - goto out; - } - - if (!web_data->inspserver_addr) { - pr_err("bad inspserver addr 0x%llx\n", - web_data->inspserver_addr); - goto out; - } - - if (!web_data->tick_addr) { - pr_err("bad tick addr 0x%llx\n", web_data->tick_addr); - goto out; - } - - ret = __web_prof_enable(web_data); - if (ret) { - pr_err("failed to enable Web profiling\n"); - goto out; - } - - web_data->enable = true; - -out: - mutex_unlock(&web_mutex); - - return ret; -} - -int web_prof_disable(void) -{ - int ret = 0; - - mutex_lock(&web_mutex); - if (!web_data->enable) { - pr_err("ERROR: Web profiling is already disabled\n"); - ret = -EBUSY; - goto out; - } - - __web_prof_disable(web_data); - if (web_data->pfg) { - put_pf_group(web_data->pfg); - web_data->pfg = NULL; - } - web_data->enable = false; - -out: - mutex_unlock(&web_mutex); - return ret; -} - -static int webprobe_module_init(void) -{ - mutex_lock(&web_mutex); - web_data = kzalloc(sizeof(*web_data), GFP_KERNEL); - if (!web_data) - return -ENOMEM; - - web_data->enable = false; - mutex_unlock(&web_mutex); - - return 0; -} - -static void webprobe_module_exit(void) -{ - mutex_lock(&web_mutex); - if (web_data->enable) - __web_prof_disable(web_data); - - if (web_data->pfg) { - put_pf_group(web_data->pfg); - web_data->pfg = NULL; - } - - kfree(web_data); - web_data = NULL; - mutex_unlock(&web_mutex); -} - -SWAP_LIGHT_INIT_MODULE(NULL, webprobe_module_init, webprobe_module_exit, - webprobe_debugfs_init, webprobe_debugfs_exit); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("SWAP webprobe"); -MODULE_AUTHOR("Ruslan Soloviev " - "Anastasia Lyupa "); diff --git a/webprobe/webprobe.h b/webprobe/webprobe.h deleted file mode 100644 index 003931e..0000000 --- a/webprobe/webprobe.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _WEBPROBE_H -#define _WEBPROBE_H - -/** - * @file webprobe/webprobe_prof.h - * @author Anastasia Lyupa - * - * @section LICENSE - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * @section COPYRIGHT - * Copyright (C) Samsung Electronics, 2015 - * - * @section DESCRIPTION - * Profiling for webprobe - */ - -enum web_prof_addr_t { - INSPSERVER_START = 1, - TICK_PROBE -}; - -int web_prof_enable(void); -int web_prof_disable(void); -bool web_prof_enabled(void); -u64 *web_prof_addr_ptr(enum web_prof_addr_t type); -int web_prof_data_set(char *app_path, char *app_id); - -#endif /* _WEBPROBE_H */ diff --git a/webprobe/webprobe_debugfs.c b/webprobe/webprobe_debugfs.c deleted file mode 100644 index e93dd95..0000000 --- a/webprobe/webprobe_debugfs.c +++ /dev/null @@ -1,210 +0,0 @@ -/** - * webprobe/webprobe_debugfs.c - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * Copyright (C) Samsung Electronics, 2015 - * - * 2015 Anastasia Lyupa - * - */ - -#include -#include -#include -#include - -#include -#include - -#include "webprobe_debugfs.h" -#include "webprobe.h" - -static const char ENABLED_FILE[] = "enabled"; -static const char APP_INFO_FILE[] = "app_info"; -static const char INSPSERVER_START_FILE[] = "inspector_server_start"; -static const char TICK_PROBE_FILE[] = "tick_probe"; - -enum { max_count = 256 }; -static char app_info[max_count]; - -/* ============================================================================ - * === DEBUGFS FOR WEBPROBE INSTRUMENTATION === - * ============================================================================ - */ - -static ssize_t read_enabled(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) -{ - char buf[2]; - - buf[0] = web_prof_enabled() ? '1' : '0'; - buf[1] = '\n'; - - return simple_read_from_buffer(user_buf, count, ppos, buf, 2); -} - -static ssize_t write_enabled(struct file *file, const char __user *user_buf, - size_t count, loff_t *ppos) -{ - int ret = 0; - char buf[32]; - size_t buf_size; - - buf_size = min(count, (sizeof(buf) - 1)); - if (copy_from_user(buf, user_buf, buf_size)) - return -EFAULT; - - buf[buf_size] = '\0'; - switch (buf[0]) { - case '1': - ret = web_prof_enable(); - break; - case '0': - ret = web_prof_disable(); - break; - default: - return -EINVAL; - } - - if (ret) - return ret; - - return count; -} - -static const struct file_operations fops_enabled = { - .write = write_enabled, - .read = read_enabled, - .open = swap_init_simple_open, - .release = swap_init_simple_release, -}; - -static ssize_t write_app_info(struct file *file, const char __user *user_buf, - size_t count, loff_t *ppos) -{ - int ret = 0; - char *buf, *path, *id; - int n; - - if (count > max_count) - return -ENOMEM; - - buf = kmalloc(count + 1, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - if (copy_from_user(buf, user_buf, count)) { - ret = -EFAULT; - goto free_buf; - } - - buf[count] = '\0'; - - path = kmalloc(count, GFP_KERNEL); - if (!path) { - ret = -ENOMEM; - goto free_buf; - } - - id = kmalloc(count, GFP_KERNEL); - if (!id) { - ret = -ENOMEM; - goto free_path; - } - - n = sscanf(buf, "%s %s", path, id); - - if (n != 2) { - ret = -EINVAL; - goto free_app_info; - } - - web_prof_data_set(path, id); - snprintf(app_info, sizeof(app_info), "%s\n", buf); - -free_app_info: - kfree(id); -free_path: - kfree(path); -free_buf: - kfree(buf); - - return ret ? ret : count; -} - -static ssize_t read_app_info(struct file *file, char __user *userbuf, - size_t count, loff_t *ppos) -{ - return simple_read_from_buffer(userbuf, count, ppos, app_info, - sizeof(app_info) - 1); -} - -static const struct file_operations fops_app_info = { - .write = write_app_info, - .read = read_app_info, - .open = swap_init_simple_open, - .release = swap_init_simple_release, -}; - -/* ============================================================================ - * === INIT/EXIT === - * ============================================================================ - */ - -static struct dentry *webprobe_dir; - -void webprobe_debugfs_exit(void) -{ - debugfs_remove_recursive(webprobe_dir); - webprobe_dir = NULL; -} - -int webprobe_debugfs_init(void) -{ - struct dentry *dentry; - - dentry = swap_debugfs_getdir(); - if (!dentry) - return -ENOENT; - - webprobe_dir = swap_debugfs_create_dir("webprobe", dentry); - if (!webprobe_dir) - return -ENOMEM; - - dentry = swap_debugfs_create_file(ENABLED_FILE, 0600, webprobe_dir, - NULL, &fops_enabled); - - dentry = swap_debugfs_create_file(APP_INFO_FILE, 0600, webprobe_dir, - NULL, &fops_app_info); - if (!dentry) - goto fail; - - dentry = swap_debugfs_create_x64(INSPSERVER_START_FILE, 0600, - webprobe_dir, - web_prof_addr_ptr(INSPSERVER_START)); - if (!dentry) - goto fail; - - dentry = swap_debugfs_create_x64(TICK_PROBE_FILE, 0600, webprobe_dir, - web_prof_addr_ptr(TICK_PROBE)); - if (!dentry) - goto fail; - - return 0; - -fail: - webprobe_debugfs_exit(); - return -ENOMEM; -} diff --git a/webprobe/webprobe_debugfs.h b/webprobe/webprobe_debugfs.h deleted file mode 100644 index e6a8544..0000000 --- a/webprobe/webprobe_debugfs.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _WEBPROBE_DEBUGFS_H -#define _WEBPROBE_DEBUGFS_H - -/** - * @file webprobe/webprobe_debugfs.h - * @author Anastasia Lyupa - * - * @section LICENSE - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - * - * @section COPYRIGHT - * Copyright (C) Samsung Electronics, 2015 - * - * @section DESCRIPTION - * Debugfs for webprobe - */ - -int webprobe_debugfs_init(void); -void webprobe_debugfs_exit(void); - -#endif /* _WEBPROBE_DEBUGFS_H */ -- 2.7.4 From 845c4492c6045c0397f8f6bdc1f590a3aea8cec9 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Tue, 10 Oct 2017 10:10:50 +0300 Subject: [PATCH 12/16] Disable build for non-emulator i586 target Change-Id: I3b9a3000e3755c304a4119b0ad877bbcd5b8b78f --- packaging/swap-modules.spec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packaging/swap-modules.spec b/packaging/swap-modules.spec index a7074d8..aee4509 100755 --- a/packaging/swap-modules.spec +++ b/packaging/swap-modules.spec @@ -1,3 +1,5 @@ +%bcond_with emulator + Name: swap-modules Version: 3.0 Release: 1 @@ -30,7 +32,11 @@ BuildRequires: arm64-tm2-linux-kernel-devel BuildRequires: kernel-devel-exynos7270-tw2 %else %ifarch i586 i686 + %if %{with emulator} BuildRequires: emulator-kernel-devel + %else +ExclusiveArch: + %endif %endif %endif %endif -- 2.7.4 From ec756cfd43e5dd782857c96ac60b521d584da048 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Tue, 10 Oct 2017 10:58:27 +0300 Subject: [PATCH 13/16] Not build unsupported targets Change-Id: I9b8f895c30751671c879bab0fad8263779e1f27d Signed-off-by: Dmitry Kovalenko --- packaging/swap-modules.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/swap-modules.spec b/packaging/swap-modules.spec index aee4509..aecca2f 100755 --- a/packaging/swap-modules.spec +++ b/packaging/swap-modules.spec @@ -37,6 +37,8 @@ BuildRequires: emulator-kernel-devel %else ExclusiveArch: %endif + %else +ExclusiveArch: %endif %endif %endif -- 2.7.4 From 9e54980c416353ea9e0dcdb61ed3db2d6c985dd2 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Fri, 13 Oct 2017 12:36:58 +0300 Subject: [PATCH 14/16] Fix issues found by static analysis tool decode_thumb.c: Out-of-bounds access probes_arm.c: Out-of-bounds access swap_kprobes.c: Resource leak Change-Id: I54c92029f5adb83b8d4f8f29cc4e683d6545ab6c Signed-off-by: Dmitry Kovalenko --- arch/arm/probes/decode_thumb.c | 5 +++-- arch/arm/probes/probes_arm.c | 12 ++++++------ kprobe/swap_kprobes.c | 4 +++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm/probes/decode_thumb.c b/arch/arm/probes/decode_thumb.c index 71f5da5..a35f262 100644 --- a/arch/arm/probes/decode_thumb.c +++ b/arch/arm/probes/decode_thumb.c @@ -68,7 +68,7 @@ static void make_def(void *tramp, u32 insn, u32 vaddr, bool t2) static void tt_make_common(void *tramp, u32 insn, u32 vaddr, bool t2) { - memcpy(tramp, gen_insn_execbuf_thumb, 4 * PROBES_TRAMP_LEN); + memcpy(tramp, gen_insn_execbuf_thumb, sizeof(gen_insn_execbuf_thumb)); make_def(tramp, insn, vaddr, t2); } @@ -77,7 +77,8 @@ static void tt_make_pc_deps(void *tramp, u32 mod_insn, u32 vaddr, bool t2) u32 pc_val = vaddr + 4; u16 *tr = tramp; - memcpy(tramp, pc_dep_insn_execbuf_thumb, 4 * PROBES_TRAMP_LEN); + memcpy(tramp, pc_dep_insn_execbuf_thumb, + sizeof(pc_dep_insn_execbuf_thumb)); make_def(tramp, mod_insn, vaddr, t2); /* save PC value */ diff --git a/arch/arm/probes/probes_arm.c b/arch/arm/probes/probes_arm.c index 9e27870..114eeb4 100644 --- a/arch/arm/probes/probes_arm.c +++ b/arch/arm/probes/probes_arm.c @@ -140,7 +140,7 @@ static int make_branch_tarmpoline(u32 addr, u32 insn, u32 *tramp) if (ARM_INSN_MATCH(B, insn) && !ARM_INSN_MATCH(BLX1, insn)) { /* B check can be false positive on BLX1 instruction */ - memcpy(tramp, b_cond_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, b_cond_insn_execbuf, sizeof(b_cond_insn_execbuf)); tramp[PROBES_TRAMP_RET_BREAK_IDX] = RET_BREAK_ARM; tramp[0] |= insn & 0xf0000000; tramp[6] = get_addr_b(insn, addr); @@ -149,14 +149,14 @@ static int make_branch_tarmpoline(u32 addr, u32 insn, u32 *tramp) /* BX, BLX (Rm) */ } else if (ARM_INSN_MATCH(BX, insn) || ARM_INSN_MATCH(BLX2, insn)) { - memcpy(tramp, b_r_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, b_r_insn_execbuf, sizeof(b_r_insn_execbuf)); tramp[0] = insn; tramp[PROBES_TRAMP_RET_BREAK_IDX] = RET_BREAK_ARM; tramp[7] = addr + 4; ok = 1; /* BL, BLX (Off) */ } else if (ARM_INSN_MATCH(BLX1, insn)) { - memcpy(tramp, blx_off_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, blx_off_insn_execbuf, sizeof(blx_off_insn_execbuf)); tramp[0] |= 0xe0000000; tramp[1] |= 0xe0000000; tramp[PROBES_TRAMP_RET_BREAK_IDX] = RET_BREAK_ARM; @@ -166,7 +166,7 @@ static int make_branch_tarmpoline(u32 addr, u32 insn, u32 *tramp) ok = 1; /* BL */ } else if (ARM_INSN_MATCH(BL, insn)) { - memcpy(tramp, blx_off_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, blx_off_insn_execbuf, sizeof(blx_off_insn_execbuf)); tramp[0] |= insn & 0xf0000000; tramp[1] |= insn & 0xf0000000; tramp[PROBES_TRAMP_RET_BREAK_IDX] = RET_BREAK_ARM; @@ -251,7 +251,7 @@ int make_trampoline_arm(u32 addr, u32 insn, u32 *tramp) } if (unlikely(uregs && pc_dep)) { - memcpy(tramp, pc_dep_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, pc_dep_insn_execbuf, sizeof(pc_dep_insn_execbuf)); if (prep_pc_dep_insn_execbuf(tramp, insn, uregs) != 0) { pr_err("Error in %s at %d: failed " "to prepare exec buffer for insn %x!", @@ -261,7 +261,7 @@ int make_trampoline_arm(u32 addr, u32 insn, u32 *tramp) tramp[6] = addr + 8; } else { - memcpy(tramp, gen_insn_execbuf, PROBES_TRAMP_LEN); + memcpy(tramp, gen_insn_execbuf, sizeof(gen_insn_execbuf)); tramp[PROBES_TRAMP_INSN_IDX] = insn; } diff --git a/kprobe/swap_kprobes.c b/kprobe/swap_kprobes.c index 5fe9474..3981ffe 100644 --- a/kprobe/swap_kprobes.c +++ b/kprobe/swap_kprobes.c @@ -543,8 +543,10 @@ int swap_register_kprobe(struct kprobe *p) } ret = arch_kp_core_prepare(core, &sm); - if (ret) + if (ret) { + kp_core_free(core); goto unlock; + } ret = kp_core_add_kprobe(core, p); if (ret) { -- 2.7.4 From 202877cf2d9c870b325b3412f55fe75d3aab4a4e Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Mon, 16 Oct 2017 16:58:56 +0300 Subject: [PATCH 15/16] Fix build for ARM targets Change-Id: I8412bf8be7ebd648feb0683ea0aa2c8c99bdf491 Signed-off-by: Dmitry Kovalenko --- arch/arm/probes/tramps_arm.h | 66 +++++++++++++-- arch/arm/probes/tramps_arm_img.c | 86 ------------------- arch/arm/probes/tramps_thumb.h | 139 +++++++++++++++++++++++++++++-- arch/arm/probes/tramps_thumb_img.c | 165 ------------------------------------- kprobe/Kbuild | 3 +- uprobe/Kbuild | 3 - 6 files changed, 195 insertions(+), 267 deletions(-) delete mode 100644 arch/arm/probes/tramps_arm_img.c delete mode 100644 arch/arm/probes/tramps_thumb_img.c diff --git a/arch/arm/probes/tramps_arm.h b/arch/arm/probes/tramps_arm.h index 27f0a35..0fc5d72 100644 --- a/arch/arm/probes/tramps_arm.h +++ b/arch/arm/probes/tramps_arm.h @@ -37,11 +37,67 @@ #include -extern u32 gen_insn_execbuf[]; -extern u32 pc_dep_insn_execbuf[]; -extern u32 b_r_insn_execbuf[]; -extern u32 b_cond_insn_execbuf[]; -extern u32 blx_off_insn_execbuf[]; +/* + * These arrays generated from tramps_arm.c + * using 32 bit compiler: + * $ gcc tramps_arm.c -c -o tramps_arm.o + * $ objdump -d tramps_arm.o + */ + +static u32 __attribute__((unused)) gen_insn_execbuf[] = { + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe59ff004, // ldr pc, [pc, #4] + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop +}; + +static u32 __attribute__((unused)) pc_dep_insn_execbuf[] = { + 0xe50d0004, // str r0, [sp, #-4] + 0xe59f000c, // ldr r0, [pc, #12] + 0xe320f000, // nop + 0xe51d0004, // ldr r0, [sp, #-4] + 0xe59ff004, // ldr pc, [pc, #4] + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop +}; + +static u32 __attribute__((unused)) b_r_insn_execbuf[] = { + 0xe320f000, // nop + 0xe59ff010, // ldr pc, [pc, #16] + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop +}; + +static u32 __attribute__((unused)) b_cond_insn_execbuf[] = { + 0x0a000000, // beq 68 + 0xe59ff010, // ldr pc, [pc, #16] + 0xe59ff008, // ldr pc, [pc, #8] + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop +}; + +static u32 __attribute__((unused)) blx_off_insn_execbuf[] = { + 0x059fe010, // ldreq lr, [pc, #16] + 0x012fff3e, // blxeq lr + 0xe59ff00c, // ldr pc, [pc, #12] + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop + 0xe320f000, // nop +}; #endif /* _SWAP_ASM_TRAMPS_ARM_H */ diff --git a/arch/arm/probes/tramps_arm_img.c b/arch/arm/probes/tramps_arm_img.c deleted file mode 100644 index 22f4fac..0000000 --- a/arch/arm/probes/tramps_arm_img.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Copyright (C) Samsung Electronics, 2016 - * - * 2016 Vyacheslav Cherkashin - * - */ - - -#include "tramps_arm.h" - - -/* - * These arrays generated from tramps_arm.c - * using 32 bit compiler: - * $ gcc tramps_arm.c -c -o tramps_arm.o - * $ objdump -d tramps_arm.o - */ - -u32 gen_insn_execbuf[] = { - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe59ff004, // ldr pc, [pc, #4] - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop -}; - -u32 pc_dep_insn_execbuf[] = { - 0xe50d0004, // str r0, [sp, #-4] - 0xe59f000c, // ldr r0, [pc, #12] - 0xe320f000, // nop - 0xe51d0004, // ldr r0, [sp, #-4] - 0xe59ff004, // ldr pc, [pc, #4] - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop -}; - -u32 b_r_insn_execbuf[] = { - 0xe320f000, // nop - 0xe59ff010, // ldr pc, [pc, #16] - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop -}; - -u32 b_cond_insn_execbuf[] = { - 0x0a000000, // beq 68 - 0xe59ff010, // ldr pc, [pc, #16] - 0xe59ff008, // ldr pc, [pc, #8] - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop -}; - -u32 blx_off_insn_execbuf[] = { - 0x059fe010, // ldreq lr, [pc, #16] - 0x012fff3e, // blxeq lr - 0xe59ff00c, // ldr pc, [pc, #12] - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop - 0xe320f000, // nop -}; diff --git a/arch/arm/probes/tramps_thumb.h b/arch/arm/probes/tramps_thumb.h index 4524530..eb34275 100644 --- a/arch/arm/probes/tramps_thumb.h +++ b/arch/arm/probes/tramps_thumb.h @@ -34,12 +34,139 @@ #include -extern u16 gen_insn_execbuf_thumb[]; -extern u16 pc_dep_insn_execbuf_thumb[]; -extern u16 b_r_insn_execbuf_thumb[]; -extern u16 b_off_insn_execbuf_thumb[]; -extern u16 b_cond_insn_execbuf_thumb[]; -extern u16 cbz_insn_execbuf_thumb[]; +/* + * These arrays generated from tramps_thumb.c + * using 32 bit compiler: + * $ gcc tramps_thumb.c -c -o tramps_thumb.o + * $ objdump -d tramps_thumb.o + */ + +static u16 __attribute__((unused)) gen_insn_execbuf_thumb[] = { + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xb082, // sub sp, #8 + 0x9000, // str r0, [sp, #0] + 0x4803, // ldr r0, [pc, #12] + 0x9001, // str r0, [sp, #4] + 0xbf00, // nop + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; + +static u16 __attribute__((unused)) pc_dep_insn_execbuf_thumb[] = { + 0xb4c0, // push {r6, r7} + 0x4e06, // ldr r6, [pc, #24] + 0x466f, // mov r7, sp + 0x46b5, // mov sp, r6 + 0xbf00, // nop + 0xbf00, // nop + 0x46bd, // mov sp, r7 + 0xbcc0, // pop {r6, r7} + 0xb403, // push {r0, r1} + 0x4803, // ldr r0, [pc, #12] + 0xbf00, // nop + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; + +static u16 __attribute__((unused)) b_r_insn_execbuf_thumb[] = { + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xb403, // push {r0, r1} + 0x4804, // ldr r0, [pc, #16] + 0xbf00, // nop + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; + +static u16 __attribute__((unused)) b_off_insn_execbuf_thumb[] = { + 0xb403, // push {r0, r1} + 0x4806, // ldr r0, [pc, #24] + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xb403, // push {r0, r1} + 0x4804, // ldr r0, [pc, #16] + 0xbf00, // nop + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; + +static u16 __attribute__((unused)) b_cond_insn_execbuf_thumb[] = { + 0xf000, 0x8005, // beq.w ce + 0xb403, // push {r0, r1} + 0x4807, // ldr r0, [pc, #28] + 0xbf00, // nop + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xb403, // push {r0, r1} + 0xf8df, 0x000c, // ldr.w r0, [pc, #12] + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; + +static u16 __attribute__((unused)) cbz_insn_execbuf_thumb[] = { + 0xbf00, // nop + 0xb403, // push {r0, r1} + 0x4806, // ldr r0, [pc, #24] + 0xbf00, // nop + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xb403, // push {r0, r1} + 0x4803, // ldr r0, [pc, #12] + 0x9001, // str r0, [sp, #4] + 0xbd01, // pop {r0, pc} + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop + 0xbf00, // nop +}; #endif /* _SWAP_ASM_TRAMPS_THUMB_H */ diff --git a/arch/arm/probes/tramps_thumb_img.c b/arch/arm/probes/tramps_thumb_img.c deleted file mode 100644 index 27fe7e8..0000000 --- a/arch/arm/probes/tramps_thumb_img.c +++ /dev/null @@ -1,165 +0,0 @@ -/** - * @author Alexey Gerenkov User-Space Probes initial - * implementation; Support x86/ARM/MIPS for both user and kernel spaces. - * @author Ekaterina Gorelkina : redesign module for - * separating core and arch parts - * - * @section LICENSE - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * @section COPYRIGHT - * - * Copyright (C) Samsung Electronics, 2006-2016 - * - */ - - -#include "tramps_thumb.h" - - -/* - * These arrays generated from tramps_thumb.c - * using 32 bit compiler: - * $ gcc tramps_thumb.c -c -o tramps_thumb.o - * $ objdump -d tramps_thumb.o - */ - -u16 gen_insn_execbuf_thumb[] = { - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xb082, // sub sp, #8 - 0x9000, // str r0, [sp, #0] - 0x4803, // ldr r0, [pc, #12] - 0x9001, // str r0, [sp, #4] - 0xbf00, // nop - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; - -u16 pc_dep_insn_execbuf_thumb[] = { - 0xb4c0, // push {r6, r7} - 0x4e06, // ldr r6, [pc, #24] - 0x466f, // mov r7, sp - 0x46b5, // mov sp, r6 - 0xbf00, // nop - 0xbf00, // nop - 0x46bd, // mov sp, r7 - 0xbcc0, // pop {r6, r7} - 0xb403, // push {r0, r1} - 0x4803, // ldr r0, [pc, #12] - 0xbf00, // nop - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; - -u16 b_r_insn_execbuf_thumb[] = { - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xb403, // push {r0, r1} - 0x4804, // ldr r0, [pc, #16] - 0xbf00, // nop - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; - -u16 b_off_insn_execbuf_thumb[] = { - 0xb403, // push {r0, r1} - 0x4806, // ldr r0, [pc, #24] - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xb403, // push {r0, r1} - 0x4804, // ldr r0, [pc, #16] - 0xbf00, // nop - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; - -u16 b_cond_insn_execbuf_thumb[] = { - 0xf000, 0x8005, // beq.w ce - 0xb403, // push {r0, r1} - 0x4807, // ldr r0, [pc, #28] - 0xbf00, // nop - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xb403, // push {r0, r1} - 0xf8df, 0x000c, // ldr.w r0, [pc, #12] - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; - -u16 cbz_insn_execbuf_thumb[] = { - 0xbf00, // nop - 0xb403, // push {r0, r1} - 0x4806, // ldr r0, [pc, #24] - 0xbf00, // nop - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xb403, // push {r0, r1} - 0x4803, // ldr r0, [pc, #12] - 0x9001, // str r0, [sp, #4] - 0xbd01, // pop {r0, pc} - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop - 0xbf00, // nop -}; diff --git a/kprobe/Kbuild b/kprobe/Kbuild index adc6cac..e6d12ca 100644 --- a/kprobe/Kbuild +++ b/kprobe/Kbuild @@ -25,8 +25,7 @@ swap_kprobe-y += swap_kprobes.o ### ARM swap_kprobe-$(CONFIG_ARM) += \ arch/arm/swap-asm/swap_kprobes.o \ - ../arch/arm/probes/probes_arm.o \ - ../arch/arm/probes/tramps_arm_img.o + ../arch/arm/probes/probes_arm.o ifeq ($(CONFIG_STRICT_MEMORY_RWX), y) swap_kprobe-$(CONFIG_ARM) += arch/arm/swap-asm/memory_rwx.o diff --git a/uprobe/Kbuild b/uprobe/Kbuild index 94f0b7e..ad4d051 100644 --- a/uprobe/Kbuild +++ b/uprobe/Kbuild @@ -9,7 +9,6 @@ swap_uprobe-$(CONFIG_ARM) += \ arch/arm/swap-asm/swap_uprobes.o \ ../arch/arm/probes/probes_thumb.o \ ../arch/arm/probes/decode_thumb.o \ - ../arch/arm/probes/tramps_thumb_img.o \ ../arch/arm/probes/probes.o \ ../arch/arm/uprobe/swap_uprobe.o @@ -19,10 +18,8 @@ swap_uprobe-$(CONFIG_ARM64) += \ arch/arm64/swap-asm/swap_uprobes.o \ arch/arm64/swap-asm/uprobes-arm64.o \ ../arch/arm/probes/probes_arm.o \ - ../arch/arm/probes/tramps_arm_img.o \ ../arch/arm/probes/decode_thumb.o \ ../arch/arm/probes/probes_thumb.o \ - ../arch/arm/probes/tramps_thumb_img.o \ ../arch/arm/probes/probes.o \ ../arch/arm/uprobe/swap_uprobe.o -- 2.7.4 From 205d9d68cb9d3627d5497d0d5c1a5281fe36f7d7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Mon, 16 Oct 2017 17:09:04 +0300 Subject: [PATCH 16/16] ARM: use swap_access_process_vm() for user memory access Change-Id: I93b31067a58d538de30d9e37d4e3406b2b74ac17 Signed-off-by: Vyacheslav Cherkashin --- kprobe/swap_kprobes_deps.c | 7 ++++--- kprobe/swap_kprobes_deps.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kprobe/swap_kprobes_deps.c b/kprobe/swap_kprobes_deps.c index 2e2694a..9a54bb8 100644 --- a/kprobe/swap_kprobes_deps.c +++ b/kprobe/swap_kprobes_deps.c @@ -453,7 +453,7 @@ int init_module_dependencies(void) } -#ifdef CONFIG_ARM64 +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) static int do_access_process_vm(struct task_struct *tsk, struct mm_struct *mm, unsigned long addr, void *buf, int len, @@ -537,7 +537,7 @@ int swap_access_process_vm(struct task_struct *tsk, unsigned long addr, } EXPORT_SYMBOL_GPL(swap_access_process_vm); -#else /* CONFIG_ARM64 */ +#else /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */ #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38) /* FIXME: must be < 32 */ #define GUP_FLAGS_WRITE 0x1 @@ -1364,6 +1364,7 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, /* FIXME: danger: write memory in atomic context */ atomic = in_atomic(); + WARN_ON(atomic); /* ignore errors, just check how much was successfully transferred */ while (len) { @@ -1421,7 +1422,7 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, } EXPORT_SYMBOL_GPL(access_process_vm_atomic); -#endif /* CONFIG_ARM64 */ +#endif /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */ /** * @brief Page present. diff --git a/kprobe/swap_kprobes_deps.h b/kprobe/swap_kprobes_deps.h index e40d39e..8d4f345 100644 --- a/kprobe/swap_kprobes_deps.h +++ b/kprobe/swap_kprobes_deps.h @@ -135,7 +135,7 @@ do { \ int init_module_dependencies(void); -#ifdef CONFIG_ARM64 +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) int swap_access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); @@ -145,7 +145,7 @@ int swap_access_process_vm(struct task_struct *tsk, unsigned long addr, # define write_proc_vm_atomic(tsk, addr, buf, len) \ swap_access_process_vm(tsk, addr, buf, len, 1) -#else /* CONFIG_ARM64 */ +#else /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); @@ -155,7 +155,7 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, # define write_proc_vm_atomic(tsk, addr, buf, len) \ access_process_vm_atomic(tsk, addr, buf, len, 1) -#endif /* CONFIG_ARM64 */ +#endif /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */ int page_present(struct mm_struct *mm, unsigned long addr); -- 2.7.4