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: 945087 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 41VNWs2kh7z9rxs for ; Wed, 18 Jul 2018 00:51:21 +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="DnjCIkol"; 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 41VNWs0lRTzF3Hg for ; Wed, 18 Jul 2018 00:51:21 +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="DnjCIkol"; 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:c0d::244; helo=mail-qt0-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="DnjCIkol"; dkim-atps=neutral Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::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 41VM9r5h6hzF3Hh for ; Tue, 17 Jul 2018 23:50:40 +1000 (AEST) Received: by mail-qt0-x244.google.com with SMTP id a18-v6so887641qtj.4 for ; Tue, 17 Jul 2018 06:50:40 -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=uprfVSkak4TEHjOLbYlq0sSx7lyVQBt1nIaem7JJ6ng=; b=DnjCIkolJv1/90TJj9q+lzCwHtOovdi6sDN+PbgJ1DjQAwffx49UqJIoa/QwYvaOdY Hm65mLYT2fLSBrV6PoJGQxH4yplZpdtJAmtL4cjwc3J+SHsabAWneMy3x+ZPg+0SFtby 4msOP4hDlpbrKygky4b3JmGRl2apfj+XLdqBi17AU5wAVargJQAB+/fe7N6jyaNINpT2 lEFffgUHr5zDS+m6wQNJzhnjtB+JdYCZ4OdrbA7Ku6HulxIX1qfjx3sZ+nKxykdXAg5C ki3r9mnd34XQzzqaWy23LCnSAUyaOMx0NoKYmv59wp26bnl28FmzTb8hjakW4bpalCLT v0hA== 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=uprfVSkak4TEHjOLbYlq0sSx7lyVQBt1nIaem7JJ6ng=; b=nQ9jTztJbJweyvkq1RvHcGqnMcmO2EEreLB3qkon4C0+1LnFzeZc93I9iS/Kei3Ol1 WmT+ZKmog8qYtjkdYtvAWjE16kwsn6YFKzJYzCqlmvVBQy4S8t2SNOwVXWPjtIprfK7D 9FcFKYVldnmxfOZZqsVSPDDCJY6AN+gdF45udaABzaTbHIVV0Pce8+GXBoBXzJizTQAJ DqtylxUji4ZnX5ATaEb2lhLr78mS2pkQpehBjp0gksZOusgXb50iSjpBgNzKojxzW0Z4 GwOUHF5NSdydGUi90rfUIFaIIK7aDbBray7KrN3aNv4kp1fzIyJWuv5jOJzfEpk1EYSg DoKw== X-Gm-Message-State: AOUpUlGbpFga9qrXV+/EWo5JvEU2gXL++wY6dmmpMY7wGo/Sn63+vhQ3 N/7Rq3IZmR9g2jPJBckOOBE= 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 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-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 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 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,