From patchwork Tue Jul 17 13:49:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529525 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 7E3FC600F4 for ; Tue, 17 Jul 2018 13:51:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 641FE2921E for ; Tue, 17 Jul 2018 13:51:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57F1229225; Tue, 17 Jul 2018 13:51:18 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID 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 EB97D2921E for ; Tue, 17 Jul 2018 13:51:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FBD36B0278; Tue, 17 Jul 2018 09:50:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 684186B0279; Tue, 17 Jul 2018 09:50:40 -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 487306B027A; Tue, 17 Jul 2018 09:50:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by kanga.kvack.org (Postfix) with ESMTP id 18E446B0278 for ; Tue, 17 Jul 2018 09:50:40 -0400 (EDT) Received: by mail-qk0-f197.google.com with SMTP id u22-v6so826354qkk.10 for ; Tue, 17 Jul 2018 06:50:40 -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:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=uprfVSkak4TEHjOLbYlq0sSx7lyVQBt1nIaem7JJ6ng=; b=fge/+4xjc17gpT5S1cLIUz0rUvIPnsv//4GUCcm8O9cIhU5siTne+EJH5i+NXLDQAK RQ3Lc9c8n7An5aDlLFnISF7ZRCzb4fOzIiQzs+JhzWBZJvpZu+hPsYdIDZQ/z7+681qa 0hf3dZ45Hiywt9UngXJVX6h2NUaLKdxZ4Mf8AqFtBGstgJDEuGE+Em1KUanrWxeKG3+C X1JcV6CBaKzPHmjgipHIM5/AdscLBzqESjRqJG74zRc9+j479GlXRa88JjOhvm6GkaZb HE/KIN0Da2+CV3P//rbd/ajmC96S4SPkDPKtU5Jjqm9ceNgLSxNRiNHAVZHtCidqlGvg qTpQ== X-Gm-Message-State: AOUpUlETyv1QT5IEjhvze0gjTvhHncR9qiRWC0ezyUx59UZ/2lcharAS w7jWNMUSwHGQL3aBvameVa43Ar+oPAI8FySWsbc854HV/nATmTg/b8Hoz1mVWacCbgZBOarPdAZ zSWA8a/KhG25Z7xEWz+RNRcELd/R/dUd3Jw1U+vpbyfSk9rWMCTsiEiGsWGkabcVooy6CbdOn6w SUl+ue0VywEpCB0DEG+qU3L/4UCAl0p1+mBc40gHFbqxz4tignJrVMzfDJIKftNaPzbhvcAtgKi vfT/8cc2JtpnapgdylRQOb1WhHBsBG1Ayuv/7p500zZXTqsQNv3xyDOVll6SGQ4yvC6oCynlpi5 rqmbfQOnJYdizGlBkrItzNZe4S/CdotKZxJZhBSFvyM2aaeHwTD8hASoAbpjfubAB8AMESxhkg= = X-Received: by 2002:ac8:2d61:: with SMTP id o30-v6mr1611244qta.253.1531835439902; Tue, 17 Jul 2018 06:50:39 -0700 (PDT) X-Received: by 2002:ac8:2d61:: with SMTP id o30-v6mr1611192qta.253.1531835439141; Tue, 17 Jul 2018 06:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835439; cv=none; d=google.com; s=arc-20160816; b=Cw8TSsYI7WGn7IJV42On0WQ3Fm1f015Kt4HzIwOC8ZQV2UidkhUu1BQD8olYT1O81M RFn/LAL2UlDi5o/yN3Le3u94BMzdpaYDdYAF7cTVuPBT42vTpBzENZUusvv0Jqsp8Xsd iv5x63RdNv+nnXsftHyWUPHo7F1oOUuWyMuvP7m6xd2yGFUEquPX7nWuUcMntxJToyn8 IcAvEjgJHWxl4OhpMetC/gZzeg2fJJYzHDXRAHsDB5iXqikcWDoxGZ2GNtNyBd5Y4LJD hYj3hdw9EwNW1cZCCt9468UKoWs4fMJnOz1GAqEWJjaWXDYmA+qHppJhyJZ9SjnRnmuE 9F2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=uprfVSkak4TEHjOLbYlq0sSx7lyVQBt1nIaem7JJ6ng=; b=gTpKSGWLiifLek74aCXUUxf8JsPr0icCTJGbY7EdHe38+O3CcqPRfmzX7gCpQT2e97 eIX/d6nrnFzS3geVIN8sROo758kYBE9gGihULHrCyr69+sbT00tD09lMpdvn9DTs1CeL W+aZVeWrrc4dwLt+/azVbQJRU/1iwsicVAoi51g1DgGUtH7Bp+TNMdumgRq3qM+M1fWQ ib4dc00wcoQo5Ldjo8DsmcPHHrhuBRNC8HEGp9Lt9aNBnRMtk3a6mVoaq7tgoqHZvzqI XwDeiJTcpgP3U5qkRifSkU6WBa/tEtUMweWclRt0ldKd+fEgmJ48F+BkEH84JNv/pQvm w/7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DnjCIkol; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m20-v6sor480187qvm.25.2018.07.17.06.50.39 for (Google Transport Security); Tue, 17 Jul 2018 06:50:39 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DnjCIkol; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com 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=uprfVSkak4TEHjOLbYlq0sSx7lyVQBt1nIaem7JJ6ng=; b=DnjCIkolJv1/90TJj9q+lzCwHtOovdi6sDN+PbgJ1DjQAwffx49UqJIoa/QwYvaOdY Hm65mLYT2fLSBrV6PoJGQxH4yplZpdtJAmtL4cjwc3J+SHsabAWneMy3x+ZPg+0SFtby 4msOP4hDlpbrKygky4b3JmGRl2apfj+XLdqBi17AU5wAVargJQAB+/fe7N6jyaNINpT2 lEFffgUHr5zDS+m6wQNJzhnjtB+JdYCZ4OdrbA7Ku6HulxIX1qfjx3sZ+nKxykdXAg5C ki3r9mnd34XQzzqaWy23LCnSAUyaOMx0NoKYmv59wp26bnl28FmzTb8hjakW4bpalCLT v0hA== X-Google-Smtp-Source: AAOMgpf0CRpOcZU7+Hkcgvm28W2NtbYtpiLfK9AZM3jLkJtaC+waR6lCyIsn8tjpX1G4QEyiaZHvQA== X-Received: by 2002:a0c:c963:: with SMTP id v32-v6mr1765580qvj.215.1531835438953; Tue, 17 Jul 2018 06:50:38 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id s83-v6sm640937qki.20.2018.07.17.06.50.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:38 -0700 (PDT) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, mingo@redhat.com, dave.hansen@intel.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, linuxram@us.ibm.com, fweimer@redhat.com, msuchanek@suse.de, aneesh.kumar@linux.vnet.ibm.com Subject: [PATCH v14 17/22] selftests/vm: associate key on a mapped page and detect access violation Date: Tue, 17 Jul 2018 06:49:20 -0700 Message-Id: <1531835365-32387-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> References: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> 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 detect access-violation on a page to which access-disabled key is associated much after the page is mapped. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai Acked-by: Dave Hansen --- tools/testing/selftests/vm/protection_keys.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 67d841e..d41b2dc 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1020,6 +1020,24 @@ void test_read_of_access_disabled_region(int *ptr, u16 pkey) dprintf1("*ptr: %d\n", ptr_contents); expected_pkey_fault(pkey); } + +void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, + u16 pkey) +{ + int ptr_contents; + + dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", + pkey, ptr); + ptr_contents = read_ptr(ptr); + dprintf1("reading ptr before disabling the read : %d\n", + ptr_contents); + read_pkey_reg(); + pkey_access_deny(pkey); + ptr_contents = read_ptr(ptr); + dprintf1("*ptr: %d\n", ptr_contents); + expected_pkey_fault(pkey); +} + void test_write_of_write_disabled_region(int *ptr, u16 pkey) { dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); @@ -1397,6 +1415,7 @@ void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) void (*pkey_tests[])(int *ptr, u16 pkey) = { test_read_of_write_disabled_region, test_read_of_access_disabled_region, + test_read_of_access_disabled_region_with_page_already_mapped, test_write_of_write_disabled_region, test_write_of_access_disabled_region, test_kernel_write_of_access_disabled_region,