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: 10463113 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 29544600D0 for ; Thu, 14 Jun 2018 00:48:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BF8628988 for ; Thu, 14 Jun 2018 00:48:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1025D28BA8; Thu, 14 Jun 2018 00:48:00 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98C0928988 for ; Thu, 14 Jun 2018 00:47:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE3A26B0286; Wed, 13 Jun 2018 20:47:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A1D1A6B0288; Wed, 13 Jun 2018 20:47:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E86D6B0289; Wed, 13 Jun 2018 20:47:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id 5B4006B0286 for ; Wed, 13 Jun 2018 20:47:25 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id p85-v6so3512410qke.23 for ; Wed, 13 Jun 2018 17:47:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=qqFDmIxgxNpw2/anSLkzhIk/EvGSPAJyjRm2/9tJDyGzREe4pfz/q/qOhuTJ+74/oN dCxFMAQiRhhGDs5plxlCn00fN99sLZRE4wPXVNTBCVQZGr2k+io1fPB5Rqkyt9Akwp6q NYxlmMUSd18hV/WnlJOXsbD2HTIVl9a0GRWGnHs8UfW+6lFQd9vI8/LchMr/Dz7VDhVk EDB8It3yqAN5/E+M3/qd6/TgUF2NIjroQF1RFj3nWrUQ1mPmbwY4wakul/Sb0W0fF+W/ DlKUMLPXSn3Lf31hT8j+UyNw/2A0bBqWgFeoDzxarc/w8yFf0iNmCv1+qYYTboQtAhwf Z9vQ== X-Gm-Message-State: APt69E0jmN9scrAqglTavlJhF/1xc/NepKF0e6xJJJHMJRmEvnGnfDFT PcRn5+tqStdYmwdK7yBO/PGjxYZj5tByPw38Gw4h9XS6NKrI3oGcLM8J7q1289sKoRQ/gTvrikA qiur6SUcO+xevS8a1w1VzLs4MVpHDS+h1TRSlLvL33lzWQTDlUTrOPpeanqHmB81bNljHmFaKJM gZsocuy04gOSR2uitZzUlqbiBpVAAGIAHw0ICoaR6HBApBTifFwQNa8PpUT1+UrgDDL3aJR0cR7 1OQTtdR7rNUbzQyCzoWDafbwZuKpIRKdHugQtdnREEFTZ+3zU0VF0E0Rz/l7974kCLLubu0qX1+ eguye+fYuTwQNshiTmV9n1nZgPBTYks8rEvqCw4t3mIKKNznpY9J2075lGpqrOLp8ZlcNzekBQ= = X-Received: by 2002:ac8:112:: with SMTP id e18-v6mr352855qtg.91.1528937245186; Wed, 13 Jun 2018 17:47:25 -0700 (PDT) X-Received: by 2002:ac8:112:: with SMTP id e18-v6mr352829qtg.91.1528937244415; Wed, 13 Jun 2018 17:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937244; cv=none; d=google.com; s=arc-20160816; b=xB/8t/Ag4ZY1gda+8DQXSTX9Q3LZtVlMS8bN+JSB6uVR8X5Dyo2im+FtSVqn2e49uj TVSkfsrEbt3lncGCmN3+pa9PALFYpVqhsjN0mLvpTNH416TxYa/0xFAnMxNBNlzKYbqT LlpQdF/vVOw5tRR/DnbHhD6V/ZEqJN5+Ga3fLPv4y/7gGf7H3DHBBYNb9s90mWfDLHWe 9RFxtqO2f2wROAlobWCcigggI5QdhT3nHsLhSwfunxYfY7dR6s8RXxeZ3QKk8ZK4XGsW m3vIv8MaRdRipUyiwvS/LIoUQK8ef8FZbwZT0jxCAj7sbCZTZAxr4seQKjwljXWN0+ZV kx8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=cGV6PVozN5CBPDCYZts951aT/8GuQ4CwLZ1RGk5TXkU+7tW1DyHINxoowJTbGrsK+m 5PaqzcanFSl83XPhdgUCSSkZ4Ukpshccir3Uvu40vUNcXiNxNRsT9k/95DuNnaru46Lj mHHqML3M8zI54EhHjcqBbMMNpCMGZGcsHlrAme8wLkKhRk+8Z8x7wmF2sPIIm5NVQ/7W 4uBteCiS7IXAolA+4UHxH90PJuSMcXc4PuGcdls6FJ92dGaVTwTFEJDN/i30KMucpyCF TybvU37VcDRD76+5X1bnichzmudHFlWhjxEywQGfVV9Dt9O+xl0Uk4QUFIEwy4Tay8YJ JCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aqI92FA2; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 4-v6sor1805201qvs.88.2018.06.13.17.47.24 for (Google Transport Security); Wed, 13 Jun 2018 17:47:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aqI92FA2; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com 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-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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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,