From patchwork Thu Feb 22 01:55:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 876480 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 3zmz7q5gwdz9s0W for ; Thu, 22 Feb 2018 13:39:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h7kO5LKs"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zmz7q4QqrzDqYN for ; Thu, 22 Feb 2018 13:39:03 +1100 (AEDT) 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="h7kO5LKs"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::242; helo=mail-qk0-x242.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h7kO5LKs"; dkim-atps=neutral Received: from mail-qk0-x242.google.com (mail-qk0-x242.google.com [IPv6:2607:f8b0:400d:c09::242]) (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 3zmyCg41W3zF13S for ; Thu, 22 Feb 2018 12:57:19 +1100 (AEDT) Received: by mail-qk0-x242.google.com with SMTP id v124so4612723qkh.11 for ; Wed, 21 Feb 2018 17:57:19 -0800 (PST) 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=F1Q8Pg2/NeJXGCNglceMKF0HTR854N/pSIX433WQwT8=; b=h7kO5LKsJ6LY2y6gP2hnihyNoxLmJceswYlF94X1hXSxm+GQtqGHSShWe9z7wRQWOn 6uGDXHWFllxVcZBr494qJ9GZOWtXDth2wR0Ujw5I7LncPZS0vkamWp4qVrkxIjKtBg00 CuPBDu9a4R/4jYckOceOTCkVeP1rrOCfU6FsqbmrpWTEsmGNXlCvlpHZUjNx/x75iW1J DdZYOJdpFfUGLfr7U1yzZwdXY+QysfnVOuaGVcQrvHuIJZYeRsGSBdVcZJuEh8EiQe0e TSyB4rA+3YvZ3BxhaQVcsWY/ZHEuOfEX2shbkOa3oS7BhXfdcELLkDQM30MIKaqdpScX HMMg== 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=F1Q8Pg2/NeJXGCNglceMKF0HTR854N/pSIX433WQwT8=; b=VDnIW7ZYx9ffrYotPE26gr5ZcOePNdqz9bwlEyBQpTC7eCQ7Zr8T95gQ8WR0ANrk42 pI7E7Bx+tDCr/elFuRrczecn8ajr6zIDGBlAC3PU7lvJYL9dNxTBN7MRfqm2BAgUY4hB Ak54Cqf5sGe83B6BxRdhnkdOMubPoNwApghOtjtaX13duWF4YAKfZ/VAs3JgNP2gyZgm +PASm5FKFt00LSxaUVlYaXKj1TI4crvXNAd25t+t/Pq+9P5ws2B2QycQgnbbzUsTmCHa 9F2rOphd/IqPI27HAVTi4z0i+efnt8Q175NuSLO8Kqg7N4BYBT02eJiGXm2hhoOm+OqR z49w== X-Gm-Message-State: APf1xPBISPXpu2NbJojhhwXBqwZmH/rH5kgtlrVbznBS0n8fnCb2/NsM 2TilGPiQyOO9lazAeZfMoWQ= X-Google-Smtp-Source: AG47ELts/WwxRkAhj9enWAAReI91rGbOIxCj2UhoGHrwinn9FYdC6E8xGaw6odp4oBvXBPvMRxWXxQ== X-Received: by 10.55.1.78 with SMTP id 75mr7911886qkb.310.1519264637240; Wed, 21 Feb 2018 17:57:17 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id n29sm14182630qtf.18.2018.02.21.17.57.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:57:16 -0800 (PST) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Subject: [PATCH v12 17/22] selftests/vm: associate key on a mapped page and detect access violation Date: Wed, 21 Feb 2018 17:55:36 -0800 Message-Id: <1519264541-7621-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-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, ebiederm@xmission.com, arnd@arndb.de, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com 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 aae6771..dba9162 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1016,6 +1016,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); + rdpkey_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); @@ -1310,6 +1328,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,