From patchwork Sun Jul 16 03:56:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 789030 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x9Dqx60H5z9s4s for ; Sun, 16 Jul 2017 15:04:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="odhpV74h"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3x9Dqx4pwRzDr17 for ; Sun, 16 Jul 2017 15:04:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="odhpV74h"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3x9CNd6bFHzDqmQ for ; Sun, 16 Jul 2017 13:59:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="odhpV74h"; dkim-atps=neutral Received: by mail-qk0-x244.google.com with SMTP id a66so16022866qkb.0 for ; Sat, 15 Jul 2017 20:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=UR8XPDglxyzKMbYORmg3ILv0sH/mR1ESr7o97MGEUCI=; b=odhpV74hICV1LySyG/qWte+Olz0TkqrQeeqGnEHmZrH13CMe1j4Mgd+IlvRlbzYU2a cSSdmY8R9fDKngjCVAI4SivoErvApMOEcwlsHNzn9gizugEc1E6ZE4mNETDzLRVCMdqU HtvHLlc8XaZGnc723kOztHF8ubvQNcBNkINAUW5WCDpYIIaIrnydD9omqFPkxelSV2P2 WfnurabuTjsHSzv46mZkD5+YS/kOroAAuCMeb0mB2gvo4STE4Gdawg9u4kbOZeox2+WP 8hqPoTfy7gVOx9zAZqNXLaDDNYxRUqRY32XEoabJ6SHBetuCHOKchcjcVSQ9ad8I6daB cTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=UR8XPDglxyzKMbYORmg3ILv0sH/mR1ESr7o97MGEUCI=; b=rLTN8+TkgZpKeZii24nA1H0ucBuoopzJtnW/4O7OCmoqCAXxdx1oQ9mD+w4FvEOiI7 R6yDhsl72BG/iv2t6HUii2B2rEQOfqud6whM3XzjrhuM7L0+JgXyIpXvmjysgu7LuenB BeGy2ESul3NSZO16eJhK9LVK22a0SY67ToAK80MTSh6ao49Hr2oqfHJl6Lp8LnS34Amf K/7AzwIj3uRATAKWnNBmMlz525kHg50eKrKYnGz/T8l5D9s1CLZs7Z9172AVpgdSz/tS iZR1E8/OhHTk9FEd2OVeJH5EnIzLOU/T2Wp4Yj4V59LkLXRYXuwugtp51AbUVB9TW4+V VYRw== X-Gm-Message-State: AIVw110tmPI9Mfy6Cdf4AqLQZGNeMDioT6ZmFCbaQpec9Hiol1r9MZER xXsIRt1tr6C45thTBMc= X-Received: by 10.55.5.131 with SMTP id 125mr20501684qkf.28.1500177567927; Sat, 15 Jul 2017 20:59:27 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id q46sm2290345qtc.54.2017.07.15.20.59.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jul 2017 20:59:27 -0700 (PDT) From: Ram Pai To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC v6 35/62] powerpc: Deliver SEGV signal on pkey violation Date: Sat, 15 Jul 2017 20:56:37 -0700 Message-Id: <1500177424-13695-36-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> References: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arnd@arndb.de, corbet@lwn.net, linuxram@us.ibm.com, mhocko@kernel.org, dave.hansen@intel.com, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The value of the AMR register at the time of exception is made available in gp_regs[PT_AMR] of the siginfo. The value of the pkey, whose protection got violated, is made available in si_pkey field of the siginfo structure. Signed-off-by: Ram Pai --- arch/powerpc/include/uapi/asm/ptrace.h | 1 + arch/powerpc/kernel/signal_32.c | 5 +++++ arch/powerpc/kernel/signal_64.c | 4 ++++ arch/powerpc/kernel/traps.c | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/uapi/asm/ptrace.h b/arch/powerpc/include/uapi/asm/ptrace.h index 8036b38..fc9c9c0 100644 --- a/arch/powerpc/include/uapi/asm/ptrace.h +++ b/arch/powerpc/include/uapi/asm/ptrace.h @@ -110,6 +110,7 @@ struct pt_regs { #define PT_RESULT 43 #define PT_DSCR 44 #define PT_REGS_COUNT 44 +#define PT_AMR 45 #define PT_FPR0 48 /* each FP reg occupies 2 slots in this space */ diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c index 97bb138..9c4a7f3 100644 --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -500,6 +500,11 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame, (unsigned long) &frame->tramp[2]); } +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS + if (__put_user(get_paca()->paca_amr, &frame->mc_gregs[PT_AMR])) + return 1; +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ + return 0; } diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c index c83c115..86a4262 100644 --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -174,6 +174,10 @@ static long setup_sigcontext(struct sigcontext __user *sc, if (set != NULL) err |= __put_user(set->sig[0], &sc->oldmask); +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS + err |= __put_user(get_paca()->paca_amr, &sc->gp_regs[PT_AMR]); +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ + return err; } diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index d4e545d..fe1e7c7 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -247,6 +248,15 @@ void user_single_step_siginfo(struct task_struct *tsk, info->si_addr = (void __user *)regs->nip; } +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS +static void fill_sig_info_pkey(int si_code, siginfo_t *info, unsigned long addr) +{ + if (si_code != SEGV_PKUERR) + return; + info->si_pkey = get_paca()->paca_pkey; +} +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ + void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) { siginfo_t info; @@ -274,6 +284,11 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) info.si_signo = signr; info.si_code = code; info.si_addr = (void __user *) addr; + +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS + fill_sig_info_pkey(code, &info, addr); +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ + force_sig_info(signr, &info, current); }