Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933825AbcDEWMq (ORCPT ); Tue, 5 Apr 2016 18:12:46 -0400 Received: from mail-bl2on0063.outbound.protection.outlook.com ([65.55.169.63]:8640 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933808AbcDEWMk (ORCPT ); Tue, 5 Apr 2016 18:12:40 -0400 Authentication-Results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=caviumnetworks.com; From: Yury Norov To: , , , CC: , , , , , , , , , , , , , , , 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 Content-Type: text/plain 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+vjYvDVGgsj7nrlps5uSeFQgk3BtvLLvdP7eIiD3ukeIiNfvofoC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vCWZOZ4TEqhooCKSO0FdDN8y/hiz9yp5o19D6gyISVRCreWAC3LpXk5qUFJcq7Btnl506b5PwYpGRBib5XVkUZ7WAVpDM7UoaD0F7WFCt5bwjrJIhPokQ+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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5842 Lines: 182 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; -- 2.5.0