From patchwork Thu Jan 3 18:13:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 154733 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp937083ljp; Thu, 3 Jan 2019 10:14:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Ybfu0YzThQUMdjs7wYyjctI7FpWX0bngTHg9G2DKkVVIw0v9Tz0f5/Ibt9QJqizbGU1IZ X-Received: by 2002:a62:9111:: with SMTP id l17mr49088358pfe.200.1546539245114; Thu, 03 Jan 2019 10:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546539245; cv=none; d=google.com; s=arc-20160816; b=DZOe4q15oiffxVBnFtmX7EWtqYviSwj56EoPg7TOoC50OYecU6ooVnPsYuE6zmhlJK EIBZEJN1a3OJKU8LfTg46jXhAapZuz+UlhVauKjXLwU9jgpqfYErkTOLxKSEIbJUx3NZ SUCAxRLaLQPQ88Y4fCT2ipPYjPuVp3U4Z926ZSWxJCZcsIaeFb64Aaov6zs10+rDOU8J e/4D86Wj/+5LazCdWWoiAbCS6LAD7I//VwINTTvVwbu+CmnUvgl4H7F6QJMMlz74sCUL XiKlI/iAt4IkXNr6uhfEWMf7OV47If9XAuUZ8++Ut00x3qVabg6wK+GBwuu7giDonBgt 460Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=OG06qj31qh4fZbr8L0CrK7e8me2BkjkHvgdVrOkI2Jc=; b=PYIvUdMLJQbwzgtKtiVtSoyZjeLgW0Kt2jEjVoo/2nL6p5WkFBzRLJnATCIZELO8t2 edcR0ro5EESDtyMFa9uZcflJsiiSAB9Z+Wu0E/zfWCKU6G85M7oddVQnNw76bXAoup6E lXmzLoxfg/W6b3QzYc2gGDEz37EnLwbJHNEr52dSNHP7luvUQ2faeiPk0WzMsUnnZmGp ID/d8KWCYYIE9UGUxzP6+BFVhDMTijFPlCzbkJKBwIfPOK/Fw0I8Uw9B6EMokwrN25MO zmpZruxOY8s+9Nd1xZ2tUtZEKrjRZIRUcRJPFFrI5//cizoHtlIsze5+8Ayl2uAAR9ng hvBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o13si4638572pgp.540.2019.01.03.10.14.04; Thu, 03 Jan 2019 10:14:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730784AbfACSOD (ORCPT + 15 others); Thu, 3 Jan 2019 13:14:03 -0500 Received: from foss.arm.com ([217.140.101.70]:54390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730675AbfACSOC (ORCPT ); Thu, 3 Jan 2019 13:14:02 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 88F5415BE; Thu, 3 Jan 2019 10:14:02 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 572713F706; Thu, 3 Jan 2019 10:14:02 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 8242D1AE09EC; Thu, 3 Jan 2019 18:14:02 +0000 (GMT) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Dave.Martin@arm.com, pihsun@chromium.org, Will Deacon , Subject: [PATCH 1/3] arm64: compat: Avoid sending SIGILL for unallocated syscall numbers Date: Thu, 3 Jan 2019 18:13:58 +0000 Message-Id: <1546539240-20647-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1546539240-20647-1-git-send-email-will.deacon@arm.com> References: <1546539240-20647-1-git-send-email-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The ARM Linux kernel handles the EABI syscall numbers as follows: 0 - NR_SYSCALLS-1 : Invoke syscall via syscall table NR_SYSCALLS - 0xeffff : -ENOSYS (to be allocated in future) 0xf0000 - 0xf07ff : Private syscall or -ENOSYS if not allocated > 0xf07ff : SIGILL Our compat code gets this wrong and ends up sending SIGILL in response to all syscalls greater than NR_SYSCALLS which have a value greater than 0x7ff in the bottom 16 bits. Fix this by defining the end of the ARM private syscall region and checking the syscall number against that directly. Update the comment while we're at it. Cc: Cc: Dave Martin Reported-by: Pi-Hsun Shih Signed-off-by: Will Deacon --- arch/arm64/include/asm/unistd.h | 5 +++-- arch/arm64/kernel/sys_compat.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) -- 2.1.4 diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index b13ca091f833..be66a54ee3a1 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -40,8 +40,9 @@ * The following SVCs are ARM private. */ #define __ARM_NR_COMPAT_BASE 0x0f0000 -#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE+2) -#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE+5) +#define __ARM_NR_compat_cacheflush (__ARM_NR_COMPAT_BASE + 2) +#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) +#define __ARM_NR_compat_syscall_end (__ARM_NR_COMPAT_BASE + 0x800) #define __NR_compat_syscalls 399 #endif diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c index 32653d156747..5972b7533fa0 100644 --- a/arch/arm64/kernel/sys_compat.c +++ b/arch/arm64/kernel/sys_compat.c @@ -102,12 +102,12 @@ long compat_arm_syscall(struct pt_regs *regs) default: /* - * Calls 9f00xx..9f07ff are defined to return -ENOSYS + * Calls 0xf0xxx..0xf07ff 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) + if (no < __ARM_NR_compat_syscall_end) return -ENOSYS; break; } From patchwork Thu Jan 3 18:13:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 154734 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp937092ljp; Thu, 3 Jan 2019 10:14:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN7AhgZ4sjqIsnaarioOjQpy7wJ5iEEHiRXrr1qewNzjBLAgHNeWnoxB4IfQfCqss7QtfVyE X-Received: by 2002:a63:314d:: with SMTP id x74mr17769992pgx.10.1546539245523; Thu, 03 Jan 2019 10:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546539245; cv=none; d=google.com; s=arc-20160816; b=sqms4A487vlb7Z0XYOkXZadLrEXMy9S0lK0YB4nFHR1xiPZlTPbCJFi7B4vfJS2IZj 0BYEZgXy7IX0f/hwLmGxL/QP6p4MPit8kf+VmdPJ0NdLPPEHaK/ddmrsoZP5anw9WX0F bB1Bq/yv/ovCfOU7HvE8717MLdTZdymEggyIX8PoxJIut41Lvoi7gqVeZyU0bfuWxj88 06rHeDaARWSswqhiA123FdJd39qVnmkhpk+NGzP72NnYZOlEVa9hA0Jsv5mdT+Akj8/n D4KOrJUNc1NP0VMOk7oJKGPOLUJkKkgiT5vhd9CnVCoO8nOdVr6Q+KeeHfO8wvD9Imj3 PVEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=pkI/yxCuiWyJOtVzUM/yCVgv8vRjRkwf2XqhpxKrx/w=; b=XUJr5BQiuriK/yplFtKj2SU3QzIt+gBCtOFGwizMXQckZFFfja+CXSGPGq3zR3aD2O NLGn8Xs6+JIoKqgs7wxGAORcqZi8b9nbctTexZLvSXh04GM+q0LDnoVNThfQTxZyRxUy J+5O42+wkjjGclcaMp2eVoG7vt13s45RN3sDjcE47mKn/DC4ItkHug6BDJZxybtaBF/J H2xaEFnwB4e0/ydun43VTPnhBq6LW7VoBxahz91AOc1aliFCZHgkQb8BetCaVwrA8fv4 OWiuoxFhHmD7nqAJBHpOG9/vFp5uf/OsVUFvrktTGDwSdH7GCGTXWj8yei8l5xzv/IgD +Rbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o13si4638572pgp.540.2019.01.03.10.14.05; Thu, 03 Jan 2019 10:14:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730675AbfACSOD (ORCPT + 15 others); Thu, 3 Jan 2019 13:14:03 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:54394 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730759AbfACSOD (ORCPT ); Thu, 3 Jan 2019 13:14:03 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9E44E15BF; Thu, 3 Jan 2019 10:14:02 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6C71A3F802; Thu, 3 Jan 2019 10:14:02 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 92B741AE0C51; Thu, 3 Jan 2019 18:14:02 +0000 (GMT) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: Dave.Martin@arm.com, pihsun@chromium.org, Will Deacon , Subject: [PATCH 2/3] arm64: compat: Don't pull syscall number from regs in arm_compat_syscall Date: Thu, 3 Jan 2019 18:13:59 +0000 Message-Id: <1546539240-20647-3-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1546539240-20647-1-git-send-email-will.deacon@arm.com> References: <1546539240-20647-1-git-send-email-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The syscall number may have been changed by a tracer, so we should pass the actual number in from the caller instead of pulling it from the saved r7 value directly. Cc: Cc: Dave Martin Cc: Pi-Hsun Shih Signed-off-by: Will Deacon --- arch/arm64/kernel/sys_compat.c | 9 ++++----- arch/arm64/kernel/syscall.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) -- 2.1.4 Reviewed-by: Dave Martin diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c index 5972b7533fa0..54c29cd38ff9 100644 --- a/arch/arm64/kernel/sys_compat.c +++ b/arch/arm64/kernel/sys_compat.c @@ -66,12 +66,11 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags) /* * Handle all unrecognised system calls. */ -long compat_arm_syscall(struct pt_regs *regs) +long compat_arm_syscall(struct pt_regs *regs, int scno) { - unsigned int no = regs->regs[7]; void __user *addr; - switch (no) { + switch (scno) { /* * Flush a region from virtual address 'r0' to virtual address 'r1' * _exclusive_. There is no alignment requirement on either address; @@ -107,7 +106,7 @@ long compat_arm_syscall(struct pt_regs *regs) * way the calling program can gracefully determine whether * a feature is supported. */ - if (no < __ARM_NR_compat_syscall_end) + if (scno < __ARM_NR_compat_syscall_end) return -ENOSYS; break; } @@ -116,6 +115,6 @@ long compat_arm_syscall(struct pt_regs *regs) (compat_thumb_mode(regs) ? 2 : 4); arm64_notify_die("Oops - bad compat syscall(2)", regs, - SIGILL, ILL_ILLTRP, addr, no); + SIGILL, ILL_ILLTRP, addr, scno); return 0; } diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 032d22312881..5610ac01c1ec 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -13,16 +13,15 @@ #include #include -long compat_arm_syscall(struct pt_regs *regs); - +long compat_arm_syscall(struct pt_regs *regs, int scno); long sys_ni_syscall(void); -asmlinkage long do_ni_syscall(struct pt_regs *regs) +static long do_ni_syscall(struct pt_regs *regs, int scno) { #ifdef CONFIG_COMPAT long ret; if (is_compat_task()) { - ret = compat_arm_syscall(regs); + ret = compat_arm_syscall(regs, scno); if (ret != -ENOSYS) return ret; } @@ -47,7 +46,7 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno, syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)]; ret = __invoke_syscall(regs, syscall_fn); } else { - ret = do_ni_syscall(regs); + ret = do_ni_syscall(regs, scno); } regs->regs[0] = ret;