Received: by 10.223.164.202 with SMTP id h10csp13574wrb; Mon, 6 Nov 2017 01:34:21 -0800 (PST) X-Google-Smtp-Source: ABhQp+RKSTgkxwgbflb3W2KXOJUZ8aFfnxKwnbhyOnyi0UaHhN6kNfWkioyuxsfgkJaIdj5j3spE X-Received: by 10.101.90.13 with SMTP id y13mr14964903pgs.235.1509960861178; Mon, 06 Nov 2017 01:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509960861; cv=none; d=google.com; s=arc-20160816; b=W0zfoxaAFIgVl6tyq4g3LZBh3uVvpzj886Z4XX5qJeenktnzEteKhORhKtwcDfZVaB fIXZkMSuqG6PWY/Khlmj9INKFeKSwimxHBv1nHic1guXQnpor5iKqw83RO6INGcJjAF4 9lvPapVXFMVXOTaBZKlhqs7//RHEkNnLHPmqvD4DlBHkvdsoKDxRtJqr4QTpSpg9eDuO UajmnUrlsOs4AxsxH90PzUlTxry/jJYrl2/5qqN7F+lo1iuzMFzbgzeLni2zmxFx7zUC VVwFdG1tNFmdfJEoKWuXeTqqHyzOvlwX/VfiSMu0+7TUiN14mYR4GRQm1bMR81vIzuaz lBOQ== 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:dkim-signature:arc-authentication-results; bh=23595Mb75LDgee3M8YfkN9D4MUXeLpV8VmKLmm3LgwU=; b=dTzHGhocM7gGO43gLTvbFRDBtZ1H+s9K0CmyadPGsUqqDDrU0WLYuYx2wcXRREMUlW YQjNR4Baav/vzPBKrrX6Y/xYUiRf2jdhDubptktYRV+QnFGMeiZMPxJGP9pACJHFw/aj bdGSNhNocz5xuOOviQKXrtqub4lgllXKUEVFzJZ4hAYd/u1kA7eewQfgdX6JFpv+Ewdw E+2qA10dYcerXNleSYNYFRC93HiJaWnrdWLcTurrfDCgvhHxyLMArwRjQdrmHLcr581d rw8lce6pqs5FTQvww+ag2RQ9ooh69U7sQp38jeAdlZmRWW5zWqywNx+5AsX/x+IVQ5jo UXXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RvBx1HYz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si12315530pfc.18.2017.11.06.01.34.07; Mon, 06 Nov 2017 01:34:21 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RvBx1HYz; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751979AbdKFJdb (ORCPT + 98 others); Mon, 6 Nov 2017 04:33:31 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:43550 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752310AbdKFI7U (ORCPT ); Mon, 6 Nov 2017 03:59:20 -0500 Received: by mail-qt0-f196.google.com with SMTP id j58so10029555qtj.0; Mon, 06 Nov 2017 00:59:19 -0800 (PST) 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=23595Mb75LDgee3M8YfkN9D4MUXeLpV8VmKLmm3LgwU=; b=RvBx1HYz44e4J+06PMW0oGbTARwdMl9uyDQuGnh17iC2wX/nM6Ylx/eTxtl/FtUJp5 4tVvWJ9hCUvNZ91xebl3Ph15NKmxUdKtZCTO2Y+8XJK7ZlzOIcwkZ3Ve2tImT6wRf8h0 HIshwDK0dkosd9v5i32h/lj3yNeZdkoBLS28PLv2zAaEocvdZTIZCcqoBDaXWu5RNdg8 W9corWW7tLw+KeG0JSasCgQeL8AukyzXqPcsiJfcqxGdugXnA5FAfojMP9I/KQslPAdg JXhBiwaE9/xXQKJnyNfH13WbRZ8oAwVN2103ld7qu+rnmKI6Dybhq5c22mT9F3xUBcJ1 Cuog== 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=23595Mb75LDgee3M8YfkN9D4MUXeLpV8VmKLmm3LgwU=; b=ROfYSvL6RkA/YQxAlXLmbr1LcsZ3IZ6lobbRT1Xa8jC8nXITxFIw2Ijm7L3AIg4LWj qA7KPVzqR2pIq9l52TO7WOjBJQXUgJMUI4lW+G8Gb5/JL8eBiYp7CzPNjkppxJPSXZgZ 8IUhXD8Xc764BhNm+Y8HtTy92vI1z546KxnIVrbf5CZKdLTqgITkQVxMIenSw4jalMUs e1cjCU8wbAKCKvEt2CMBdo9aEhk0eWFl7H6MZB1JcA63BDNTbdblAMdJzZsRtpYFwlmT Pu2Tz0FPsv9v1FaUuDu+SOhxjNMowBW5hfK8QlnckP8BkxI6k7v4ToD+Svo9ORhUDBeQ uR1w== X-Gm-Message-State: AMCzsaWtRP0A2OOSsl72IIYxIfIuIdkBIz2b4nNTllsoZj80qUyYBnGJ D4fA0ogRJ1+e4RUlJVI4IkI= X-Received: by 10.237.55.102 with SMTP id i93mr22959567qtb.333.1509958759304; Mon, 06 Nov 2017 00:59:19 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:18 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com Subject: [PATCH v9 21/51] powerpc: Deliver SEGV signal on pkey violation Date: Mon, 6 Nov 2017 00:57:13 -0800 Message-Id: <1509958663-18737-22-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/asm/bug.h | 1 + arch/powerpc/kernel/traps.c | 12 ++++++++- arch/powerpc/mm/fault.c | 55 ++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h index 3c04249..97c3847 100644 --- a/arch/powerpc/include/asm/bug.h +++ b/arch/powerpc/include/asm/bug.h @@ -133,6 +133,7 @@ extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long); extern void bad_page_fault(struct pt_regs *, unsigned long, int); extern void _exception(int, struct pt_regs *, int, unsigned long); +extern void _exception_pkey(int, struct pt_regs *, int, unsigned long, int); extern void die(const char *, struct pt_regs *, long); extern bool die_will_crash(void); diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 13c9dcd..ed1c39b 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -265,7 +266,9 @@ void user_single_step_siginfo(struct task_struct *tsk, info->si_addr = (void __user *)regs->nip; } -void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) + +void _exception_pkey(int signr, struct pt_regs *regs, int code, unsigned long addr, + int key) { siginfo_t info; const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ @@ -292,9 +295,16 @@ 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; + info.si_pkey = key; + force_sig_info(signr, &info, current); } +void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) +{ + _exception_pkey(signr, regs, code, addr, 0); +} + void system_reset_exception(struct pt_regs *regs) { /* diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index dfcd0e4..84523ed 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -107,7 +107,8 @@ static bool store_updates_sp(struct pt_regs *regs) */ static int -__bad_area_nosemaphore(struct pt_regs *regs, unsigned long address, int si_code) +__bad_area_nosemaphore(struct pt_regs *regs, unsigned long address, int si_code, + int pkey) { /* * If we are in kernel mode, bail out with a SEGV, this will @@ -117,17 +118,18 @@ static bool store_updates_sp(struct pt_regs *regs) if (!user_mode(regs)) return SIGSEGV; - _exception(SIGSEGV, regs, si_code, address); + _exception_pkey(SIGSEGV, regs, si_code, address, pkey); return 0; } static noinline int bad_area_nosemaphore(struct pt_regs *regs, unsigned long address) { - return __bad_area_nosemaphore(regs, address, SEGV_MAPERR); + return __bad_area_nosemaphore(regs, address, SEGV_MAPERR, 0); } -static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code) +static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code, + int pkey) { struct mm_struct *mm = current->mm; @@ -137,30 +139,18 @@ static int __bad_area(struct pt_regs *regs, unsigned long address, int si_code) */ up_read(&mm->mmap_sem); - return __bad_area_nosemaphore(regs, address, si_code); + return __bad_area_nosemaphore(regs, address, si_code, pkey); } static noinline int bad_area(struct pt_regs *regs, unsigned long address) { - return __bad_area(regs, address, SEGV_MAPERR); + return __bad_area(regs, address, SEGV_MAPERR, 0); } -static int bad_page_fault_exception(struct pt_regs *regs, unsigned long address, - int si_code) +static int bad_key_fault_exception(struct pt_regs *regs, unsigned long address, + int pkey) { - int sig = SIGBUS; - int code = BUS_OBJERR; - -#ifdef CONFIG_PPC_MEM_KEYS - if (si_code & DSISR_KEYFAULT) { - perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); - sig = SIGSEGV; - code = SEGV_PKUERR; - } -#endif /* CONFIG_PPC_MEM_KEYS */ - - _exception(sig, regs, code, address); - return 0; + return __bad_area_nosemaphore(regs, address, SEGV_PKUERR, pkey); } static int do_sigbus(struct pt_regs *regs, unsigned long address, @@ -411,7 +401,16 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, if (unlikely(page_fault_is_bad(error_code))) { if (!is_user) return SIGBUS; - return bad_page_fault_exception(regs, address, error_code); + + if (error_code & DSISR_KEYFAULT) { + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, + address); + return bad_key_fault_exception(regs, address, + get_mm_addr_key(current->mm, address)); + } + + _exception_pkey(SIGBUS, regs, BUS_OBJERR, address, 0); + return 0; } /* Additional sanity check(s) */ @@ -516,8 +515,16 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address, fault = handle_mm_fault(vma, address, flags); #ifdef CONFIG_PPC_MEM_KEYS - if (unlikely(fault & VM_FAULT_SIGSEGV)) - return __bad_area(regs, address, SEGV_PKUERR); + if (unlikely(fault & VM_FAULT_SIGSEGV)) { + /* + * The PGD-PDT...PMD-PTE tree may not have been fully setup. + * Hence we cannot walk the tree to locate the PTE, to locate + * the key. Hence lets use vma_pkey() to get the key; instead + * of get_mm_addr_key(). + */ + up_read(¤t->mm->mmap_sem); + return bad_key_fault_exception(regs, address, vma_pkey(vma)); + } #endif /* CONFIG_PPC_MEM_KEYS */ major |= fault & VM_FAULT_MAJOR; -- 1.7.1 From 1583289397657835511@xxx Mon Nov 06 04:27:13 +0000 2017 X-GM-THRID: 1583289397657835511 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread