From patchwork Sun Jun 17 11:23:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10468801 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 0A7FD6029B for ; Sun, 17 Jun 2018 11:36:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF5D628874 for ; Sun, 17 Jun 2018 11:36:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3FD428A1B; Sun, 17 Jun 2018 11:36:17 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41C9D28874 for ; Sun, 17 Jun 2018 11:36:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D1586B000A; Sun, 17 Jun 2018 07:36:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 153E96B000C; Sun, 17 Jun 2018 07:36:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 040F36B000D; Sun, 17 Jun 2018 07:36:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id BA7556B000A for ; Sun, 17 Jun 2018 07:36:14 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id g20-v6so7136891pfi.2 for ; Sun, 17 Jun 2018 04:36:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:to:cc:from:date :message-id:mime-version:content-transfer-encoding; bh=Wx0zIF103Teqs+L+7WV4uRcpSRXuJvb6uVTUcPvJ8OI=; b=jRJPOsFEoCLud7qVLynIDs0JXSd0ggCUDDpIvy2O0nOQzXkvpYvjFmkQgRxXU5OIrl cSAnMa6mIUuNfsj3Vmdi7fkU4QkPWMdcYaZqk/ZpL2O9flgkXs3dx/k/ePFoTEeVpcRy dV6jbE1KoTSQHGuxRxXQWznXLmtAOwfaOoIL4+4tMuEi64gR+tNgX7ZUUJzyTESqGzsx 3t5rv8nLfz8DtzNy/w0xILhI0Swt5C/yXgY55Qs+A1fLDaQsPLWYC0DVI/6Z0E7iLaES DyS3J0bgRS37pIfapLZL6N15Uuvbv/z1hQdgtntsZUph0FZtCNRUvng5RKhqq/eJRkmJ 2+ag== X-Gm-Message-State: APt69E0XoB5lH1Du2qqbxsaOEakCn7gQc8rx0W+5iHU92Lj9dJFOYtjB go/VPwiSUk0brUPcg9159sBiEeFfMYderC2r71p+M0w14ZWA+XZ1aqrBj6NXXUHeBWIskjuM16p wOt3lieJ7ZL0mt8xn+rV4mc6dD6DxTQTcATWgZfP7rLa9x4lXD3iPQs0LM+huMD4= X-Received: by 2002:a63:721c:: with SMTP id n28-v6mr7620969pgc.96.1529235374389; Sun, 17 Jun 2018 04:36:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI1LOvRZFWTJwjxHZKjSbPbsQSnSASqZJEj3mMIK0W4p1GDoAaH2Gb4/PkzPPUlAtoKpKhT X-Received: by 2002:a63:721c:: with SMTP id n28-v6mr7620933pgc.96.1529235373633; Sun, 17 Jun 2018 04:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529235373; cv=none; d=google.com; s=arc-20160816; b=XAC509TRRAZB7PhmUi2nu5t2udY4V2LP9n3azvoCZWItUH+MRnNie+a1YNtIEhQFL+ DaxUBOL3vmuv1Xd7ZjnjGWQW6bBWe47a5TcNrp6bKplTRjSD0afqWMMI7g4q7YT7kjpr QnjgxKRlQlaMGdaq6CRRIP+Fq1ssxWfJc6j7fduD7UVbsC582WwRMTlwcZ6yNFIOPjck BC5brgCmb7S3jXU2lYYAoHPlbpSlPj/gTFI6vllgK6dnOBXJLEEr/ohz/DOcC1ns6dHX uWrpFn/4Y0M1iAOtYIZd9PPiUFcbxbQs8xGmngYBKJugQdV7QwqluvY241QWsqeL27Va S/8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:from:cc:to :subject:dkim-signature:arc-authentication-results; bh=Wx0zIF103Teqs+L+7WV4uRcpSRXuJvb6uVTUcPvJ8OI=; b=zQlnTQGgNHsXUG7VuWDLLWbJElZbFMRx63nuraQj0IffJRWcAFWUHBWvim2+SV0Odk sLHFkAIxhFB1C4heZt61RsW6rZ5GSWU6BG/fse3TPEzqckf5fup4k/6zUXDcQ1F/i1KX LiuAyMYs2Dy6Os2UimccTVpR+kFyUax49r+U0uwbRggahltX2i3i0AV8yvzgB5XyFirF gg2qxlu+vNjw9GGlNnNZtXJNABbIhuBGuolfraWQWQC3eJlzaTrtWU0Jw+51voh9Pbsc o22s2zEwO7+xFXUpN6dOo/tBO1dGP5EwmolYk6SNHevs09c78/UOpBvGmz5Ieibk9kbM +5JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p2nfesOr; spf=pass (google.com: domain of srs0=nxds=jd=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=nXdS=JD=linuxfoundation.org=gregkh@kernel.org" Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id b1-v6si12152110pld.323.2018.06.17.04.36.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jun 2018 04:36:13 -0700 (PDT) Received-SPF: pass (google.com: domain of srs0=nxds=jd=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p2nfesOr; spf=pass (google.com: domain of srs0=nxds=jd=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom="SRS0=nXdS=JD=linuxfoundation.org=gregkh@kernel.org" Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B9A07208D5; Sun, 17 Jun 2018 11:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529235373; bh=uHrwdKQCv0PSLN6YXoRkwZRUAwpfAUtYP/TTYjvKOR0=; h=Subject:To:Cc:From:Date:From; b=p2nfesOrRmDqJU8hxCHTglskbFbSl4CAe1lOZXVEmXsOASqG91Pg+9CdAyEV0Wqee +kRilxKnakbadggnCeElW7E+JtRouUDP4bApnhC7Vdurio5UhPiZ3Zq2DFMg4FOoat vkESroE6zvRonwf6VDD5e0q8ryk09iFbRf/M+8c0= Subject: Patch "x86/pkeys/selftests: Add PROT_EXEC test" has been added to the 4.14-stable tree To: 20180509171348.9EEE4BEF@viggo.jf.intel.com, akpm@linux-foundation.org, alexander.levin@microsoft.com, dave.hansen@intel.com, dave.hansen@linux.intel.com, gregkh@linuxfoundation.org, linux-mm@kvack.org, linuxram@us.ibm.com, mingo@kernel.org, mpe@ellerman.id.au, peterz@infradead.org, shuah@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Cc: From: Date: Sun, 17 Jun 2018 13:23:31 +0200 Message-ID: <15292346113162@kroah.com> MIME-Version: 1.0 X-stable: commit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This is a note to let you know that I've just added the patch titled x86/pkeys/selftests: Add PROT_EXEC test to the 4.14-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-pkeys-selftests-add-prot_exec-test.patch and it can be found in the queue-4.14 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From foo@baz Sun Jun 17 12:13:49 CEST 2018 From: Dave Hansen Date: Wed, 9 May 2018 10:13:48 -0700 Subject: x86/pkeys/selftests: Add PROT_EXEC test From: Dave Hansen [ Upstream commit 6af17cf89e99b64cf1f660bf848755442ab2f047 ] Under the covers, implement executable-only memory with protection keys when userspace calls mprotect(PROT_EXEC). But, we did not have a selftest for that. Now we do. Signed-off-by: Dave Hansen Cc: Andrew Morton Cc: Dave Hansen Cc: Linus Torvalds Cc: Michael Ellermen Cc: Peter Zijlstra Cc: Ram Pai Cc: Shuah Khan Cc: Thomas Gleixner Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180509171348.9EEE4BEF@viggo.jf.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/protection_keys.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) Patches currently in stable-queue which might be from dave.hansen@linux.intel.com are queue-4.14/x86-pkeys-selftests-factor-out-instruction-page.patch queue-4.14/x86-pkeys-selftests-fix-pointer-math.patch queue-4.14/x86-pkeys-selftests-adjust-the-self-test-to-fresh-distros-that-export-the-pkeys-abi.patch queue-4.14/x86-pkeys-selftests-add-a-test-for-pkey-0.patch queue-4.14/x86-pkeys-selftests-stop-using-assert.patch queue-4.14/x86-pkeys-selftests-save-off-prot-for-allocations.patch queue-4.14/x86-pkeys-selftests-remove-dead-debugging-code-fix-dprint_in_signal.patch queue-4.14/x86-mpx-selftests-adjust-the-self-test-to-fresh-distros-that-export-the-mpx-abi.patch queue-4.14/x86-pkeys-selftests-add-prot_exec-test.patch queue-4.14/x86-pkeys-selftests-allow-faults-on-unknown-keys.patch queue-4.14/x86-pkeys-selftests-give-better-unexpected-fault-error-messages.patch queue-4.14/x86-pkeys-selftests-fix-pkey-exhaustion-test-off-by-one.patch --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c @@ -1303,6 +1303,49 @@ void test_executing_on_unreadable_memory expected_pk_fault(pkey); } +void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) +{ + void *p1; + int scratch; + int ptr_contents; + int ret; + + dprintf1("%s() start\n", __func__); + + p1 = get_pointer_to_instructions(); + lots_o_noops_around_write(&scratch); + ptr_contents = read_ptr(p1); + dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents); + + /* Use a *normal* mprotect(), not mprotect_pkey(): */ + ret = mprotect(p1, PAGE_SIZE, PROT_EXEC); + pkey_assert(!ret); + + dprintf2("pkru: %x\n", rdpkru()); + + /* Make sure this is an *instruction* fault */ + madvise(p1, PAGE_SIZE, MADV_DONTNEED); + lots_o_noops_around_write(&scratch); + do_not_expect_pk_fault("executing on PROT_EXEC memory"); + ptr_contents = read_ptr(p1); + dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents); + expected_pk_fault(UNKNOWN_PKEY); + + /* + * Put the memory back to non-PROT_EXEC. Should clear the + * exec-only pkey off the VMA and allow it to be readable + * again. Go to PROT_NONE first to check for a kernel bug + * that did not clear the pkey when doing PROT_NONE. + */ + ret = mprotect(p1, PAGE_SIZE, PROT_NONE); + pkey_assert(!ret); + + ret = mprotect(p1, PAGE_SIZE, PROT_READ|PROT_EXEC); + pkey_assert(!ret); + ptr_contents = read_ptr(p1); + do_not_expect_pk_fault("plain read on recently PROT_EXEC area"); +} + void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) { int size = PAGE_SIZE; @@ -1327,6 +1370,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_kernel_gup_of_access_disabled_region, test_kernel_gup_write_to_write_disabled_region, test_executing_on_unreadable_memory, + test_implicit_mprotect_exec_only_memory, test_ptrace_of_child, test_pkey_syscalls_on_non_allocated_pkey, test_pkey_syscalls_bad_args,