From patchwork Mon Jun 18 08:13:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10469879 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 328D76032A for ; Mon, 18 Jun 2018 08:28:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2382628861 for ; Mon, 18 Jun 2018 08:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18346288B8; Mon, 18 Jun 2018 08:28:15 +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, 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 842D828865 for ; Mon, 18 Jun 2018 08:28:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97FCC6B0269; Mon, 18 Jun 2018 04:28:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A8266B026A; Mon, 18 Jun 2018 04:28:12 -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 728986B026B; Mon, 18 Jun 2018 04:28:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 1BA086B0269 for ; Mon, 18 Jun 2018 04:28:12 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id b65-v6so8688271plb.5 for ; Mon, 18 Jun 2018 01:28:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:user-agent :mime-version; bh=A03xX0cVCvwvRTMLM1L8swp3HUWcfK4ZgflgSDarnjk=; b=qUk7A2VUyuWVchMlD512RHdiAdcXEbGwPY4A71x2AgN8Co4F4EQ0+JJrkRKrk4ECJW 7LnzsKWxIFUFUFBv++efDbwzRGpR4U2+ak1y7wPBMwOk0vi+SaVxviGFj2+xpxNhY18S HeKUUldcUNsVIyduOh+4e4hy+r/3V36Dx+08j3CZr/zt6UIBSXlcbenQCtTwNJA9mTfH CYCEgl/tYy1nmvUh/CaH1VFuKfTovuHMvo74ELIrNrEcMFy6TVNrKAENm67mOQOj62yy BRK/mdIKENH+wTokKYNwvFkU5STQGSJ5qLYoK11l4zV83rGhM3yQZYo2SZhLsc0xKn9H Tzkg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Gm-Message-State: APt69E3eoyYQ/sIxOwczh8/aoUaSh9nD0D/3XZn2iRINme6QyofHplvK y3vVElyDvHTaogGEqgGdo7ALsD//NVzEg58j10HZC1bLBc3HCsKEHTIndpbIhuCwGOYOggFYYb5 AIxgaIiv8eK2esbstaAx7T78qvxy38jtsO7D2Rnl2D5LcoPo6JnYzV6rFY59t9Vk7hw== X-Received: by 2002:a62:9b57:: with SMTP id r84-v6mr12611160pfd.157.1529310491782; Mon, 18 Jun 2018 01:28:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLIQOUHeKCT8tgmwbRL/QtK+hnuReZ17IsF4284s/fPMpvTMU7GDHFtt7gIyXiZIqNrLqpr X-Received: by 2002:a62:9b57:: with SMTP id r84-v6mr12611109pfd.157.1529310490843; Mon, 18 Jun 2018 01:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529310490; cv=none; d=google.com; s=arc-20160816; b=RSXK5OhDmihR8S5MPmKmZXMIvKmbQNFilbjabnMzZBEfZ9GdTgFal7+o5XZJKsW0bT 37KsbWTnYACC28sPSpbveV5RoR7ZD8V1pUTyRj/dsMLoTx1yvewCKAKeeMI1ZOcfWsFZ /jAvayZo8f9y+xKnae8B2fmpLDaePCnHoqG92As4PF5WAtwSUFYGtGzJwWk0MJ3N2S+4 q0xHDEliUItXMNqc4IXU8ej34K1DmOv82d5NTpWli1k8ZQB7f0uMjgRf79SPn0WfD3Zn jUyxWTRo5bHB4TgwO/oW86sxrsZzvCQlmUss7Me7Yw/zBKte24AkReLo02xr7+dFUJYE HE0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=A03xX0cVCvwvRTMLM1L8swp3HUWcfK4ZgflgSDarnjk=; b=f0cLmel68YOUXa+7AqxDB14IcCDgRysYplsJnd7zV+Tp1CUT0K2PbvXccshCTEO9/S Fnn5I+xM0FdAGSvE0P823Zry9Dpmow80jKfDwh+7+Z0sV+hZdhq3uPTGthmiCmyd+9+Z ZxyXWjXiaGCNEXJoGdD7HH4gFZgQJgQurAsNECAdnDtbpXpujfiWpCnFyPCK7Y8mWT0d AZomSgFr3+M8wLb8Tk7STUNSt4Mm++ratChZPOgWDWJBk252Fk0rt0R3YW7+9cM/TMBJ tfp0OgrNgy8C/HqwjAgBZ1e/9bCfSSbQYOWECr5ETs14XT64M2JXp88brhAhYLkQKJNC C1+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id r5-v6si14108162pls.518.2018.06.18.01.28.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 01:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1585BCC9; Mon, 18 Jun 2018 08:28:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Andrew Morton , Dave Hansen , Linus Torvalds , Michael Ellermen , Peter Zijlstra , Ram Pai , Shuah Khan , Thomas Gleixner , linux-mm@kvack.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.16 247/279] x86/pkeys/selftests: Add a test for pkey 0 Date: Mon, 18 Jun 2018 10:13:52 +0200 Message-Id: <20180618080618.983261598@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Hansen [ Upstream commit 3488a600d90bcaf061b104dbcfbdc8d99b398312 ] Protection key 0 is the default key for all memory and will not normally come back from pkey_alloc(). But, you might still want pass it to mprotect_pkey(). This check ensures that you can use pkey 0. 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/20180509171356.9E40B254@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 | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c @@ -1184,6 +1184,35 @@ void test_pkey_alloc_exhaust(int *ptr, u } } +/* + * pkey 0 is special. It is allocated by default, so you do not + * have to call pkey_alloc() to use it first. Make sure that it + * is usable. + */ +void test_mprotect_with_pkey_0(int *ptr, u16 pkey) +{ + long size; + int prot; + + assert(pkey_last_malloc_record); + size = pkey_last_malloc_record->size; + /* + * This is a bit of a hack. But mprotect() requires + * huge-page-aligned sizes when operating on hugetlbfs. + * So, make sure that we use something that's a multiple + * of a huge page when we can. + */ + if (size >= HPAGE_SIZE) + size = HPAGE_SIZE; + prot = pkey_last_malloc_record->prot; + + /* Use pkey 0 */ + mprotect_pkey(ptr, size, prot, 0); + + /* Make sure that we can set it back to the original pkey. */ + mprotect_pkey(ptr, size, prot, pkey); +} + void test_ptrace_of_child(int *ptr, u16 pkey) { __attribute__((__unused__)) int peek_result; @@ -1378,6 +1407,7 @@ void (*pkey_tests[])(int *ptr, u16 pkey) test_kernel_gup_write_to_write_disabled_region, test_executing_on_unreadable_memory, test_implicit_mprotect_exec_only_memory, + test_mprotect_with_pkey_0, test_ptrace_of_child, test_pkey_syscalls_on_non_allocated_pkey, test_pkey_syscalls_bad_args,