From patchwork Tue Apr 5 22:08:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 8756081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 262059F3D1 for ; Tue, 5 Apr 2016 22:19:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23632201FA for ; Tue, 5 Apr 2016 22:19:28 +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 1608B2025A for ; Tue, 5 Apr 2016 22:19:27 +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 1anZIC-0005yG-KB; Tue, 05 Apr 2016 22:17:48 +0000 Received: from mail-bl2on0100.outbound.protection.outlook.com ([65.55.169.100] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1anZDW-0008H1-42 for linux-arm-kernel@lists.infradead.org; Tue, 05 Apr 2016 22:13:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PkIheXTThV6GA7pWMp9Mste8SK4DhyziUBPmEiJS2A4=; b=aizZmPYiHyogcg205UntK73k9Qo50LodJmTZqRod2LpxzrGFaz4F3piYOCUFRAAksuVXHNiATYndWSbVcvhypDhJl6I01ztBzjTH0/h5Do4dUW9lRXrS9Z85Wd3xlA9X621ZfyqkPATVOh5T5U2N+lsjhbVJccDIvZvOHq9BmQ4= Authentication-Results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost (95.143.213.121) by BLUPR07MB611.namprd07.prod.outlook.com (10.141.207.16) with Microsoft SMTP Server (TLS) id 15.1.447.15; Tue, 5 Apr 2016 22:12:34 +0000 From: Yury Norov To: , , , Subject: [PATCH 19/25] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32 Date: Wed, 6 Apr 2016 01:08:41 +0300 Message-ID: <1459894127-17698-20-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459894127-17698-1-git-send-email-ynorov@caviumnetworks.com> References: <1459894127-17698-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM2PR03CA0001.eurprd03.prod.outlook.com (10.160.207.11) To BLUPR07MB611.namprd07.prod.outlook.com (10.141.207.16) X-MS-Office365-Filtering-Correlation-Id: c01898f9-f736-4908-a3fc-08d35d9f63bf X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB611; 2:SuliOSSCVm1eSS8N9On/2nALgze0GjvVNe0AwYAZVGU2Ja3vbyGxIjfZJlaQ4+AXloVqc2uxKB8ijg1gMhiJVMHF1s8pv0MNo3iDmrk6v3GOBbMpHOhY7NUHyZQA2jLx9hzc42uJYWKlozSvpFTrzPAWbMjF36Ir7ESvaAkogii2jUwRGzL4KDfDbMTCN2Ex; 3:ldTYYmCJrb9B9VcGVKct8K3j2Ej4UYGHvY8ZJsG2FFDMTsOb5eDfVX4O+0+vjYvDVGgsj7nrlps5uSeFQgk3BtvLLvdP7eIiD3ukeIiNfvofoC3sUKT8Q3oxwNw5i1+7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR07MB611; X-Microsoft-Exchange-Diagnostics: 1; BLUP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FCt5bwjrJIhPokQ+AF2KFMdqkDGPniDcNZI+eXoqiwVYOA//JBdshEBzyOx2KRLAmtAhYCBRWr9irPDlugzkpcLIFrp/+IfUgAES9qIdZRxWbHxG4wcPkQvf0uF9WXcIhGSN9Lb/XVE4N0+KbLz42fUl/fJwB9lA32BfQNLZIBtPK+qfyyxMSdWUGf5UK6KUFCb7w2jpWRSc4RL4ZREOEVdS8NT1FmlniylgXYw+4etJVZWUQXkujpOT/MLDFuNXN7cdCU+7dNSidTW7+Mpr4Cv/ApsYeJiVXR7eNY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BLUPR07MB611; BCL:0; PCL:0; RULEID:; SRVR:BLUPR07MB611; X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB611; 4:1YF9J43W27wL/5SGlVqUA4INkRbUDbEu0CsLmD9gxVvKl+voDXt1UEnoXUxzopwIPTBZZKdfcb4dPQvfAiYrTelVtUMa0JyhcENKua7gbgNojdgIzWRY32vOvR+RDautFqqhT1DkrznhqXyUl0cfewHvzipmu3JqJ1UhHtZy6LSM13Dnap0lLzPUsvxS9G7Z9f3XzNDyjeoxT19Hld372Ml9tvDajBGYm1nH1DjAVy1OYNQscvMRSBeQYSLKqb7U9HpyRsEFz3OLZIpu3hfik4QzitQegTAGBwUc4jQLGCQzw6Jy4ftmZUJmsSjVBG9wpJmpRZPs1JiP19hsyvzSWP9lWZWLfzDeQbfFGiG+zo013+5pAfhDIdr8qO/hlzH2 X-Forefront-PRVS: 0903DD1D85 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(2201001)(5008740100001)(48376002)(5004730100002)(66066001)(36756003)(586003)(76506005)(50986999)(6116002)(3846002)(42186005)(76176999)(92566002)(1096002)(229853001)(5003940100001)(4326007)(189998001)(2906002)(77096005)(2950100001)(19580405001)(19580395003)(5890100001)(47776003)(81166005)(50466002)(33646002)(5001770100001)(50226001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR07MB611; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR07MB611; 23:OHgd6bUsyv+PGuEwyPxbAfEALCWZP2tVetxxb2bDjn?= =?us-ascii?Q?VkzEFrK3C4kC70D98n5XzAKOul1Fu9EY9kBOqvayICgFUS0VrgigwT+IV+Fy?= =?us-ascii?Q?01dBUDcgiPamNh7XH7mYcmX5YvGce9hGvvT47O2EdsLpmblocoJ8/t++/i7D?= =?us-ascii?Q?UYQ7Cup8XxlzbXQjEkfUmBaunxTvXUMRJX3V1j9VOWXPfiUXR1dTkTrPCQgx?= =?us-ascii?Q?cNe+7zmk7sydHg35CTMGXq6s5BIyQlhy4Fj+P26Ee6m1Uxf/UpowsLixITQ6?= =?us-ascii?Q?8QvElD6mdloCSeWkPMVR8aCdnUuG1UmFNkbBsRY0iJA0brdIh9+KCOgvZbWk?= =?us-ascii?Q?Hc6Nc2Z3wD/5AkCFkja47B8z6tKAt5jKFdO7oQVHSuN7ed0HU6ftaGBnfITZ?= =?us-ascii?Q?WocpibdhirGYI11fdif/yD0iaxOv2sJAUBcrFcn3rNm/9cad+0e/XI380TUC?= =?us-ascii?Q?HVYZYgS3TqJZF0MUDquGiBOTR/x00TPPMchIKDmaz2uoywKeRhmezFhei9bi?= =?us-ascii?Q?T9Axi4fVQBssAHwW63Nd696jb0cHMbWK2QnIPv0lD1Dtv3yq5opxVOu7xaMX?= =?us-ascii?Q?6gI4Xg0+NwwIebYN3c2qViMWaIfzz35Hp9kVFQcL3kCha+cvHlFNJMQXfppK?= =?us-ascii?Q?qRmsKhcoCSxBPpPTa9yQI1r2hjkKoCNiu2s270/KbCmmpIMFLV6gsiUb8WiO?= =?us-ascii?Q?uYHPIJNDjXq+MDGvFOWOXH8bZH/Ivzvs++Od8DX/Dt3IaLuwstfRWnXqYqnG?= =?us-ascii?Q?IIP5A944bbz3IluLAQ8k8AP7legGFrdyas0cJIvjVLJWf3XklITkGG/QpLFk?= =?us-ascii?Q?SsImfJVwJo+PUxGeV1kyOlTNUktHbfjMsm8HI6Yv6XsNX3zzlpM7AumEwCvQ?= =?us-ascii?Q?HOwtxt5Fh0OKPLte/1hkWbHbrrUx/Qvpv8xIaKcYf8W9dQgBGZBA9/2vkcck?= =?us-ascii?Q?JKDAvBRbQZSI1n6Sv4gSMm2zBWXV8R74CD/raCCA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR07MB611; 5:skcdcS8E/qENKwojs+fJFl9F+xje9tCoEFeXfLEVIjCRBBZ0QCOkkn12zD+f2nNZtXRKjL5gJdOve9+wz5yqBS5CLp/JMAnjj2iyH4JKZ4n9muQ5XisSDHUmoeV/7gj6jFVXJBNvRS0z64MVeiH4DA==; 24:dRu+ttRFNy/isTUq7S8hpupzIMwyLIV87cOzcvxc3AzjmnpvY8XJYaIN2qiIKyeiSuFEOYydwtEr/7FLZMUCar/fGGFyHugN8IalSgbf2OA= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2016 22:12:34.1090 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR07MB611 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160405_151258_889302_4A71915B X-CRM114-Status: GOOD ( 11.55 ) 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: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, linux-doc@vger.kernel.org, heiko.carstens@de.ibm.com, agraf@suse.de, klimov.linux@gmail.com, ynorov@caviumnetworks.com, bamvor.zhangjian@huawei.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=-5.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, 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 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 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 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;