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: 929199 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415mSz1x6tz9ryk for ; Thu, 14 Jun 2018 11:37:23 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AMuB21mZ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 415mSz0LnFzF0dT for ; Thu, 14 Jun 2018 11:37:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AMuB21mZ"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::244; helo=mail-qk0-x244.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AMuB21mZ"; dkim-atps=neutral Received: from mail-qk0-x244.google.com (mail-qk0-x244.google.com [IPv6:2607:f8b0:400d:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 415lMJ1t8QzF09h for ; Thu, 14 Jun 2018 10:47:24 +1000 (AEST) Received: by mail-qk0-x244.google.com with SMTP id r66-v6so2699329qkr.7 for ; Wed, 13 Jun 2018 17:47:24 -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=Goxc/b9ASoVHKotD9+OuLJ5wDLAWHxchvw3zISdHc5u6I5MR78le6PbKFB4+2p/mxF U/SMPcS42htzkZ1R5/qwqQVn8q2K8Ve2cVjiY8ZlT2C5UXVl+E5xISvbuH1XbRYTP5ay z2niStWa7HyWzo9FoXQXDgPKTj6y+2eaz7T2EBghierxn6PRBTLZAJxra1FahixtZeNs l0vCdv5UHSZHnh0Nx3uEge0EVgXduuhcgcN4LrDqiWLZW4sy9ywKKaJlk80ju1gEBiNI i7Rgu0NKL+64dCdaf8pL0o5UQuCWDnbyBgqfmqEYXmVc6wAYCD57A8p+hVg3RLo3wVuC AklQ== X-Gm-Message-State: APt69E0AIe3k90yrvtmLcXfNOoFBH5M29oa1ATfYV9NkYtX0PODLtwM9 vik2SKZBKjJNN+SKWQBlYgE= 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 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-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, fweimer@redhat.com, dave.hansen@intel.com, x86@kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, mingo@redhat.com, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, msuchanek@suse.de, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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,