From patchwork Thu Jun 14 00:45:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463085 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 98ABC603EE for ; Thu, 14 Jun 2018 00:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A8E428988 for ; Thu, 14 Jun 2018 00:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F1D528BA8; Thu, 14 Jun 2018 00:47:26 +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 24BCF28988 for ; Thu, 14 Jun 2018 00:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936050AbeFNArZ (ORCPT ); Wed, 13 Jun 2018 20:47:25 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:38650 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935982AbeFNArY (ORCPT ); Wed, 13 Jun 2018 20:47:24 -0400 Received: by mail-qt0-f195.google.com with SMTP id x34-v6so4278185qtk.5; 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=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=aqI92FA2XbuvsMyC06jnkkWSleKSzLUEf7SQB22LFLEByyV/SOARQPjap540eLY3fZ Gj98AvKouDjmGgyO6ubrpCMY+DxN/XLldM1N5BDxgkhfwLj9BmI7hZxtVcC6cpb7XKGh i98srcTC/u8rC0NpZsMXF8nPMG7n6GlW11mtYAudJBQ0Jj3WOJf0flecy+r+YV1A/hAO JqNZvqbb7ZOAJoGQtGwo3FTs5EDfcBxMX92m0dyozDtW032SvVxihIjd3tpyE9UZX7bJ h2c5FNR8fLecqe/ZVeuVQR18ZyPw5wu4fqzwYNCGUDWd0wZO/k1IRLwa5diunXKfshHR 7dWg== 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=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=XFiK8/4sQ9GIRQG1wy1K/it9MxhercUE47zxWYeHdHKys0r8rEzkG9VvQDzyfzDjyE P4BJY5zz/m/X2fVT38MoBEVdNZsF/MRLKm6KoI6WGM4YUmFcquqQuQH1WOLF3soXY8ve HjoIeUATCLFEqcyKHR4hECCDl5x1mwVOhgjyrgseKko4L523YASo2XM7fABrPwq2bCqW RMFSVNVhG0vQ2id7HtaT2konmoVR2AEQKZZwS+3E55BDjId9iHqSkMMCGwholOHRl1HK Bk1L086p3B0XbDNGmyTDdGQhngJef9zAZTBgPwhcn+1UKE76X8cW6Jo9fgvnp3WXQlaT w/pg== X-Gm-Message-State: APt69E2jq5mzDRpvq/JIOzVCOqnkMPn6EqIPD4wPFAkFA3nksJVL1CBV pMHaYBWOr/Y+sAUj3hqOX50= X-Google-Smtp-Source: ADUXVKJWpXN+ccjsiGq19O0ny10KfYlaEhHbnGP174ZF/j40/f6L6Jqp0Sm4C63wsQzukemvbRZl0w== X-Received: by 2002:a0c:9273:: with SMTP id 48-v6mr373605qvz.220.1528937244243; Wed, 13 Jun 2018 17:47:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:23 -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 20/24] selftests/vm: associate key on a mapped page and detect write violation Date: Wed, 13 Jun 2018 17:45:11 -0700 Message-Id: <1528937115-10132-21-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 write-violation on a page to which write-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 | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 04d0249..f4acd72 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1042,6 +1042,17 @@ void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, expected_pkey_fault(pkey); } +void test_write_of_write_disabled_region_with_page_already_mapped(int *ptr, + u16 pkey) +{ + *ptr = __LINE__; + dprintf1("disabling write access; after accessing the page, " + "to PKEY[%02d], doing write\n", pkey); + pkey_write_deny(pkey); + *ptr = __LINE__; + 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); @@ -1422,6 +1433,7 @@ void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) 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_write_disabled_region_with_page_already_mapped, test_write_of_access_disabled_region, test_kernel_write_of_access_disabled_region, test_kernel_write_of_write_disabled_region,