From patchwork Mon May 14 17:14:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 135743 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2049606lji; Mon, 14 May 2018 10:15:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoqzxXOAfyQPJ/RtfqEMEaGBwwrFqkPFHBU8lJbyyjgqJKUsD3rc31YdByuWhLAE0jp9oG4 X-Received: by 2002:a62:da17:: with SMTP id c23-v6mr11492176pfh.128.1526318133447; Mon, 14 May 2018 10:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526318133; cv=none; d=google.com; s=arc-20160816; b=cXrkjWOqupwHF3T6/9LuEyJD2lk4DGJC36Miqr96KtIFBTwUoI8ecno1cHRc1VF9e1 JUqr3O5I72VJoLMaq8nwCtKtInBs49h1TYAR0Dl8ky7NrgEzs0WzFpc5rRtFmDQFIprQ VH5LuEx20gUzAkak/WBtGqNE3OqO48bvRhcW0i45mDHWZRoqgJHtyjJ5OCkAonyZR+xH /IRtncLQljtCIgMooLEMiJdgkWEhCibl7bYQb093ijYnD2/u9asnMsGdUJvy2qaUhI/T viz1/8ITSeAI0ak5ckMvRTIDTVIr0b872DDOAW0MnqHlgHp+TkoHD03rCQ+YFGCjo7Xx dBhQ== 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:arc-authentication-results; bh=i7kcUAjX4hkCW1ZNZSv8o/lUaBteICz2MEzb1A7dwIA=; b=AuPGVcha2cFvcX32L5YUWSDubyQrG0DzIrMf4f/UVMbzwUjyOZScl3vCSF6Z0rGdNw LEG4b4OLZyFXSXDQ9+WmjJW/OAJYayfJWGEBb2gjPWoXKi2cwiUU1hoaM0GzhchzJdIO EEEWpPjug+N1lKD1tfveYbZV+/mA7GksEntj9kHMydqPJNdtWj7YzwziJS1W044wu5nz iLDzkWtWXRTAJ0QROIVGn5IFPtgQcGY4XQIeZ16UAvWz9/9OkXOEhbqkw0+GYJwwfb2K Dcr9fhgYhAkQLVHBOy66FADZeIDZXHcu//+EbO+F1AJ3YjIdD8d5KUFf1GId2w4TxhSs W+nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 w1-v6si7866340pgp.10.2018.05.14.10.15.33; Mon, 14 May 2018 10:15:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754066AbeENRP3 (ORCPT + 29 others); Mon, 14 May 2018 13:15:29 -0400 Received: from foss.arm.com ([217.140.101.70]:46922 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752856AbeENRPZ (ORCPT ); Mon, 14 May 2018 13:15:25 -0400 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 8244D1596; Mon, 14 May 2018 10:15:25 -0700 (PDT) Received: from e103592.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 2789C3F59F; Mon, 14 May 2018 10:15:22 -0700 (PDT) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, Andrew Morton , Benjamin Herrenschmidt , Catalin Marinas , Fenghua Yu , "H. Peter Anvin" , Ingo Molnar , Ivan Kokshaysky , James Hogan , Kees Cook , Matt Turner , Michael Ellerman , Paul Mackerras , Ralf Baechle , Richard Henderson , Rich Felker , Thomas Gleixner , Tony Luck , Will Deacon , x86@kernel.org, Yoshinori Sato Subject: [RFC PATCH 01/11] prctl: Support movement of arch prctls out of common code Date: Mon, 14 May 2018 18:14:17 +0100 Message-Id: <1526318067-4964-2-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1526318067-4964-1-git-send-email-Dave.Martin@arm.com> References: <1526318067-4964-1-git-send-email-Dave.Martin@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The core framework for the prctl() syscall is unloved and looking rather crusty these days. It also relies on defining ancillary boilerplate macros for each prctl() in order to control conditional compilation of the different prctl calls. We have better ways to do this now, using Kconfig. This patch defines a new arch hook arch_syscall(). Architectures that implemement arch-specific syscalls can now select HAVE_ARCH_SYSCALL in their Kconfig and define this function appropriately. The core prctl() implementation now matches option against the list of common or legacy prctls, deferring to prctl_arch() if an unrecognised option is encountered. (arch_prctl() would have been a nicer name, but it conflicts with the pre-existing syscall of the same name on x86, particularly in the um code.) No functional change. Signed-off-by: Dave Martin Cc: Andrew Morton Cc: Benjamin Herrenschmidt Cc: Catalin Marinas Cc: Fenghua Yu Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Ivan Kokshaysky Cc: James Hogan Cc: Kees Cook Cc: Matt Turner Cc: Michael Ellerman Cc: Paul Mackerras Cc: Ralf Baechle Cc: Richard Henderson Cc: Rich Felker Cc: Thomas Gleixner Cc: Tony Luck Cc: Will Deacon Cc: x86@kernel.org Cc: Yoshinori Sato --- arch/Kconfig | 3 +++ include/linux/prctl.h | 19 +++++++++++++++++++ include/uapi/linux/prctl.h | 6 +++--- kernel/sys.c | 2 +- tools/include/uapi/linux/prctl.h | 6 +++--- 5 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 include/linux/prctl.h -- 2.1.4 Acked-by: Will Deacon diff --git a/arch/Kconfig b/arch/Kconfig index 8e0d665..b34b3e8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -969,4 +969,7 @@ config REFCOUNT_FULL against various use-after-free conditions that can be used in security flaw exploits. +config HAVE_PRCTL_ARCH + bool + source "kernel/gcov/Kconfig" diff --git a/include/linux/prctl.h b/include/linux/prctl.h new file mode 100644 index 0000000..5ce3713 --- /dev/null +++ b/include/linux/prctl.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_PRCTL_H +#define _LINUX_PRCTL_H + +#include +#include + +#ifdef CONFIG_HAVE_PRCTL_ARCH +extern int prctl_arch(int option, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5); +#else +static inline int prctl_arch(int option, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5) +{ + return -EINVAL; +} +#endif + +#endif /* ! _LINUX_PRCTL_H */ diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index af5f8c2..c911ff0 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _LINUX_PRCTL_H -#define _LINUX_PRCTL_H +#ifndef _UAPI_LINUX_PRCTL_H +#define _UAPI_LINUX_PRCTL_H #include @@ -207,4 +207,4 @@ struct prctl_mm_map { # define PR_SVE_VL_LEN_MASK 0xffff # define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ -#endif /* _LINUX_PRCTL_H */ +#endif /* _UAPI_LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index ad69218..5077f1e 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2451,7 +2451,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = SVE_GET_VL(); break; default: - error = -EINVAL; + error = prctl_arch(option, arg2, arg3, arg4, arg5); break; } return error; diff --git a/tools/include/uapi/linux/prctl.h b/tools/include/uapi/linux/prctl.h index af5f8c2..c911ff0 100644 --- a/tools/include/uapi/linux/prctl.h +++ b/tools/include/uapi/linux/prctl.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _LINUX_PRCTL_H -#define _LINUX_PRCTL_H +#ifndef _UAPI_LINUX_PRCTL_H +#define _UAPI_LINUX_PRCTL_H #include @@ -207,4 +207,4 @@ struct prctl_mm_map { # define PR_SVE_VL_LEN_MASK 0xffff # define PR_SVE_VL_INHERIT (1 << 17) /* inherit across exec */ -#endif /* _LINUX_PRCTL_H */ +#endif /* _UAPI_LINUX_PRCTL_H */