From patchwork Fri Jun 17 23:54:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9185225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E6397601C0 for ; Sat, 18 Jun 2016 00:00:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8D027EE2 for ; Sat, 18 Jun 2016 00:00:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C05832833E; Sat, 18 Jun 2016 00:00:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 23FBB27EE2 for ; Sat, 18 Jun 2016 00:00:10 +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 1bE3ee-0005KJ-Ji; Fri, 17 Jun 2016 23:58:28 +0000 Received: from mail-bn1bon0074.outbound.protection.outlook.com ([157.56.111.74] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bE3c7-0001fF-QW for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2016 23:55:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6BKb8D51HUYe+5eyr/jyLkvz9PvItniwbQ9R29r52IU=; b=e4/p64PGBbVFFoJVzUgTLl/apSQGBN2BmYng6rB/3hCEKn+nWsNicO7niW3w3Y5yHci/8Kav0Gi4Dx91wl/LpJ4qu5JfZ+qKzVdSXxwkvp616SZi+oanZzj/kdS+UcQRQjz4Lg8jJDLrtFaddmV7o/2xof4Jk7jVZ5OtukrtwRY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (50.233.148.158) by DM3PR07MB2250.namprd07.prod.outlook.com (10.164.33.148) with Microsoft SMTP Server (TLS) id 15.1.523.12; Fri, 17 Jun 2016 23:55:28 +0000 From: Yury Norov To: , , , , , , Subject: [PATCH 12/19] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32 Date: Sat, 18 Jun 2016 02:54:21 +0300 Message-ID: <1466207668-10549-13-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466207668-10549-1-git-send-email-ynorov@caviumnetworks.com> References: <1466207668-10549-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.158] X-ClientProxiedBy: CY1PR04CA0032.namprd04.prod.outlook.com (10.166.187.42) To DM3PR07MB2250.namprd07.prod.outlook.com (10.164.33.148) X-MS-Office365-Filtering-Correlation-Id: d274f1fd-201f-4e04-97c0-08d3970adbe3 X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 2:FTJircV2q29jaq0DPFdjzDyvWfzUrYU79tyGqciTJW90mq5GFoAhpANoLRfGc4okQLz8eHny1ZsHsSh8eRRyf1n+DN7BdVBktCpl9xfDlApwTIub9MZYs6dJSuL0EMwP1kMhGIkJ5n2Dj1eFZTq66Ggaw0IHnabNYGhPPxynhKJhW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N98gSr31a0doFFXz+m+X3q7owp60BEYaKql0eKbbKjZj57/Dy/7SjeIlTnNgtt8ygLNVMwpxJA6IA/Htxvp9eJ/yAOn2iM1Mp3Pk/m22Yl6xaefV5KUDUUEZiGMSV6bR9DqRqO2l55ZKmSXsyGUwouDCmqBzRMVFtY7Yiah6zHwVAa+IxhdD97R3ahCRChKl//iJv46lLKSU6ma7QwGAzI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:DM3PR07MB2250; BCL:0; PCL:0; RULEID:; SRVR:DM3PR07MB2250; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2250; 4:kfHb6oQvSyssP8A/eSUVKWp11Vs9oZEf9bWZ6CjULjoMJC5Zd6MSpOU1Vk0Cb+MBk/S0DbjIznhKgGlGq99jnpNXOds7en920uuNxBuVn/Vpw2r8CJcGpAqPZh+bk+zHMFHxwKOjqcsKw5Hy3PMiY+fDAPcfq2Pd96H42Xfxk8RWQwcjQ7i0YJy6yYc1hy8iTx2YkAt0Jm0sGHO2mT+8YPWeIeJKZ8+fNBSlZ4DCMLyTKAVaWGxjrqaeIbtS3lUuOAKAefP05cUAMDjIFBEnPwprkQzN6v3m5GVU9o5xHRcE0etDn2EnGeru8iQ2PRIBhMZlnTJfnTWGUoup5cvNCgI2Gv78zlDBEVw2f5iwa8Tj4nFj7Md1hKq+j5I0lKVf X-Forefront-PRVS: 09760A0505 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(199003)(189002)(68736007)(189998001)(66066001)(76506005)(586003)(50226002)(5890100001)(42186005)(6116002)(7846002)(47776003)(3846002)(77096005)(5004730100002)(48376002)(19580395003)(81156014)(81166006)(97736004)(5001770100001)(2201001)(92566002)(8676002)(50466002)(101416001)(105586002)(36756003)(106356001)(4326007)(19580405001)(2950100001)(33646002)(5003940100001)(50986999)(76176999)(229853001)(2906002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2250; 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; DM3PR07MB2250; 23:5qgpUQ9N3QeOu2P6mTr6Q9yL4D9BhRaWPs4zXS0m5?= =?us-ascii?Q?Cjt33hwjKvEJwnmgUjq80cpH8/cmiwSrAt49t6fn5IZsBVOF1T7QuO2cNGt2?= =?us-ascii?Q?nzVLU5o1HdIA3xzewcanUTzGADLd19c+5O60NkZeaAThP+Exc04roPBwmaog?= =?us-ascii?Q?Frx3/t6DapfdMp2vXq6O2Mojfsk+/wstpASNUP/4M2eyszlwEye1qgEB8+m6?= =?us-ascii?Q?RzKxemBSWQdry4ZIzVfIY57W8dZ3Z99CkWOnBlRYjuxbmbvZhgkiAcW34tZn?= =?us-ascii?Q?UogvseFXb1CvLIScEtxyUzD4Z+96z514u31jfkYirwo4z1mQYjGSj1+2oFXY?= =?us-ascii?Q?GvLUoDYdGWIFhjU/j0+HpWCWeeXbIB97F4D3w7/nJ8hQirB50OuRO+EVY/GL?= =?us-ascii?Q?fjmPgq4NV1l/lUpnWXzgDF6MTQvTt3kTlwokZTAwMAZbievJigbtQUIFu7AD?= =?us-ascii?Q?MyjK+r/wTbeob7bjKiLN9fr1yqiOfIdqahAeCKwklmzUEmjhtIK7cG8XxZtL?= =?us-ascii?Q?bVeI35kp2CWL9TH1K9Zv0RzrXZ4AXs5u8nCIkVw/0T3ws+ilW3eV3pQ6BEzJ?= =?us-ascii?Q?VMKiJrKKNluJF5zIHvxvN6V3xx+1MsJLt1XoZa/+Z9eiLky8SjwICxNXzwBP?= =?us-ascii?Q?Xh5Un15f1rAWPz64hB4c+WDMf3Z4CXq50rnTBdhvK/4lNv9utbglPBFTJYHI?=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BSKSXUwMpgxMB5FOV3M2jlRunwzgf2GhiF7UI5yEXPw4SQFt+4Gz26A9bCxWCBgk9I2HFq+ylUp/23huhmO67BLdFsVGo+Q0=; 7:jYKVwijk/ubMMkY/7D16sbL1zPe0bfZ5Dv6O0typWOzHVw09tMBprOYo2i1GxXyCx5qXJQdq5fMwNn0xCjWSY+Enz8xwZRMJKo8DpY7qYD1E7zuREZjx9MMDqvZJnJzkrBuD3Bz7lOn5M17hUdiyplabpFArm6TJ7FS//o27MzhyEHaLuXttr1kc4CAvH8c9+x6Hre2GD7MuW/27bLbD1lyMf/rXhG/EzqpgVj/mOUIZ9N3MtEx6gn9h0dGKvMar SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2016 23:55:28.2223 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2250 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160617_165552_502853_00C30560 X-CRM114-Status: GOOD ( 11.14 ) 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: kilobyte@angband.pl, manuel.montezelo@gmail.com, pinskia@gmail.com, szabolcs.nagy@arm.com, Nathan_Lynch@mentor.com, heiko.carstens@de.ibm.com, agraf@suse.de, geert@linux-m68k.org, Prasun.Kapoor@caviumnetworks.com, klimov.linux@gmail.com, broonie@kernel.org, ynorov@caviumnetworks.com, maxim.kuvyrkov@linaro.org, schwidefsky@de.ibm.com, bamvor.zhangjian@huawei.com, philipp.tomsich@theobroma-systems.com, linyongting@huawei.com, davem@davemloft.net, 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-Virus-Scanned: ClamAV using ClamSMTP Here new aarch32 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 b7e8ef1..6da7cbd 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 38a09338..a861105 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1114,7 +1115,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; @@ -1191,8 +1192,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 504c98a..75887a0 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -97,6 +97,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 d49bfa1..cadf24c 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -136,7 +136,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; @@ -168,7 +168,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; @@ -292,7 +292,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) { @@ -406,7 +406,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; @@ -1056,7 +1056,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;