From patchwork Tue Jul 17 13:49:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529527 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 D95016020A for ; Tue, 17 Jul 2018 13:51:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCAB32921E for ; Tue, 17 Jul 2018 13:51:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEE2D29225; Tue, 17 Jul 2018 13:51:22 +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 5042129221 for ; Tue, 17 Jul 2018 13:51:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A30536B0279; Tue, 17 Jul 2018 09:50:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9B7576B027A; Tue, 17 Jul 2018 09:50:42 -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 7BF4E6B027B; Tue, 17 Jul 2018 09:50:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id 457D76B0279 for ; Tue, 17 Jul 2018 09:50:42 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id b8-v6so737095qto.16 for ; Tue, 17 Jul 2018 06:50:42 -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=2r5cNzFLeSs/K5pqni8TxL9LDzfe8+AFTceAArQnt58=; b=W/dfdbzMja3ZndBHQYhCuGkfL7I/GT7etAaA/gmBw5fi2tbVh4Ty3UY2F9ZYY67jEL EJ2kH1Ig1tvwG4/TOw3DWGsMJKcSxg/2fIU4LrJEuTciU6IOMvgxpyqQJ5WlRYxivnQL peZOTMaY5Qq9OVtP0Bga7o4CtdUsy4OdZD74WJt13zhfFWBGGQh79F8uSyzPdwgxu0I8 6VmGG8F3MfX0A4NyQTM+b1N2aSyJ3biliD4YPoQsUdCxgVTLhw1DjoMyB3KycEaYHxwN CZ8qo1ds93LqSJ7fVWsczBi0BpKJLWFg+8IyHDp+xxhPUCtYmnm4oLsvji9eKtB7QLuW NQFQ== X-Gm-Message-State: AOUpUlEk0tDqgQL1mmlxP8cyitiVATGm4g0jERgKHPEYbd5paYyz3BNx n+LPb/EEP2GbPdpPKcns21Fo5NIquMqCkcIwtXg2Pf9mIymwgb1S47Re4r4dXWReCv/jzHB05bk CWYF2z4eP6FG412/8W919y2at+ox95HTRISn52LrqTvWqzsDN9j8hJR4PTMyG+dShg6HP14NY3P jft/z9N8N799n0+DAwHkb3lTPctzDA4/4ameNxBBpAp7AABM95X4PMs7TTZhGq8RbP3sayRga8j Hbwq41qe+ABdFMms6sW+BQFfa61o4V4lDVfoN6Ci+NPP4OE4ao3b3k/KILe1HdAn7uEztXX1SSd UiJKaA4ODLHcsdVCpCy5Ff5swIZKIWI2lUU9HyE75uNHqq2zfGjG1P/HUa2O1kHc6/Zes3m2gw= = X-Received: by 2002:a37:350b:: with SMTP id c11-v6mr1508535qka.88.1531835442048; Tue, 17 Jul 2018 06:50:42 -0700 (PDT) X-Received: by 2002:a37:350b:: with SMTP id c11-v6mr1508485qka.88.1531835441199; Tue, 17 Jul 2018 06:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835441; cv=none; d=google.com; s=arc-20160816; b=IifBhPHUKXxba4a8SlUihXkSIYCV07+L6TeKh7BAqmoAoMxscPXqriWTnXXCKRv1y+ bTl0i8AwUmKwrjLVcrMwnIRu0FuoRzFivwSBF972RekDmIOh61QsxnV5KJT+rh+95/em Ag9dpBpZ6GK13A6d3Ue/U63ILPYR9KK4/ZCyX6SpZLcXR+WDqMtwjxRPDHNx3xsCKaNc aWT77kG+Dr6XvQYLzvQY8+Lk9ALxiQWSgrMs+p1dbT9vDpbKiQmD30YGG6YVd/UwpT/k k4rwnmLKG0BwlUveidaw90aBvCTrRQ/MSnuKOM8l9Nd2H1g1JWV/nrmt7bl0lwAfsvnV 5oVQ== 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=2r5cNzFLeSs/K5pqni8TxL9LDzfe8+AFTceAArQnt58=; b=wDi1Pf8IW29zBgSLzV0JfyyGa3SHmhosx3cnzqcNSrKt4O/UnuikeZhtVKkuBEFJkm B7HjX4zqVx0yKaYrPMDMvVLeMe6n5W/QFHtLJydhfQHZnUjUPyTmDDyRjf8hGQwxf0mg +HGNtsqCIVdEyzyNjNI8xPKUebO3VzZztNE5aF5Ze+5fIZwoaniZdrOKP0S9oWjS5ZXy kRHKlYryxmXnCCdgWgbfyNMq8EtHlEL1os4JrY420zeGSxy8Talfnfv/KAXnh0nANdt+ Nh+lTOILfcWlvnlut5906CMvqQ2NxKyPbLCI7PBlAYXyo6ig43hAvqC9VS43O6ntb+Gz 6p2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NsemcX54; 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 d38-v6sor499822qtk.51.2018.07.17.06.50.41 for (Google Transport Security); Tue, 17 Jul 2018 06:50:41 -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=NsemcX54; 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=2r5cNzFLeSs/K5pqni8TxL9LDzfe8+AFTceAArQnt58=; b=NsemcX54Ab2eHV3gr3dGQEaZj5kaq4ANx8CQ/F3eCDHdWyrdUUJJDY9rAm0s87u9aH 8wE/0rCjA61HPxnRtz2oE9UixHydKdn0+sdqjuPP+Y4IamXiovGza9Msko7ZZIPgNVAB /1I+NtDRJ5DlxUV2TxWWcA+DnvlKRDhLr7y4XiG6/wuup9kvb2mu8dbJQqeoPVTOnIJ0 cZLqxohZ9ZyGxf3i/xye+z5OQM8Bdrd+jMdIGXUx6cezqSCscXgnU6Q60xl9ynb83G9O YfuENDAyis+LwF2Zuv7yyw9vzclRwxY0yFzZZQT6fScN/OPg54QHOVZEUYU0HMWVhpde zh6g== X-Google-Smtp-Source: AAOMgpcwFK68KIESRKKvrTajlz7/8yINdJHTqveLX6QSygzfQxNLzunj3DidF94kEPz6jaFgughvEA== X-Received: by 2002:ac8:174a:: with SMTP id u10-v6mr1595982qtk.367.1531835441007; Tue, 17 Jul 2018 06:50:41 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:40 -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 v14 18/22] selftests/vm: associate key on a mapped page and detect write violation Date: Tue, 17 Jul 2018 06:49:21 -0700 Message-Id: <1531835365-32387-19-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-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 d41b2dc..59f6f33 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1038,6 +1038,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); @@ -1417,6 +1428,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,