From patchwork Mon Jan 22 21:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Weiser X-Patchwork-Id: 10179355 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 E9183600F5 for ; Mon, 22 Jan 2018 22:03:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7B0328531 for ; Mon, 22 Jan 2018 22:03:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD7F2855C; Mon, 22 Jan 2018 22:03:11 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20E6528531 for ; Mon, 22 Jan 2018 22:03:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=PdGacAJn8N1WPXkCzrm1aftB1TmiGE5A8eTlbQuw1LM=; b=UrQIJY/XjXWocO68OEPGWMaPT0 egk6N/Tp66jgzTXoCF8POYr+sbaMzAUjoTw1ZkSKFSmsjiLfHf5yBoxD4+ujLU9oiE3Nq/v1Me5+u 0Lirbn0HZRWInvZBQOFqy2b5/2PNj6ALZ5hLAuGwOPc4lXMNtEbSc2YcVVJffesboYKJxOvuiOPRn +D9R0pFE5G7+OJqPwQlItX86az2EbLlBTfS7vD/wSJXTxvKKWIpfKt0rVUQYuFZpQrv8y34osPrpV VCD+pcPePOgQ6KCr/K+qQkVwe1/NTj7ik0NTAnKfcrSdeJPwMsyo4Nlo4l+//MnM6OLBhCsA4J0kE 2QtV2iGg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1edkBH-0000dV-Vc; Mon, 22 Jan 2018 22:03:07 +0000 Received: from heinz.dinsnail.net ([2a01:238:43b4:3200:9392:5dcc:2f0e:a960]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1edkAt-00008P-Gp for linux-arm-kernel@lists.infradead.org; Mon, 22 Jan 2018 22:02:47 +0000 Received: from heinz.dinsnail.net ([IPv6:::1]) by heinz.dinsnail.net (8.14.9/8.14.9) with ESMTP id w0MLMcLq026210; Mon, 22 Jan 2018 22:22:38 +0100 Received: from eldalonde.UUCP (uucp@localhost) by heinz.dinsnail.net (8.14.9/8.14.9/Submit) with bsmtp id w0MLMcGC026205; Mon, 22 Jan 2018 22:22:38 +0100 Received: from rivendell.weiser.dinsnail.net (rivendell.weiser.dinsnail.net [IPv6:fdbc:1bbf:5341::1:8]) by eldalonde.weiser.dinsnail.net (8.14.9/8.14.9) with ESMTP id w0MLKf7x030841; Mon, 22 Jan 2018 22:20:41 +0100 Received: (from michael@localhost) by rivendell.weiser.dinsnail.net (8.14.9/8.14.9/Submit) id w0MLKgGc026312; Mon, 22 Jan 2018 22:20:42 +0100 From: Michael Weiser To: Will Deacon Subject: [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls Date: Mon, 22 Jan 2018 22:20:26 +0100 Message-Id: <20180122212026.26262-3-michael.weiser@gmx.de> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122212026.26262-1-michael.weiser@gmx.de> References: <20180122212026.26262-1-michael.weiser@gmx.de> In-Reply-To: <20180122131851.GA28638@arm.com> References: <20180122131851.GA28638@arm.com> X-dinsnail-net-MailScanner-Information: Please contact the ISP for more information X-dinsnail-net-MailScanner-ID: w0MLMcLq026210 X-dinsnail-net-MailScanner: Found to be clean X-dinsnail-net-MailScanner-From: michael@rivendell.weiser.dinsnail.net X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Weiser , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 Mirror arm behaviour for unimplemented syscalls: Below 2048 return -ENOSYS. Above 2048 raise SIGILL and print a ratelimited message with details. dump_instr() is made non-static and added to system_misc.h so it can be used in compat_arm_syscall(). Also it is synced with the arm implementation to support thumb instructions. Signed-off-by: Michael Weiser --- arch/arm64/include/asm/system_misc.h | 1 + arch/arm64/kernel/sys_compat.c | 27 ++++++++++++++++++++++++++- arch/arm64/kernel/traps.c | 14 ++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/system_misc.h b/arch/arm64/include/asm/system_misc.h index 07aa8e3c5630..0f73b6c1ca63 100644 --- a/arch/arm64/include/asm/system_misc.h +++ b/arch/arm64/include/asm/system_misc.h @@ -42,6 +42,7 @@ void hook_debug_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct mm_struct; extern void show_pte(unsigned long addr); extern void __show_regs(struct pt_regs *); +extern void dump_instr(const char *lvl, struct pt_regs *regs); extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c index 8b8bbd3eaa52..3a5b3809b671 100644 --- a/arch/arm64/kernel/sys_compat.c +++ b/arch/arm64/kernel/sys_compat.c @@ -27,6 +27,7 @@ #include #include +#include #include static long @@ -67,6 +68,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags) */ long compat_arm_syscall(struct pt_regs *regs) { + siginfo_t info; unsigned int no = regs->regs[7]; switch (no) { @@ -99,6 +101,31 @@ long compat_arm_syscall(struct pt_regs *regs) return 0; default: - return -ENOSYS; + /* + * Calls 9f00xx..9f07ff are defined to return -ENOSYS + * if not implemented, rather than raising SIGILL. This + * way the calling program can gracefully determine whether + * a feature is supported. + */ + if ((no & 0xffff) <= 0x7ff) + return -ENOSYS; + break; } + + if (show_unhandled_signals_ratelimited()) { + pr_err("[%d] %s: arm syscall %d\n", + task_pid_nr(current), current->comm, no); + dump_instr("", regs); + if (user_mode(regs)) + __show_regs(regs); + } + + info.si_signo = SIGILL; + info.si_errno = 0; + info.si_code = ILL_ILLTRP; + info.si_addr = (void __user *)instruction_pointer(regs) - + (compat_thumb_mode(regs) ? 2 : 4); + + arm64_notify_die("Oops - bad syscall(2)", regs, &info, no); + return 0; } diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 0ef28b7f6aa7..2ee511243140 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -67,16 +67,22 @@ static void dump_backtrace_entry(unsigned long where) static void __dump_instr(const char *lvl, struct pt_regs *regs) { unsigned long addr = instruction_pointer(regs); + const int thumb = compat_thumb_mode(regs); + const int width = thumb ? 4 : 8; char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str; int i; - for (i = -4; i < 1; i++) { + for (i = -4; i < 1 + !!thumb; i++) { unsigned int val, bad; - bad = get_user(val, &((u32 *)addr)[i]); + if (thumb) + bad = get_user(val, &((u16 *)addr)[i]); + else + bad = get_user(val, &((u32 *)addr)[i]); if (!bad) - p += sprintf(p, i == 0 ? "(%08x) " : "%08x ", val); + p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", + width, val); else { p += sprintf(p, "bad PC value"); break; @@ -85,7 +91,7 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) printk("%sCode: %s\n", lvl, str); } -static void dump_instr(const char *lvl, struct pt_regs *regs) +void dump_instr(const char *lvl, struct pt_regs *regs) { if (!user_mode(regs)) { mm_segment_t fs = get_fs();