Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936177AbcJUVJt (ORCPT ); Fri, 21 Oct 2016 17:09:49 -0400 Received: from mail-bl2nam02on0087.outbound.protection.outlook.com ([104.47.38.87]:18978 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933451AbcJUVJl (ORCPT ); Fri, 21 Oct 2016 17:09:41 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; From: Yury Norov To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Bamvor Zhang Jian Subject: [PATCH 16/18] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32 Date: Fri, 21 Oct 2016 23:33:15 +0300 Message-ID: <1477081997-4770-17-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477081997-4770-1-git-send-email-ynorov@caviumnetworks.com> References: <1477081997-4770-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM4PR0701CA0023.eurprd07.prod.outlook.com (10.165.102.33) To CY1PR07MB2246.namprd07.prod.outlook.com (10.164.112.148) X-MS-Office365-Filtering-Correlation-Id: 0fd0bc66-7a16-4807-216d-08d3f9f1f137 X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2246;2:Ba3XTtSEhi4PSW105PnV4OKc4dHHNc7OGzGEBKxwf7JdYF7xEhzAl1ZSSGZpfGfZ7qRnehNHgTQD+XSz+KA1zji4Q+Md2KRKk5HiFMMIqBhcxdHV1af600WEEf5/Oq3K/A757etREuslNdb3YwFiEKTnUNAQfIwDqfD9Chz+Va15z2fgK+JP1jkccBiRawA30pRbTla/UjgJuxYvWoOITQ==;3:JDwgrd/TOstujXy7GeOKCNJEsikRl4lx6CPh10/akLFGnRM9LX5P5DyIYFtkWpAPLWfPcqVxzHavm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w7XXj4VxZqvfpSst8F0qAuD0XfL5Rx1fPWRaRiRDR5DZllOW7ueC52XLo662+jIUburGwjnekSvLy1/XS6yewsU1aaUL1iWYlB34JH2I03bR0HVtWZPVrtJ8VakG1tyHvYZv8xZWzW8qHoI4h+1EO91x+v4zPi2xK7EahhrYDE1q6fSc3TzQeo0N/wxOahvDu5novnh0K+Cv4m30nL9+i1non11VYZLaFEct4CyXX6A/XROiTV8x1JhL6uZWZFYSU7NLTco5SMxRUhzlWPGUkzDsJ4UECjt8PVI+8Ybs04FT+sJ3oXsnggK+2u2hTi/DwoWSepdG5BIBB58tB95tzQpIlPpR33uYRj3Bm7clOiTZ6p4wV32Bcq4aaDZKUWf08l+z4qMOq6T+ksl6AmtHN2a5sOO8Zl2w7fNlHu6TY/QWd9g0U2jB4F+qhweo= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(50582790962513); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:CY1PR07MB2246;BCL:0;PCL:0;RULEID:;SRVR:CY1PR07MB2246; X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2246;4:9hm1XEsi5GOqUvMVdzxPb3HnSWdPmUyLeJ9foIUIrr6jIhtwNSfdtL+awrDdrFsauhhc332gkinGw7IFmp18rpD7+WelnrpRyKEC5YGCr3txcSSvnNnuoJG0ZkyDq5rHvjwYCvcWKiTnQecHb4UpjxD5cc/YA4U9hlwfngW+IW94c3qID4DNnlh+2o/DozxQL7zNVakuE/iKF7BblSbKaMwG+EYzNZCCC2b50q4hh0Fb5iaay8rl5XkvHv6+iMmvDEj3slyKZ9g2emkYwhQf8lZkR3+rdm+yULG9BupLB4vZS7AOdTptceKpGo/B0eNQsaw4wRZcBa7TllyrjpZ9KpbMlaRCQvHIrcnC6XiHRkHD2sGfuATSk8yrPKSzr3/hj/8ThS/3sZuHGSaczhD8CmdLUMRrhL6gHJsCL+BZPd03bMlljuSKb1WR3FMbIzJGF1v9vKjnhRs68irbV2gDiQ== X-Forefront-PRVS: 01026E1310 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(199003)(189002)(4326007)(101416001)(6116002)(76176999)(189998001)(50466002)(5890100001)(2906002)(3846002)(47776003)(97736004)(68736007)(105586002)(229853001)(66066001)(106356001)(92566002)(5003940100001)(77096005)(50226002)(5001770100001)(81166006)(76506005)(19580405001)(19580395003)(42186005)(7416002)(2950100002)(7846002)(81156014)(36756003)(586003)(33646002)(2201001)(5660300001)(6666003)(50986999)(305945005)(48376002)(8676002)(7736002)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR07MB2246;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR07MB2246;23:avhxne7bbuhgZl0b19R2Toke17d/VtWBd3WhcCGHp?= =?us-ascii?Q?tzlLZ4JS+Bleq9gGoLJzFcPAEoWNKRnXJEv+6CoTlH+d0iXtPyR/63lBEuJ/?= =?us-ascii?Q?0/E/NAuh9DOK6bQGV6t2AK8+AXsTfdv3er6MYL4iTXRXfI76pynlZPPEmGtw?= =?us-ascii?Q?cv78J+bTriySgNDaD/W7uyZp58Au8hBLDj/hm1SDhF183PAwLKIaXyJpN0XV?= =?us-ascii?Q?UFMtffm2eMRFTRG3/4RqXT4zZFA9vUKN/j5O5k/lcLNsSngYYkPj8DFDDW/H?= =?us-ascii?Q?xxrPsspsK3Xzy48Yhzb3STln1LFhAkWbuXAYqS1j+rDZnl4zI0ppeOctR/zs?= =?us-ascii?Q?s8nkzkCNDNJafVgrpg4z0mBb4xWVmdHDwzvywF7GgjmKqaENRB3WOmUeC033?= =?us-ascii?Q?wxKFvhbP/ovCLPwHFnPXf5zOheB8SwVNa6bbd3/kD769hlKM0ma9S71KMcFU?= =?us-ascii?Q?vdBZKfg7pfAPjzHHuBahXPkiYN5E5uv5YfeqeM/4mJPimuJl2kjVChTES4XO?= =?us-ascii?Q?GToFxaYmDZEvOu2J+q7h9BGSciJiufWEal7rUgRqgUECgWZzKksp9tkYLw9Y?= =?us-ascii?Q?6EZVRo19mX+MfG7BGWHO3biiZK9gdVr0Q1NJmDTImTzGYgH9w3WuXzQUIEws?= =?us-ascii?Q?57ofuQnIMYyEhJsGAMadkphLNjb1Ky4ZAUKnpFLVGu829SNE6RyzqhtTTvZn?= =?us-ascii?Q?Va40a1hp2ECpeRlWL1dGFw8VIo0xlK+3Uj5T4dUIL0FgOkkxdZICHugyQt2R?= =?us-ascii?Q?mjIg8EEEmhQD9nB3too4/J7qbx5AizU+iSZ2CcBSLbY5kx8zO8h2OusXwbYt?= =?us-ascii?Q?AP87EoE4OpI11JTp4/CVCJL6rS3YUlxm6PF9BeKWc1vBOnB5JVvSvasbg48H?= =?us-ascii?Q?wM47wc/JtUVnIq0aomOJ3fZilizGUjVE17eWBRxqltvEMTOOqJhO2EpbLgMk?= =?us-ascii?Q?OfY6WbXKZj9JKrwV8oAEaknCCbYM1H7PoV0WiJZcqP3DE7nvbuUFz9/Mka+V?= =?us-ascii?Q?miGim1CiJTbog5wjBrZ4EiKM5T+59UTFTHpXV8bcZsEKPyh43UksC3bNptTg?= =?us-ascii?Q?PHyFfsm6eNmYkjImtu5/wd+ZJOb4vew+AKHDWaj94DUz1c30GyxWMNZynXUx?= =?us-ascii?Q?JfFRR33oi2ZLmo662dWKxikmS+Xm3f09iG3I71/nP7gUWWLv/sNjJNv4MeIS?= =?us-ascii?Q?UtYgDGcSQYnnqcr9yemesWnUKv7eWI3Iy8R?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2246;6:AI6FcAyWje7NAIvz9piMu1oWCILQuQ/GgbW7HFEgblY5i59mzTsiUyqGzut0N2RnWy2ViN2nscQAgU9wYuYc+qV3P45/GZy8kTPk2yOsBV1ertzLqpKdLWzNv2Jz2zNJgm99I8ElQhLEYVCYo/njOJgCBOt51ii3u0RWLe/I4kHnmpxOr923H6y54CbMbnEYQ9c6n58yGXfBPnFP5e6kpcb5CDGW8EVMn11F28wblf5qe9vRgWRsNgxJFBcKbJJvkCkKcBwgzXFZuB+veRweAhJNuzt5XMcFpW2d2ZYIGkLVa9UOl4ZrmagWYtxhSHKF;5:Z3zGgboKD19k5I1slUkuqu+07WYD43xIh/vwU4WHcq/WXioejh30XSfxmaZqsBtzKCsvfkzmJsA3VEVmEOrmqgVtyWh7xLz4kTHUZY+udmUogt7WBnEiJ6ZRUgxgsVeD4BqsHy9dGzAabM9y54lPsa9beeLlflrw5b54pAX14TE=;24:QlabiFN5dtHFSbArGa00wE+dzDd9uQtHZ5w++NGzGOOynZO4snzvmozRHDQPV/o6yyWW/4wRZf0aiCDKIp3d1xapArL0s95mT0B9XmFbE48=;7:rGihF7G3/8TZ25mUOuJUJVRfE3CO92RfyycwGdnLOJO40JxTs3FvQ0g73T9N8jVJ5tHAVp8HHZiX0AD6pzkxmn/9ayCSEJJfQ2kPqPbQVCROevqYIKFp9Vcc/AluWHh3rl7SGxbSKakEq3/wyqRsQWJXbiOR7rjgwpRwnath8EfUnmfiWdhQLrGeCo39zAS0ZfL96klGa3y275W3oB2fRNPvkso21mqV6SB4KQB6QC3Xfnr5r/F5dDwwp0mhtdfqZonv5Ryk0koPOh0hxZTfOGeDB7MEauOQWdYREs9JAwNRhbRdJiYod9vhZlo3eiiAV2vscoFYO1W7NiYVCyL77/NjN5GKMcaS3Jb82O8Ywgw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2016 20:36:31.5134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2246 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7141 Lines: 232 New aarch32 ptrace syscall handler is introduced to avoid run-time detection of the task type. Signed-off-by: Yury Norov Signed-off-by: Bamvor Zhang Jian Signed-off-by: Chengming Zhou --- arch/arm64/include/asm/unistd32.h | 2 +- arch/arm64/kernel/ptrace.c | 91 ++++++++++++++++++++++++++++++++++++++- arch/arm64/kernel/sys32.c | 1 + include/linux/ptrace.h | 6 +++ kernel/ptrace.c | 10 ++--- 5 files changed, 103 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 1d075ed..ac542c9 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include +#include #include #include #include @@ -1215,7 +1217,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; @@ -1292,8 +1294,95 @@ 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_ARM64_ILP32 + +long compat_arch_ptrace(struct task_struct *child, compat_long_t request, + compat_ulong_t caddr, compat_ulong_t cdata) +{ + sigset_t new_set; + + switch (request) { + case PTRACE_GETSIGMASK: + if (caddr != sizeof(compat_sigset_t)) + return -EINVAL; + + return put_sigset_t((compat_sigset_t __user *) (u64) cdata, + &child->blocked); + + case PTRACE_SETSIGMASK: + if (caddr != sizeof(compat_sigset_t)) + return -EINVAL; + + if (get_sigset_t(&new_set, (compat_sigset_t __user *) (u64) cdata)) + return -EFAULT; + + sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); + + /* + * Every thread does recalc_sigpending() after resume, so + * retarget_shared_pending() and recalc_sigpending() are not + * called here. + */ + spin_lock_irq(&child->sighand->siglock); + child->blocked = new_set; + spin_unlock_irq(&child->sighand->siglock); + + return 0; + + default: + return compat_ptrace_request(child, request, caddr, cdata); + } +} + +#elif defined(CONFIG_COMPAT) + +long compat_arch_ptrace(struct task_struct *child, compat_long_t request, + compat_ulong_t caddr, compat_ulong_t cdata) +{ + return 0; +} + +#endif + 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 2a99027..5638880 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -138,7 +138,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; @@ -170,7 +170,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; @@ -294,7 +294,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) { @@ -408,7 +408,7 @@ static int ptrace_attach(struct task_struct *task, long request, * 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; @@ -1057,7 +1057,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.7.4