From patchwork Sun Jul 16 03:56:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 789051 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 3x9Ffs64YRz9s3w for ; Sun, 16 Jul 2017 15:41:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C069QTCU"; 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 3x9Ffs4z6jzDqpy for ; Sun, 16 Jul 2017 15:41:57 +1000 (AEST) 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="C069QTCU"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) (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 3x9CPg5CWLzDqmQ for ; Sun, 16 Jul 2017 14:00:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C069QTCU"; dkim-atps=neutral Received: by mail-qt0-x243.google.com with SMTP id v31so14710678qtb.3 for ; Sat, 15 Jul 2017 21:00:23 -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=4y+HhoorGNLnhk95SB53NcFxn57tMAs2klXpdJjVdAU=; b=C069QTCURIdq1bvglcK0Zb1fOaVEcJVOAgCsSJsI7241G/CCLykf9G3CcwnLAoTjT5 +Qga1DyDkCz7AN11vkzQcNfHCC44LU9RUnpP9c49UTnoIt0jK59KSCsSFzbSLeGBnIOT 5m95k6KGlaNtz6rRcBwFbx57oe0r7yw53+FWTM67aGNCXmi86+bi99k5pecwqGzgpUXK +KBhIkcejmDdQ+PQcfakxn5F8PCuKVphVrDeRs5l8Co9iPkdd0Vy075jVi2b+o6dBy53 vZg+KgnvXIhiStK5AwEqs5g7oqWxBxjuZbP3gznuHgBgRaBE2RMZtbGCeyPt05xKR4EE v0yw== 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=4y+HhoorGNLnhk95SB53NcFxn57tMAs2klXpdJjVdAU=; b=kQ1BscMr1rBFA0MD20AeAemcvNApWvECvYYxIFtVznFeLir27sobatReVEmG85DjGB uHNwutLxOy/7ESuEU3pLT37r6cGm8Vu7URlV59ek7WaQwci1hisgWzhKUEhF56SyvLCH e2FOGL6WEz/8qbHrWeoGiOMkcINPaWIqY/E5SDNVx7wpHXj+OdGb8EqBgEwOKGT4jyob Ln8mFhgVsslHm2FvAcT7RHAl7VLoH9dEQR8D0pKu/5w2YPT1mUFXCQ32CgICVxzRflBg 6CqHje6X+mcJzI8Pmq5lDP+d6Dptl94WFd4hsxgTEkh6IZW5eA++znOiMQiHkDpdJrHH waMg== X-Gm-Message-State: AIVw1110BSQOeQd4P68DnjDE0SJoLLP5k4x8aZjdQMQGBrgX+OJZ+9G4 ymE3NHfv0qxgobIdtN4= X-Received: by 10.200.56.187 with SMTP id f56mr4049108qtc.234.1500177621104; Sat, 15 Jul 2017 21:00:21 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id q46sm2290345qtc.54.2017.07.15.21.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jul 2017 21:00:20 -0700 (PDT) From: Ram Pai To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC v6 56/62] selftest/vm: detect no key violation on a freed key Date: Sat, 15 Jul 2017 20:56:58 -0700 Message-Id: <1500177424-13695-57-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> References: <1500177424-13695-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arnd@arndb.de, corbet@lwn.net, linuxram@us.ibm.com, mhocko@kernel.org, dave.hansen@intel.com, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" a access-denied key should not trigger any key violation after the key has been freed. Signed-off-by: Ram Pai --- tools/testing/selftests/vm/protection_keys.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index bf27bcd..47c23cc 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1026,6 +1026,30 @@ void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, expected_pkey_fault(pkey); } +void test_read_of_access_disabled_but_freed_key_region(int *ptr, u16 pkey) +{ + int ptr_contents; + + dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", + pkey, ptr); + + /* read the content */ + ptr_contents = read_ptr(ptr); + do_not_expect_pkey_fault(); + + /* deny key access */ + pkey_access_deny(pkey); + ptr_contents = read_ptr(ptr); + dprintf1("*ptr: %d\n", ptr_contents); + expected_pkey_fault(pkey); + + /* free the key without restoring access */ + pkey_access_deny(pkey); + sys_pkey_free(pkey); + ptr_contents = read_ptr(ptr); + do_not_expect_pkey_fault(); +} + void test_write_of_write_disabled_region(int *ptr, u16 pkey) { dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); @@ -1333,6 +1357,7 @@ void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) test_pkey_syscalls_on_non_allocated_pkey, test_pkey_syscalls_bad_args, test_pkey_alloc_exhaust, + test_read_of_access_disabled_but_freed_key_region, }; void run_tests_once(void)