From patchwork Thu Jan 7 23:34:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 7980751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9FDEFBEEE5 for ; Thu, 7 Jan 2016 23:47:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7478A20149 for ; Thu, 7 Jan 2016 23:47:18 +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 45E352010E for ; Thu, 7 Jan 2016 23:47:17 +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 1aHKFG-0001uI-6B; Thu, 07 Jan 2016 23:45:30 +0000 Received: from mail-bn1bon0065.outbound.protection.outlook.com ([157.56.111.65] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aHKAz-0004Yd-5J for linux-arm-kernel@lists.infradead.org; Thu, 07 Jan 2016 23:41:45 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (95.143.213.121) by CO2PR07MB618.namprd07.prod.outlook.com (10.141.228.149) with Microsoft SMTP Server (TLS) id 15.1.361.13; Thu, 7 Jan 2016 23:40:42 +0000 From: Yury Norov To: , , , Subject: [PATCH v6 18/21] arm64: ilp32: introduce ilp32-specific handlers for sigframe Date: Fri, 8 Jan 2016 02:34:36 +0300 Message-ID: <1452209679-19445-19-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452209679-19445-1-git-send-email-ynorov@caviumnetworks.com> References: <1452209679-19445-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM3PR01CA047.eurprd01.prod.exchangelabs.com (10.141.191.37) To CO2PR07MB618.namprd07.prod.outlook.com (10.141.228.149) X-Microsoft-Exchange-Diagnostics: 1; CO2PR07MB618; 2:hJdrrKd6Hjnv8mJ6npcRpCRAsGszpzopHEOFGWF1ssduh9GKqN44Gxxk+ffIrRFmjGcxiyl8hR0ycalghlwVYjQo7xsLZnLhYawAGafKKMUS30eBzfMjNGZEOtqYoo9z4TvwnQgX02JJcd9OAIu4aQ==; 3:+NTrZAtgeDygU7NG9ExqsphU30V/TADyqP+y2BKjEozs6tNqsysJzm6xngo/z1Y0KvnTpRt0vcUAMzWtOSkcr90+lm4IN+w+xvuulrZEcQ23hFAc0hBYwXa2GiUnmJT/; 25:ntKml36tWDG7gfaxulK9sNu5nDCg66fd7aye9tPHaGSWYMfaC/YStkLslOI57FBvU4D4k0s1yMfVOjRY46L9Mc7ZM+mafiEgAmnWPHXNR5uJbMKdBTMUS8W3SyM9yTbsvIz5f+UBYuDMOsy/LMiGsRF/9CfnMYya4+JlriJ++lPj3dV4+9bormsB1AQSLHz3EOHB6ZoWQ9GWqjUvleWXd7el9i9IgA8X+wC+2kLC5utxszvdI7vbjf//BROez04n X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR07MB618; X-MS-Office365-Filtering-Correlation-Id: fd7fd6fb-81ad-4d29-0ce5-08d317bbf532 X-Microsoft-Exchange-Diagnostics: 1; CO2PR07MB618; 20:JpHB0bmZ1FTxJfxMxeR/6WpPnDcDcUwwXX16Z6jZGGo0nMqNEmFNz6y4xQphnfqX3Nul60/DuRzLvXqAZiV23RhKtPlCtniBEx0D9SfroWd4wqQy37+u45yYMYgBta/9rA8Ab+FEe+ioemyjILOXSIyXjg1IW3BGlfG7zCkixcZW75tkhNebI7wIzOzL5CPqVWcuCf5noRx5z8lz/Q3Dqvym+DHOfiO5lTVC7Nmr0o23DYzhnt1ifPGfn1oUk4HAMyRA7ozqfuYF5mEXdVKfTjKBA3k3N8c4sN6FRsf+bjW6j2YmU4kJ/pxLOl8f4NZ/WbbZvgpwgeBzhcivIY7gKA3783mDw5Lj4WLiXMITPAUuhak8sD3KVvNjaQq78dZwXRunH9ggDR9aGokCIIRRcyP3x3fOE4oDg9DTaL4nv5UqZ8A8pcno0P257lrz8kvy+3Xce0gb8lwQ5UleMQR8y0m+MljxXbQGgomPbmWu2ZFclM8Kt4O6TSsn2n6NQN2Slhq9wqjtcIITuINZkL6rqP4+Jl6w+iLMNyv3PqpoFfaSw0ixZoKgikFtjBeKrS/Y4rLjl9eDaCTvcQhJW0+rxQleLtMEmB1oY00YADB/IY0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001); SRVR:CO2PR07MB618; BCL:0; PCL:0; RULEID:; SRVR:CO2PR07MB618; X-Microsoft-Exchange-Diagnostics: 1; CO2PR07MB618; 4:H3ANyfENzsWlct+fyUsvaqckpL3cQzXWeWrHe1oI8fIu0Y/+5Y2sM2O7pdbKr+WLEAS6QC/ILCSBbIlcy7a8VkVs7lOx7a/7bHXgojvNmqN8ZrlqI2kDr2c6V0BBkTT5tk2Z8SstieaJwg6efGzoWWmauwhZFaYqLVQPwwbidehPkdUtFeY7KZNlzgDMs34tPm2B8+hPtKGX6y4H22xIupPcANmQVUUZleddbGPEWQfaduZgMqpRvhUyZrMgko3490aL1DTb8wi1Lv6gNUyxhv6TZF6Ue2b8jTQRzTtbbz7DolPIBzvP/NyzKe/ckmQGufcoWIKeApCKOTpj2kc6ruf7PGR4mMKCootZlerG0iMTdQuK71iAWYytJ5evseY7FjF+pQrxOy7zvCpGsG0rE7XuEqKz/EimxAfAGoGFQJX5GirMKeU8LAuYu5X43Oke X-Forefront-PRVS: 0814A2C7A3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(199003)(189002)(43544003)(19580405001)(33646002)(3846002)(42186005)(87976001)(101416001)(50986999)(5004730100002)(106356001)(36756003)(122386002)(586003)(2906002)(5001770100001)(76506005)(92566002)(15975445007)(19580395003)(4326007)(77096005)(76176999)(48376002)(81156007)(5001960100002)(2950100001)(189998001)(40100003)(66066001)(105586002)(6116002)(5008740100001)(47776003)(50466002)(97736004)(229853001)(1096002)(50226001)(2201001)(5003940100001)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR07MB618; 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; CO2PR07MB618; 23:TBEfOXAAEo6gVuadDlos3pbscNiALXNjAADTjYrhng?= =?us-ascii?Q?tv9JkiGafCxXX8anMOCGjEHrMJhk0rgVmaVLcHOJBMrXVymUIcxN4BRafljW?= =?us-ascii?Q?3zU1qnvSanLkcKwYseEFWiXHScHxYhu47mq4MhXvf3AJ8gZWWh2NUj8N5z6y?= =?us-ascii?Q?ZkydrOBnCzjgpWtNjs76Jt69IhtrZSqj8qRcszHWw7V0JwZKjGidwsVk+A3I?= =?us-ascii?Q?uKVLj2K7httB/3VU3thuJ8rp3vxjJne56f2zDhplUrW4kr7BkFQmAFYYNE/8?= =?us-ascii?Q?/lI0GwKonfKBv61aus/LFiUQDooVkl3F0w4htkgU8p3sR/QRXNvp9JBrCK/v?= =?us-ascii?Q?zIdpUI/HkToADegzld8Myl6kBvEDPs1XsNswRhGRikeKa0eConzn2lsIfRDE?= =?us-ascii?Q?iH2APikCl5rzG9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M56k1Hg+/Fp2tIte9m6VcerqhiKY5+uV0WFA6z6pX2Pmwepz6FaavFyWDz6QeXRRaf/Y7DtalkHqReWd2rHK8A==; 24:iAoc6vFm6+eTFCSbmz9kOLaaToYveRssOk6DrG3hYOvJmPhefciJn2GwRxUF93xAVnnzK9GMwUN78JEQGxhoWrVrq2TxIg5cA+OLLIVOIok= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2016 23:40:42.5174 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR07MB618 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160107_154106_277228_DF5FC60B X-CRM114-Status: GOOD ( 18.01 ) 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: pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, Nathan_Lynch@mentor.com, agraf@suse.de, klimov.linux@gmail.com, ynorov@caviumnetworks.com, jan.dakinevich@gmail.com, ddaney.cavm@gmail.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-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 ILP32 uses AARCH32 compat structures and syscall handlers for signals. But ILP32 struct rt_sigframe differs from both LP64 and AARCH32. So some specific mechanism is needed to take care of it. Signed-off-by: Yury Norov --- arch/arm64/include/asm/signal_ilp32.h | 34 +++++++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/entry_ilp32.S | 23 ++++++ arch/arm64/kernel/signal.c | 3 + arch/arm64/kernel/signal_ilp32.c | 128 ++++++++++++++++++++++++++++++++++ arch/arm64/kernel/sys_ilp32.c | 3 + 6 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/signal_ilp32.h create mode 100644 arch/arm64/kernel/entry_ilp32.S create mode 100644 arch/arm64/kernel/signal_ilp32.c diff --git a/arch/arm64/include/asm/signal_ilp32.h b/arch/arm64/include/asm/signal_ilp32.h new file mode 100644 index 0000000..30eff23 --- /dev/null +++ b/arch/arm64/include/asm/signal_ilp32.h @@ -0,0 +1,34 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __ASM_SIGNAL_ILP32_H +#define __ASM_SIGNAL_ILP32_H + +#ifdef CONFIG_ARM64_ILP32 + +#include + +int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, + struct pt_regs *regs); + +#else + +static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, + struct pt_regs *regs) +{ + return -ENOSYS; +} + +#endif /* CONFIG_ARM64_ILP32 */ + +#endif /* __ASM_SIGNAL_ILP32_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 4981933..c846626 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -28,7 +28,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o entry32.o \ ../../arm/kernel/opcodes.o binfmt_elf32.o -arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o sys_ilp32.o +arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o sys_ilp32.o \ + signal_ilp32.o entry_ilp32.o arm64-obj-$(CONFIG_COMPAT) += signal32_common.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S new file mode 100644 index 0000000..5063172 --- /dev/null +++ b/arch/arm64/kernel/entry_ilp32.S @@ -0,0 +1,23 @@ +/* + * ILP32 system call wrappers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +ENTRY(ilp32_sys_rt_sigreturn_wrapper) + mov x0, sp + b ilp32_sys_rt_sigreturn +ENDPROC(ilp32_sys_rt_sigreturn_wrapper) + diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a742a61..f8d4c92 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -35,6 +35,7 @@ #include #include #include +#include /* * Do a signal return; undo the signal stack. These are aligned to 128-bit. @@ -300,6 +301,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) ret = compat_setup_rt_frame(usig, ksig, oldset, regs); else ret = compat_setup_frame(usig, ksig, oldset, regs); + } else if (is_ilp32_compat_task()) { + ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs); } else { ret = setup_rt_frame(usig, ksig, oldset, regs); } diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c new file mode 100644 index 0000000..b635a21 --- /dev/null +++ b/arch/arm64/kernel/signal_ilp32.c @@ -0,0 +1,128 @@ +/* + * Based on arch/arm/kernel/signal.c + * + * Copyright (C) 1995-2009 Russell King + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 2016 Cavium Networks. + * Yury Norov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +struct ilp32_rt_sigframe { + struct compat_siginfo info; + struct sigframe sig; +}; + +asmlinkage int ilp32_sys_rt_sigreturn(struct pt_regs *regs) +{ + struct ilp32_rt_sigframe __user *frame; + + /* Always make any pending restarted system calls return -EINTR */ + current->restart_block.fn = do_no_restart_syscall; + + /* + * Since we stacked the signal on a 128-bit boundary, + * then 'sp' should be word aligned here. If it's + * not, then the user is trying to mess with us. + */ + if (regs->sp & 15) + goto badframe; + + frame = (struct ilp32_rt_sigframe __user *)regs->sp; + + if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) + goto badframe; + + if (restore_sigframe(regs, &frame->sig)) + goto badframe; + + if (restore_altstack(&frame->sig.uc.uc_stack)) + goto badframe; + + return regs->regs[0]; + +badframe: + if (show_unhandled_signals) + pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n", + current->comm, task_pid_nr(current), __func__, + regs->pc, regs->compat_sp); + force_sig(SIGSEGV, current); + return 0; +} + +static struct ilp32_rt_sigframe __user *ilp32_get_sigframe(struct ksignal *ksig, + struct pt_regs *regs) +{ + unsigned long sp, sp_top; + struct ilp32_rt_sigframe __user *frame; + + sp = sp_top = sigsp(regs->sp, ksig); + + sp = (sp - sizeof(struct ilp32_rt_sigframe)) & ~15; + frame = (struct ilp32_rt_sigframe __user *)sp; + + /* + * Check that we can actually write to the signal frame. + */ + if (!access_ok(VERIFY_WRITE, frame, sp_top - sp)) + frame = NULL; + + return frame; +} + +/* + * ILP32 signal handling routines called from signal.c + */ +int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, + sigset_t *set, struct pt_regs *regs) +{ + struct ilp32_rt_sigframe __user *frame; + int err = 0; + + frame = ilp32_get_sigframe(ksig, regs); + + if (!frame) + return 1; + + __put_user_error(0, &frame->sig.uc.uc_flags, err); + __put_user_error(NULL, &frame->sig.uc.uc_link, err); + + err |= __save_altstack(&frame->sig.uc.uc_stack, regs->sp); + err |= setup_sigframe(&frame->sig, regs, set); + if (err == 0) { + setup_return(regs, &ksig->ka, frame, + offsetof(struct ilp32_rt_sigframe, sig), usig); + if (ksig->ka.sa.sa_flags & SA_SIGINFO) { + err |= copy_siginfo_to_user32(&frame->info, &ksig->info); + regs->regs[1] = (unsigned long)&frame->info; + regs->regs[2] = (unsigned long)&frame->sig.uc; + } + } + + return err; +} + diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c index 71912b0..acc7961 100644 --- a/arch/arm64/kernel/sys_ilp32.c +++ b/arch/arm64/kernel/sys_ilp32.c @@ -46,6 +46,9 @@ asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long fd, off_t off); #define sys_mmap2 sys_mmap +asmlinkage long ilp32_sys_rt_sigreturn_wrapper(void); +#define compat_sys_rt_sigreturn ilp32_sys_rt_sigreturn_wrapper + #include #undef __SYSCALL