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: 10463083 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 C9438600D0 for ; Thu, 14 Jun 2018 00:47:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B876128988 for ; Thu, 14 Jun 2018 00:47:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACDD428BA8; Thu, 14 Jun 2018 00:47:24 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 587F628988 for ; Thu, 14 Jun 2018 00:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936027AbeFNArY (ORCPT ); Wed, 13 Jun 2018 20:47:24 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:45857 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935982AbeFNArW (ORCPT ); Wed, 13 Jun 2018 20:47:22 -0400 Received: by mail-qk0-f195.google.com with SMTP id c198-v6so2685846qkg.12; Wed, 13 Jun 2018 17:47:22 -0700 (PDT) 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-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=TxPIBJzKdcbbpXTfdFZzp89aKEC/YQm1GqPzMpN4p9Y=; b=YJ6lDzGEDCWjsSOl92e1mexe40JH0wjS8MsvowjUHKgJt5ioUAAZ5qo7Csd93EfGnX TE+Bia4k3QfXzPbjTGPoX71QjDMsqRMI6WSRvtEEWSqnzQeELlrxtkXDHSOpGcWz+NsP HfXlF7NnlixtBDyI2mIQ5fXTruI/2ulc+8GTL2cHodw+b7QYHSaSTr5K402FeLu02Js+ SlosVL3Hm1D2fifZcr5zwHaOxd3mfhudTlSxykXQPf14EdH2tswQQce/+UeFiQF0kiNQ Nj4F35fITFn+QPOlifeN/HZIRnQp2TY8jI241G7lrrdaXFppiD8r9FISCn+mpOAxB2OI sZhw== X-Gm-Message-State: APt69E1RZhGtEpDD0ZYeDWN9nRyH28O0r2+pZq/BKlx81XN3gHh5uAX3 yXHdxvhf0AxnQc0/TMt3A2E= 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> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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,