Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3690578imm; Mon, 18 Jun 2018 02:21:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIpDQuNTFEJqkgaNFpAl7vmNzrjx36eoy+oBxvJA+FuBuNfozc0aZfG67mcH7b1axYQsTEw X-Received: by 2002:a65:66c6:: with SMTP id c6-v6mr10304392pgw.76.1529313714708; Mon, 18 Jun 2018 02:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529313714; cv=none; d=google.com; s=arc-20160816; b=rg+TfBvDZ6wGp+hCMutOK1UeUJbsjgFZSWvNr3pDQVAOsptGxn0R1i6kfITzYqKvdr Os8jnWvZsx9SuyOh+yxPmM6R/UU5Hgw4a3CM1iJ8jhj1iNGYtUKLx1bOt4lwReuBpILP 3MwFW87X5+9WuzF1OVvSHsCyHKi3foenjYD6GKbxfmKVjlZq+n6feRW0QRnUiGq2lr7L /s5t0EeY+a9AT5/f9cs6F2s4CkoyYu9HstJbpjGMklB3fS1pFtCifxuZW7dDhkTHwM9x 5FRhn85Ck/xYnwvgEdm44XHWmSluOnd0y1XCpzhcPx/7bKbaES4H+yq+pb4remxFBTyo U1RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4Edk8mcCkNpmAExd307VxplCjNaamcu3DXDNaoMhr5I=; b=wrCMBxdVpRlm+6qBjirVuq12FKNVK/JCfJxVzOvLgy3Rrr2dQBE6m0fvXAEtwiWssq c5cQoathoQtspsYShHjXgNHOUdYdmuP8Chfny7l6Pw9duF0KAjcEqvVkLARXlYjKNryu r2qEHwyyInXiJcoQ7XhItyp1HRXXaiDJN6lFUyUrI0vsmwImIF9mYrWwvJhe4hCGaOSn 4SpH3qnRMvXv3sm8fz+UQoHIIwijUFqW3EXLlCgMFOWJQWkTVCN5Y5hpjRqwgZdNaSJK f4wg4M/DlsAENsJxfVC9EcqKsXvITMGFNHp++uo+xj5CKwnxCaGQj6vUvWtqM5Q1PMM9 XTpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n21-v6si9992853plp.31.2018.06.18.02.21.33; Mon, 18 Jun 2018 02:21:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966566AbeFRI2D (ORCPT + 99 others); Mon, 18 Jun 2018 04:28:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58466 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966524AbeFRI2B (ORCPT ); Mon, 18 Jun 2018 04:28:01 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 667E3C7A; Mon, 18 Jun 2018 08:28:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Andrew Morton , Dave Hansen , Linus Torvalds , Michael Ellermen , Peter Zijlstra , Ram Pai , Shuah Khan , Thomas Gleixner , linux-mm@kvack.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.16 244/279] x86/pkeys/selftests: Fix pkey exhaustion test off-by-one Date: Mon, 18 Jun 2018 10:13:49 +0200 Message-Id: <20180618080618.870305371@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Hansen [ Upstream commit f50b4878329ab61d8e05796f655adeb6f5fb57c6 ] In our "exhaust all pkeys" test, we make sure that there is the expected number available. Turns out that the test did not cover the execute-only key, but discussed it anyway. It did *not* discuss the test-allocated key. Now that we have a test for the mprotect(PROT_EXEC) case, this off-by-one issue showed itself. Correct the off-by- one and add the explanation for the case we missed. Signed-off-by: Dave Hansen Cc: Andrew Morton Cc: Dave Hansen Cc: Linus Torvalds Cc: Michael Ellermen Cc: Peter Zijlstra Cc: Ram Pai Cc: Shuah Khan Cc: Thomas Gleixner Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180509171350.E1656B95@viggo.jf.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/protection_keys.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/tools/testing/selftests/x86/protection_keys.c +++ b/tools/testing/selftests/x86/protection_keys.c @@ -1163,12 +1163,15 @@ void test_pkey_alloc_exhaust(int *ptr, u pkey_assert(i < NR_PKEYS*2); /* - * There are 16 pkeys supported in hardware. One is taken - * up for the default (0) and another can be taken up by - * an execute-only mapping. Ensure that we can allocate - * at least 14 (16-2). + * There are 16 pkeys supported in hardware. Three are + * allocated by the time we get here: + * 1. The default key (0) + * 2. One possibly consumed by an execute-only mapping. + * 3. One allocated by the test code and passed in via + * 'pkey' to this function. + * Ensure that we can allocate at least another 13 (16-3). */ - pkey_assert(i >= NR_PKEYS-2); + pkey_assert(i >= NR_PKEYS-3); for (i = 0; i < nr_allocated_pkeys; i++) { err = sys_pkey_free(allocated_pkeys[i]);