From patchwork Thu Jan 14 17:23:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 8034701 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7FCC4BEEE5 for ; Thu, 14 Jan 2016 17:36:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B20820439 for ; Thu, 14 Jan 2016 17:36:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 682212044B for ; Thu, 14 Jan 2016 17:36:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJlnG-0004qL-H2; Thu, 14 Jan 2016 17:34:42 +0000 Received: from mail-bl2on0095.outbound.protection.outlook.com ([65.55.169.95] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJlfM-00056C-9l for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2016 17:26:40 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (95.143.213.121) by DM2PR07MB624.namprd07.prod.outlook.com (10.141.177.154) with Microsoft SMTP Server (TLS) id 15.1.361.13; Thu, 14 Jan 2016 17:26:08 +0000 From: Yury Norov To: , , , Subject: [PATCH v6 12/21] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32 Date: Thu, 14 Jan 2016 20:23:09 +0300 Message-ID: <1452792198-10718-13-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452792198-10718-1-git-send-email-ynorov@caviumnetworks.com> References: <1452792198-10718-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: DB5PR02CA0001.eurprd02.prod.outlook.com (25.161.237.11) To DM2PR07MB624.namprd07.prod.outlook.com (10.141.177.154) X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB624; 2:eSkPz9gEMzhjEYHijtvWaf+APsryyoo23ciGWvXSWttPwo8/l1kCshfl8qhJ7JR9ocBslcruWE1QIGkWTsuyBLgTTGgv5tr8YxWBONbIx0j2SMPrmhj1g1KamjzK88dm898hv8dka5MT56j7S6nxVw==; 3:/WF+eankFHZU4qmXfOJmcTn7TImCABqv5nv8l17kDoQ5ENMMTEfLvRdI9avtdm1rVM+7l6AYj5nkyKoB5uPk8ZHA1J062niKCcXP1GfHAoKmdYZHMRvQRkbGZG4PfoL2; 25:qvcVullFakV+grhwdveFSIXeBo/NvxtpQJIV0iWwjC71X/MakJbOdmpYUB25zDxzo9VAQVG93PmlwpG0bPKdCLy22j/8yigiIi+nK04JvpZOQ47SzvADZqMntm2Rhw1SY8oOwO69bmk7eGxx7ZiIUinUBQvPVPKOAJs9YEAQr78Xl79XPt3UX0QySHT2rBSUK/YYZeD68wqvIdk49JaCYUNpzMKVSgcYT5aw4wNOrEYabnVuIWCHpra2kYa56Znj X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR07MB624; X-MS-Office365-Filtering-Correlation-Id: 574c84b2-c43d-4be1-8515-08d31d07ca87 X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB624; 20:nf7LFKiJHcoAHS6COFjsFNT/XKlaXxAIELKXwtSewZd4Ppjbedtorg50RpLTzwCgBJ/GpJtjqnq+QCa7HcrdnemWQw4RuL1A8RZFDuGmSmXo10z1pH/yQI6mpt5v/9eJ1vvlo0VB4Ww0Vht/WRBv++8Ag9vT+veB0RxFnr2S+5+7j821/JEYiLt4X4KhLe890Zh3gecp9EDQnE2Egj0drpkDbRFVUKjah8dtHwsTrq9N+qvnbpBRD60QE8+zg9rjBQQ4cg3ZsQU8ixFKshldsHpYmPr3Gt92l0mXjTQ19PP3qYr+JnzwU5OOUR9+q9JNHCGcQ1cMTOxMV/YAK3L5cqMVCHT4gtvsJgiIDKTk5TxHWgC/IZ4q3940Aj555cf29Ea/vD8NvavaQZxKnkSz1XXYAGlQxZj0C+3uV35I2ffW+wnR5xaozaYDiftWZiYgRoBWsxmWAthY0HBf7ZgsVVaMSDV1UUyZYreFAMI8BUAvKeBnaK3Dd0RnQl9vPjgOQ8zUJM+f4GcWm4C1OGHkwhOjYu5bckFnGs589+sTyj6b8nLgd+vQ7qKvPJitlAtoL4wICAjbUbBKz1oFr504MSnDygo+Mj/ovqqCA3wbLAI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(3002001)(10201501046); SRVR:DM2PR07MB624; BCL:0; PCL:0; RULEID:; SRVR:DM2PR07MB624; X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB624; 4:Pr68wd15EvCrhaJCi3tNQmZqe43r76szK9rRtDrREJrowB9/JX3vTv7a51dRswPkf9zk+4aAyaH8S4sqF2xaQd09ws45ge72cs4tQASNEB0c4bJpE+Ha2EjQgr3C89y1kxWKOC87h1x7kBpXkMp2JjRV3KHQwc1WIavmciKvAYQV9u+gm/UYKJZCEoI4eqSaGbMmL+I+zku7O61FaBw8VpQet9FGjG0UOvdoLjA7zsvfCLvVVnxgbBqgj+QsmRovMNFxjbG00oObngqIdNb3N95vyYvifRCMyUznJvE6nNifnzapkkyQ5fDfJngLpogY8TrTEy+fqxOaxqUYb4NXVYSIxcYGuZ7ru7RYpajSBY6y0JzCfLu01fcbrqRbOj6xxEgrDMfFfcdfWesUkuW+4RqmUCom643IpH0oZa04iaXka9yiGrBda2zt7EkIKii8 X-Forefront-PRVS: 08213D42D3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(199003)(189002)(76176999)(33646002)(50466002)(5001960100002)(5008740100001)(50226001)(4326007)(76506005)(97736004)(189998001)(6116002)(40100003)(5003940100001)(48376002)(5004730100002)(2950100001)(5001770100001)(92566002)(2906002)(3846002)(122386002)(229853001)(5890100001)(19580405001)(81156007)(1096002)(36756003)(42186005)(101416001)(87976001)(586003)(105586002)(77096005)(47776003)(106356001)(66066001)(19580395003)(2201001)(50986999)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR07MB624; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR07MB624; 23:vaAn8pJTRtIxo7WRbKd2ObGsgQ8koN9qDN8IhBygSB?= =?us-ascii?Q?56ha7g2QOhwtVfULmB/RlW5Sitq3Th60YrPjWfJ+pBdaePcgvv3bahYrF7h8?= =?us-ascii?Q?ids3gGJfpgaAP6t6tLzEZ31xtSoRUwqv/p+8LduOOxjJBgOcy0o3yj9X9w31?= =?us-ascii?Q?QOyZSVWkGaXqCPusMSO10RZl6oWe13VUkRRg+VXX9YAsI1In9FGx1gYCFidh?= =?us-ascii?Q?MXtSxxvB02CmguPKEXr5D3tLL1UPY4bVvVNl4++0QYsbwuqOamAdrQ3rD+jd?= =?us-ascii?Q?jW0aDx1DGHGQuynn4pwXbwaNmr4iVh9TbDxyGxnQ+bwnoOjFa38Id9bdvjTn?= =?us-ascii?Q?2Bg1hKq0c5cXIv6rqvldnmvRcmtrysnqzWxqs62yfPgCPfTgP4kbOqQuDA/y?= =?us-ascii?Q?C7NVPfQ7qdNcDL2IqgGfdMW8heUIrLmeLPRn5dKiaOWw6S7e+NCf/7uesh6n?= =?us-ascii?Q?jtzYogr3vWTaKMjKfuqrGOsqYPUXzKZ0Z5Stken7t4qljaEeUJ+Eun1lnEqR?= =?us-ascii?Q?azkF5O8lfSB1ti0fw5EAto00CwT082Wg1V2C7EBRibOrZwBZsVveV3YdVJ3B?= =?us-ascii?Q?iKnI9BXSomFE9xtTiBg6CMon4RxQpMl+O91huEbhfZTHClrfSex2I1RP7d0j?= =?us-ascii?Q?NFfgMobxRK2QTSpI4Zvh5Bu6lp4xHYz8724bp0BeD1gxAme2fFTvA/qVbRzr?= =?us-ascii?Q?9ibS0gflgW3g0yXQ1J2Y6f2EC5sFTEDySwMeaVkrWJyK3zrDsZosGRO9V+dC?= =?us-ascii?Q?YWwxnp7DzMR2cM4ZEjezXgfXCLFfubCs/415natlbATY2f+vTlvzh4hlaD8F?= =?us-ascii?Q?EjMEx2GcQD3+dtOjLzre15zwvfBJ7A7bzCgGMUKfScUBijHElv4Gg1EDC41p?= =?us-ascii?Q?mk31yFC0z+FZYmZpq+uI4S67D5T1z/LnB6438bdWLaeEORUKYcvvkecU3LOL?= =?us-ascii?Q?2oCUFlHQTWTz1z5NdDcnurDqETjw0pYl63QibZ606QwhP4o7V70p8KQtjLPE?= =?us-ascii?Q?Pap0sNzuaTgS8esx5/HssiN1Z4bN3LeCC7i+98BzHVl407W8dtkOCGmeKGBK?= =?us-ascii?Q?+RSaSS43W5+6Qc6YEqDp8ttaKeVjIAvkrBe9j8lABiUkAQ3zACr6Bbuu/kMO?= =?us-ascii?Q?URcjad+WIwNMt4FBnAynpu4tXbo2fcN7fmVbvUH8NGEvMZRCS8RA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB624; 5:xiFXgA/7z/ixm4Qb2ahAqBOO8yRn36kGX2d2/rzsKgmb2BPwf2qSwIVTDgbYyBisxiH7xcwOd8M82t5RdY/Omd5M0ezw1L4PoMgj0fnQpSYPAuLe25OxjTrh+kvFVMplsH6/Ck8I8Uk3woni7NBZnQ==; 24:WAQPveBD++aIv9akqGqSsnyXefFhhfNgsHhhiMiGqiYo0sG6WpUen5O/zyMZafNdkGyqnrINnhtX2O1S5a9M0gG/WAeiCUYHLHCloZUnwOA= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2016 17:26:08.5633 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR07MB624 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160114_092633_282883_0B39198B X-CRM114-Status: GOOD ( 12.70 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, heiko.carstens@de.ibm.com, agraf@suse.de, klimov.linux@gmail.com, ynorov@caviumnetworks.com, jan.dakinevich@gmail.com, schwidefsky@de.ibm.com, Nathan_Lynch@mentor.com, joseph@codesourcery.com, christoph.muellner@theobroma-systems.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here new ptrace syscall handler is introsuced to avoid run-time detection of the task type. Signed-off-by: Yury Norov --- arch/arm64/include/asm/unistd32.h | 2 +- arch/arm64/kernel/ptrace.c | 50 ++++++++++++++++++++++++++++++++++++++- arch/arm64/kernel/sys32.c | 1 + include/linux/ptrace.h | 6 +++++ kernel/ptrace.c | 10 ++++---- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index 5b925b7..f57bbe3 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -74,7 +74,7 @@ __SYSCALL(__NR_getuid, sys_getuid16) /* 25 was sys_stime */ __SYSCALL(25, sys_ni_syscall) #define __NR_ptrace 26 -__SYSCALL(__NR_ptrace, compat_sys_ptrace) +__SYSCALL(__NR_ptrace, compat_sys_aarch32_ptrace) /* 27 was sys_alarm */ __SYSCALL(27, sys_ni_syscall) /* 28 was sys_fstat */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index c166548..607a140 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1108,7 +1109,7 @@ static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num, } #endif /* CONFIG_HAVE_HW_BREAKPOINT */ -long compat_arch_ptrace(struct task_struct *child, compat_long_t request, +static long compat_a32_ptrace(struct task_struct *child, compat_long_t request, compat_ulong_t caddr, compat_ulong_t cdata) { unsigned long addr = caddr; @@ -1185,8 +1186,55 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, return ret; } + +COMPAT_SYSCALL_DEFINE4(aarch32_ptrace, compat_long_t, request, compat_long_t, pid, + compat_long_t, addr, compat_long_t, data) +{ + struct task_struct *child; + long ret; + + if (request == PTRACE_TRACEME) { + ret = ptrace_traceme(); + goto out; + } + + child = ptrace_get_task_struct(pid); + if (IS_ERR(child)) { + ret = PTR_ERR(child); + goto out; + } + + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) { + ret = ptrace_attach(child, request, addr, data); + goto out_put_task_struct; + } + + ret = ptrace_check_attach(child, request == PTRACE_KILL || + request == PTRACE_INTERRUPT); + if (!ret) { + ret = compat_a32_ptrace(child, request, addr, data); + if (ret || request != PTRACE_DETACH) + ptrace_unfreeze_traced(child); + } + + out_put_task_struct: + put_task_struct(child); + out: + return ret; +} + #endif /* CONFIG_AARCH32_EL0 */ +#ifdef CONFIG_COMPAT + +long compat_arch_ptrace(struct task_struct *child, compat_long_t request, + compat_ulong_t caddr, compat_ulong_t cdata) +{ + return compat_ptrace_request(child, request, caddr, cdata); +} + +#endif /* CONFIG_COMPAT */ + const struct user_regset_view *task_user_regset_view(struct task_struct *task) { #ifdef CONFIG_AARCH32_EL0 diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index a40b134..3752443 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -38,6 +38,7 @@ asmlinkage long compat_sys_fadvise64_64_wrapper(void); asmlinkage long compat_sys_sync_file_range2_wrapper(void); asmlinkage long compat_sys_fallocate_wrapper(void); asmlinkage long compat_sys_mmap2_wrapper(void); +asmlinkage long compat_sys_aarch32_ptrace(void); #undef __SYSCALL #define __SYSCALL(nr, sym) [nr] = sym, diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index 061265f..c38d068 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -75,6 +75,12 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr, unsigned long data); int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr, unsigned long data); +int ptrace_traceme(void); +struct task_struct *ptrace_get_task_struct(pid_t pid); +int ptrace_attach(struct task_struct *task, long request, + unsigned long addr, unsigned long flags); +int ptrace_check_attach(struct task_struct *child, bool ignore_state); +void ptrace_unfreeze_traced(struct task_struct *task); /** * ptrace_parent - return the task that is tracing the given task diff --git a/kernel/ptrace.c b/kernel/ptrace.c index b760bae..8f688ae 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -137,7 +137,7 @@ static bool ptrace_freeze_traced(struct task_struct *task) return ret; } -static void ptrace_unfreeze_traced(struct task_struct *task) +void ptrace_unfreeze_traced(struct task_struct *task) { if (task->state != __TASK_TRACED) return; @@ -169,7 +169,7 @@ static void ptrace_unfreeze_traced(struct task_struct *task) * RETURNS: * 0 on success, -ESRCH if %child is not ready. */ -static int ptrace_check_attach(struct task_struct *child, bool ignore_state) +int ptrace_check_attach(struct task_struct *child, bool ignore_state) { int ret = -ESRCH; @@ -270,7 +270,7 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode) return !err; } -static int ptrace_attach(struct task_struct *task, long request, +int ptrace_attach(struct task_struct *task, long request, unsigned long addr, unsigned long flags) { @@ -378,7 +378,7 @@ out: * Performs checks and sets PT_PTRACED. * Should be used by all ptrace implementations for PTRACE_TRACEME. */ -static int ptrace_traceme(void) + int ptrace_traceme(void) { int ret = -EPERM; @@ -1028,7 +1028,7 @@ int ptrace_request(struct task_struct *child, long request, return ret; } -static struct task_struct *ptrace_get_task_struct(pid_t pid) +struct task_struct *ptrace_get_task_struct(pid_t pid) { struct task_struct *child;