From patchwork Tue May 24 00:04:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9132551 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 92FFE607D3 for ; Tue, 24 May 2016 00:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 872CE2824F for ; Tue, 24 May 2016 00:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BDFE2825E; Tue, 24 May 2016 00:09:49 +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=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 C60162824F for ; Tue, 24 May 2016 00:09:48 +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 1b4ztQ-0007y0-Jr; Tue, 24 May 2016 00:08:16 +0000 Received: from mail-bn1on0082.outbound.protection.outlook.com ([157.56.110.82] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b4zrj-0005nW-7K for linux-arm-kernel@lists.infradead.org; Tue, 24 May 2016 00:06:41 +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=aqo+3VRhhAGy2wNAmH2eoFq0CNdHDzEO0vqq6njf4iw5pAye24Boafu1SPcFody24aphNdoXZdN9o/BiX1MS49nc75GRHwnNfWKgN9zqRnljmdZBcNoK3RGN/ShkIWZRB/1qbWCJrcQj22goFn2UfvOpea8UxBbOyBg/N1u5iXU= 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 (50.233.148.158) by DM3PR07MB2235.namprd07.prod.outlook.com (10.164.33.145) with Microsoft SMTP Server (TLS) id 15.1.501.7; Tue, 24 May 2016 00:06:09 +0000 From: Yury Norov To: , , , , , , , Subject: [PATCH 17/23] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32 Date: Tue, 24 May 2016 03:04:46 +0300 Message-ID: <1464048292-30136-18-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1464048292-30136-1-git-send-email-ynorov@caviumnetworks.com> References: <1464048292-30136-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.158] X-ClientProxiedBy: DM3PR13CA0036.namprd13.prod.outlook.com (10.164.193.46) To DM3PR07MB2235.namprd07.prod.outlook.com (10.164.33.145) X-MS-Office365-Filtering-Correlation-Id: aa01fd74-bc99-47e0-59d7-08d3836735d8 X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 2:XYhFQ265fEBTwHxEBH9l/gEZ1yqs7ymRJ/uYSYKxCkXrPE7HqUrMLLxP818QH6nNxwKkIoqfsMj6UCrckO1nEQNsxKmMXxqpeo4Bl7lGlcvYMInlMGcSL2Yc4wU6RdKjQNOKzvndPu1dpf1qU7fm9E7gGpSOfQOUsO0J1GVGrKw/zsXjQUQOuFuj3+eaHEtO; 3:Ywg8nrKcwl7MBKxrvNbBlRoA2toWDskXCyvuIaZgGAqNEHToKo3+tiYWL2PLlcs71JhmMAq/XFCCrxiLYLEV0osNcSuxXq7yE7vV/vR9kdTjItm95oGK+8EOvrzoEJwf X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM3PR07MB2235; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 25:cAo68EE2wyofq7vd5WyVJsY4wV+L06eZAJh6zd8eECVnksIfHHhAOed/3pU8dPlUHScaXQ2tvPYXZyKbURCx9rBEYfSKnCq3RoPp4wUkt7U9DlsevjX1uDIKxZ8+n+LTwh81LGZqNnQk8lcBNAItJgmQ+i92LVEx+C5JslMCvkcAV7b0vqIKc6vUYR1tCio5KMszo+N6UTG0xNtg+mVIzYmCYtv+hm7QHks468trFvtGO1AqG1O7G/s9qIy4jEBhOqR+h6dKg2t1TLwxWMWukbQ28j3b4/CXzOYjGvXjN8W2TY1aDuJRir/aqojmcPkiaKmyBGDvgiXUlNgI0WGD3fV4ssW5aLEiwYt9VJFI1hP+rd6JRBEIM956En3eJcGluCxDqr0uOR5OtaRe8R9T+ivDJ3t8A0DdQh1Dd46DUPcViyfL2oQazl1xQRRTMw9DdDCGCJ17Aywv1hlw6lbhtQIzmFTLjOSGvHMBNCwBFJgyIic2asjjXn6TPK9hIgl5SVTRPCm8yx86pssZs8tNMWwexpbS0ozEig/5M/ZXmJq8aeBkC3Lfrr/PwoTZcGeXFmyM4bNG658DIkB9ubhlr5NkYsI1yBvftQ2QSi6OQ5pzl69EFurrqX+zpE1/EIX/N4PJ2ZabfJmW456CXmEq4CeqqnXlcmRc4cEmW/t4899UHpWZTPB1E2v8AsYXl5WPc4izG0LPUTu4hsZ7jQ8DfsDp5StbSfVTjfQ1mppE+MKAMpDuUtG5npm/RuMVVtYafRO499qo64r568UWU1Z4caSYVxqzMoQpkf9UEH+/Awc= X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 20:JXjyqyqa+rQFRv+zhHeDGzRTmeLamslnoRxF46toQ/Q74rjvM/WmXSueCVrGnDngmv1LD9cPXb+ysHxWP8SUPVjMJAhre2yd/+SBafF283CpRZUPDbnxYppILRXXy3zHGzb//Qor8Zq1SzzYrVT8K8f6m1Egtp8x7jM3FJtm08swVn/nJ22mad+ACcDG/GjRfBf4aiDDsaMKqZORHVluKAYhtVjOC3PwxV8HPX0s3A43ua+EhP5me/u8chxQhOFJDnx4Z8l5aB/qrGsJFKgnKEWRQzbYXzwsJWhjveFpAOXlzKg8ik4TVNthGiSz9l+BObQl3eE2AqGPVN1tj4na/vZloFmTeGznyolWC+Z5SmnMdeq/LOkqQtGhLno5g9/sheHR+iJ8QlBytN11D54GPo06rPspefXf/lX/Rhqgo7dHogMwUfwMsNakJFN9qSwuD6ZxzjDJhq7pNqZJZEPGQwAkrtTNpOl0c94+I1UxfUp9GaiFpmacv2/kTJ0FxXDXaEM922q+ok324TrF67AM3+F//m1ONR0unYMAEKlWC67d7JrDYV9Kp+PN4E92r5ozUSnUTLlMOUI1Ji48WXk/Zc1WLePHUjDHcuY1cZZPHlY= 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:DM3PR07MB2235; BCL:0; PCL:0; RULEID:; SRVR:DM3PR07MB2235; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 4:1ij3rdjLgVz4EFXaxkofXV/cUNGl8bsj9xVajCrEBB/0/c0jElQCohZfms/d3CDQX+2G1aCWYjsQpIgQtCIwfyGwDdc/ad2e8KHqEl1V+1fnqrWHxoFAqnqqQ9vbsPRWGd93scZs7VoratyE7B96Zlu2cxHYJ3NQuJkm9GtpaTBGIllZhU7OuM+1hmPxa+gYXYFMeKb9fhFqNEak6LZKRs9gOXP36WQ+P4mbzNAgJYsbyeNJPGq64+rZ8ZP7VdTKzRoyxdkFdkcvMkb1ksnB2UHlfmbqS0Wl7WWe9b29OZ2KLDkK0wh52n+OgkIDMIswVOkleDiCeWzpvHymHU431iO6+wcsv8vDRD+SK3w5wpU0xHkxq/nYi/ZbgFMJzaU1 X-Forefront-PRVS: 09525C61DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(2906002)(5890100001)(5008740100001)(5001770100001)(92566002)(19580405001)(586003)(50226002)(77096005)(6116002)(19580395003)(229853001)(189998001)(50466002)(48376002)(36756003)(2201001)(66066001)(8676002)(33646002)(47776003)(81166006)(50986999)(5003940100001)(42186005)(2950100001)(76176999)(76506005)(4326007)(5004730100002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2235; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 23:UTLPo89UWLUk4CmguKtZJ2G/sEfPHjdOMlDCvB+l93He1S+mw/STSRuPYfUuCSmXs2lgcxyaFgXzaC86iLuxEQmnRSzO0q2WhurREcMlNNqt3fVuD4KgzVyY+Npd9rHpTdkbZU3TfXyhX4CdFv/v5XQvEDVIjF0XPGTukDoYuWDnjNAjYqhvwT65yhAOgPplzet/UTsXUB2Vdoe9A8yDcQeBMA87KvIEppqFMIDXIFz6mZGVEFnOX0OQVOS6drJW9o8VcEbjJVDOtdLc2kShRXeh1xi6y6spIOq0FWkvdTrtxaFsZYz4Oy5TXg2yFNv9WyB+uEvOhqEtVSn6G7p0855ph1tUbwcZdPeI5CPvH0YJSjhJGiY/11oS1DKsyfkLngqcYRRJpAU/2NbVXjUSl/lEM9VilldLRco8IliI1Gr5uw6S3vcIPaJauvf6/yTyUgcD1aZlQ+tj3D05Gr09WIwAla4eYfYq+5q4ZAkkUuMjJkNJwmyiCatwuOQSiTJUuIUVo3nXww0W0wEyTY61FlGqYC0tgjX3YiJaXCK+F6QBoxN7YyOEo21ueqp9XL8yIPvQg9Dxw+Qg6DALUk+mKI5tS9SVFVT9jrMYDUwcTpcRSpCY7cK90IYm+Yt/4W+9MMxVWRrOAuSFgRm2II9ZFCYZSJDKBCgnDR+LmkXuKmNhkjrqvH8ne7YDphrvYKm4zM0sjownT2NX8gBJqgOngZv3e30SI3Q5hcybweKs5vOVMi3vD2IoXC1Re7jOstpGCSIK2nilFRq5tWxtMV3xqDE7l96bL+fufnFg2lfEZmCeCPo63zCDNDexzAo1HoKpHEBdTB+MKvLRtxd4B1NLp/Vo2u8RV9l5dj/XIxR3EfcfO1Ntg/xEg3sw3LkciPOrD4vsGtxkYcNh0lSr+TI9TgEjj2ftzgSbJ2viy/qvmXo= X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2235; 5:B5hzr39mFgxiDCyJPUJ+tXHrLwqXlNozKcP/QI+Y9RD+bVLcbtolG44HGS4wJmGrxoAQHE6cBjEa3d+pH/nzdRG2pM/SmRrvqYxKeivZW3oGKsTHbSrzXrJ+yaFXLiiUGWclHwvmYTfSr7DmOke1RA==; 24:LN+Dop0r7B2SooNGLrvUIPX25+ppPVsMPh2yxqDA3hBoq/ZgOKmsWjOdMKUxehAs1M8wLTYJ1cdQN2xtwwrEVFIeilbK7+y4vB5Sbmd3W04=; 7:npnn60ru3KgtmOCX03E6yy4SGBK46II3JNMMA1lmAY/AYVQChhK/iDsl4C+mvrxEoGt/TNrC/Be02Gq9jLr4L1Lp5E+b25cBJXxnZrAnHEI1kSyBlRBoKlNp2eEe7NHw/RJpUBr7H1djfEDnmUF0qzwFjyMHcX66/V+ZzvvvxB+GEZiH5PHnvbu4TBdAYeRq SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2016 00:06:09.5738 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2235 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160523_170632_159573_A9E81137 X-CRM114-Status: GOOD ( 11.07 ) 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, 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, schwidefsky@de.ibm.com, bamvor.zhangjian@huawei.com, philipp.tomsich@theobroma-systems.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-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;