From patchwork Thu Jun 14 00:45:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463111 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 A0FC6603EE for ; Thu, 14 Jun 2018 00:47:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93D5928988 for ; Thu, 14 Jun 2018 00:47:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 873C428BA8; Thu, 14 Jun 2018 00:47:56 +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 1E84428988 for ; Thu, 14 Jun 2018 00:47:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A98016B0284; Wed, 13 Jun 2018 20:47:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A248F6B0286; Wed, 13 Jun 2018 20:47:23 -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 7FAE66B0287; Wed, 13 Jun 2018 20:47:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by kanga.kvack.org (Postfix) with ESMTP id 53F2A6B0284 for ; Wed, 13 Jun 2018 20:47:23 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id k7-v6so3364372qtm.1 for ; Wed, 13 Jun 2018 17:47:23 -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=TxPIBJzKdcbbpXTfdFZzp89aKEC/YQm1GqPzMpN4p9Y=; b=Jmvs6Fe57tnEqYt7tGL1BTJU2taSpK+mX/lFMsMz7ZpwqEsTa1c8iXfw42JE/zY+wM verAjwhiyZg89K9rL4J+KEW19md2XCTbGTTDeXx/aoagSUpHqucvsWYqQIBIen8CXYy4 5hnqbYexp7AGRHfw4JqT9oXv6aXTAds68Ry7X7QEAw8hqsjNGX9HnW9BhFvN7st7s5cY VZfVNbeMxeStFKyD3p6EEgXs2Y7QFBH9o9HRpERBRT7sEQ5n0pz3a+yuBQIU0C1xvdax ex7uQuKX4B5LPPYgENInDqsVGgq5iWFQT/vVc14uPzGjnfs+yIpQVBmazmWsVoDs8ZhE 5EYg== X-Gm-Message-State: APt69E241r4VlJLn7jm417e0GjpOTGjqqFvHkgNThuaMYxjz2VhKk3oG 6uCmka8vBg2fW2fzx59qVcZjkYy21oEU0B234Qg2JIVRd25iLySpIpVsJSSBl/INX9OncjC84QS CmHrQ9VyY4TJoa5VH/u5V7PhxM3yOu8IAVkXskjm4WSQO+Kdx7zOnX/CUXdDY8FOdhYYcMxhB5z YAyrHPQvh22A1+hK7k3hlQLj6eatvKwQnd6dj81EIhcWTYQgYC3965hQhFJ5FjdQ0zP91mqdlU0 yp44nzJWuaGtiBowobIxOZJa0W571B+bT9QnUegNGG3bMOHLO8Hgmn+/z2IzuIS/vbkTW7p/V6c mnOCcsxX7eacDp7XoAvBkYiC8348vTU/xY6g5sifH8f9Qm4D9HjDemzK1Vjk+Rh5bf3ZBq817Q= = X-Received: by 2002:aed:2448:: with SMTP id s8-v6mr384652qtc.336.1528937243138; Wed, 13 Jun 2018 17:47:23 -0700 (PDT) X-Received: by 2002:aed:2448:: with SMTP id s8-v6mr384624qtc.336.1528937242400; Wed, 13 Jun 2018 17:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937242; cv=none; d=google.com; s=arc-20160816; b=woUM/gHttET2rV0oASgVhY7Rfj4ULRh+foArilR2v1oqqzwGo9gv85BEYYt7/zgyHJ wqhrMBx75uGCv54Z8J77AGsFGim/wxZSl6npv0pl4zxmNNOH93kpOb9814keSpWospKR HAQCfyvTBeIrBJ9y7mBHiJ8Dk4bmWo/e/uO9xbhhqZ4z2BASl4mVC11MsmeISBBNsViv q/U6bXMRCbreIWbuRQRAChjewxMmCfOVbsX53knTjfEKyED0FmcyIG8n2kQa0HgDhQ70 gu8kY4l/Z98dbIy/Pms0Y71OW7UgWPB/RohA8qxpj+blocA3yXHe0gY+cellrqwBupt3 rr3Q== 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=TxPIBJzKdcbbpXTfdFZzp89aKEC/YQm1GqPzMpN4p9Y=; b=ibJR2cuSnyt++USV0dg3Q3NRnQjfzyDkO/Hv0LEHEtA2srqEGhxy8jBPVak31hqFX5 Ali/WKoqivZ4wBQCe5Y4DsjaQxc2dQxG350Fijp3dfRqoRgJG+Hng3y7BY9+xIfVDeMW oyLPlmupDj7gfEvDD28YydTP6k68IMmw2xEFpXM/09nbIEr8oayS2rvZxI2lGmhm8oYL PKP5fVdtc/l98KNd3Zp9Psr3OXLBtxmmlyIDxQRIsx7n7ZjFUFQEsz808+o0AHMnioKF +zDDHt+gMMzX61URXBA2zvXxU6E8f2kFqXZadg2uA4H7ymu0HybZzH2r3dToLnxTcNle AUQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AMuB21mZ; 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 b190-v6sor2072017qkg.98.2018.06.13.17.47.22 for (Google Transport Security); Wed, 13 Jun 2018 17:47:22 -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=AMuB21mZ; 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=TxPIBJzKdcbbpXTfdFZzp89aKEC/YQm1GqPzMpN4p9Y=; b=AMuB21mZoMaaSzKfLujqkeRt9ZtLV5AQFqqdv3iied0hXBaFJNk0jMW62Xdz38VXwd iABGsPhLbg+K5Kt3iILXPFjuYGoVOULnr8woEkzdwwX00r0rwmY0TV0241IkBL+ipc0K xerSkIlKzzfUDJMIvzZK0uoBT7D4WAUUTsguSYi7ZVwpoKg4RkywUwJ6cB5QacYkJlzy n5tp92En7uNASQ63BLqpochDH6AuHIq9PwonNpsmunfWTmg4YTqDqmAoXBJyFA9YOh88 fiksaqCwYsrdOj00zvhhZwRcohLr7HsrBk1EyjDAFS7c4Uzi3d2P9/mHFy4Ln5/lUR+v Da5A== X-Google-Smtp-Source: ADUXVKL1RfFIpUxURIGVan7c+cA+RZ7V53mjJK7m+7GD1ib7bQv3JTSxIYkbXYx3oVu4TlsG1onMAQ== X-Received: by 2002:ae9:d60a:: with SMTP id r10-v6mr338827qkk.303.1528937242213; Wed, 13 Jun 2018 17:47:22 -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 u31-v6sm3225898qtc.28.2018.06.13.17.47.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:21 -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 v13 19/24] selftests/vm: associate key on a mapped page and detect access violation Date: Wed, 13 Jun 2018 17:45:10 -0700 Message-Id: <1528937115-10132-20-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-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 e8ad970..04d0249 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1024,6 +1024,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); @@ -1402,6 +1420,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,