Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1243723pxa; Thu, 20 Aug 2020 06:35:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHorBJgiHaK9t6TQyzpz3kwRaedK/2X/EVMMveD/LBwVPop/YB/E72FJ4hiuohICznkATB X-Received: by 2002:a17:906:7f0b:: with SMTP id d11mr3547892ejr.116.1597930554283; Thu, 20 Aug 2020 06:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597930554; cv=none; d=google.com; s=arc-20160816; b=yCAGPYkrycFyINc2mhJRdAlHtHgdQpMvLn9+al4xAQWUbgjT6KUgPA23Yo0Q74rVQs WR4cBhhlpZS9QK43REdC6F9Ja+KnIv2vQa1KlfmmdoGNGK4L88lfZMHRxXbItfiO9E9W +0+qC/rgDriPxV4QcmDcm9qtvRrYx0EDRqnHbwql4pzDnAxibHRtInu9MqIA6GP4PfB8 PQiHCYT1+GF5SD5k3BdwnLDv0yRC5Fozwcl1w9mYCepNy/jzhnQkzM2cmPSSFCxThZat tNB3jwgilaYun8iP8xjMLDLIU3U2a4IgSoVmmP6aT4zRRz/26wHWrfpFg3NtD0Kw/fd2 VlHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HyYrqO/JDDP/S70jfWVr6VMrB/8oQv3qYBpQCNvC1NI=; b=YnW2KXGNkdQIbx1Or71QmgxH7z7RTjUH+cBVraDpRJIao20JPLXeVRNxsMVNVH4iAx rEy7wXN0rV9bj3LF4n+JSY79m8va37DK2SiHfL1ECN0//Yff9c4yL0jstyB2b3EJ/94H i+zFTCHjMaDmfU29Y4EGKAKTriTPKK1VX4XWyxayJvbe01wDnq7NyTC3cOJjGuJmQ8rt Eol7XWx/C1gVOVXKaj1gQiE9umBFnXpL2LKuK+uitCFTSdcMI2lyyCAr+8EvwMQexi9s UrgHq5G25UNLs84xnFf0HvFSyc7xJxGmXkLuWxYij8tHJFXjdzyXcqPDmhOHNd4iLR4T 7sZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lUssC45K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si1383332ejl.636.2020.08.20.06.35.29; Thu, 20 Aug 2020 06:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lUssC45K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729070AbgHTNds (ORCPT + 99 others); Thu, 20 Aug 2020 09:33:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:41348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728183AbgHTJas (ORCPT ); Thu, 20 Aug 2020 05:30:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19F7F206FA; Thu, 20 Aug 2020 09:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915847; bh=FIf245zXysx06zrfB4Thg/nzHVS7fWcttgKSzi+mJQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lUssC45K8j8/29+8aCJvaIA+xN9cxYi/GAEb696wCizTI3jpzim00K2TvdoI9WstZ kY+dghzzwYBTVtsAY8P8/gcKUplc4SulKt2gRM7WlCghrs0wQQ6LUzNs8qwSmI7ggI U+/qH/b9bRiwXFK3xQ6i3pXPRQ8M4+40940XarVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Aneesh Kumar K.V" , Michael Ellerman , Sasha Levin Subject: [PATCH 5.8 153/232] selftests/powerpc: ptrace-pkey: Update the test to mark an invalid pkey correctly Date: Thu, 20 Aug 2020 11:20:04 +0200 Message-Id: <20200820091620.221360472@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aneesh Kumar K.V [ Upstream commit 0eaa3b5ca7b5a76e3783639c828498343be66a01 ] Signed-off-by: Aneesh Kumar K.V Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20200709032946.881753-22-aneesh.kumar@linux.ibm.com Signed-off-by: Sasha Levin --- .../selftests/powerpc/ptrace/ptrace-pkey.c | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c b/tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c index f9216c7a1829e..bc33d748d95b4 100644 --- a/tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c +++ b/tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c @@ -66,11 +66,6 @@ static int sys_pkey_alloc(unsigned long flags, unsigned long init_access_rights) return syscall(__NR_pkey_alloc, flags, init_access_rights); } -static int sys_pkey_free(int pkey) -{ - return syscall(__NR_pkey_free, pkey); -} - static int child(struct shared_info *info) { unsigned long reg; @@ -100,7 +95,11 @@ static int child(struct shared_info *info) info->amr1 |= 3ul << pkeyshift(pkey1); info->amr2 |= 3ul << pkeyshift(pkey2); - info->invalid_amr |= info->amr2 | 3ul << pkeyshift(pkey3); + /* + * invalid amr value where we try to force write + * things which are deined by a uamor setting. + */ + info->invalid_amr = info->amr2 | (~0x0UL & ~info->expected_uamor); if (disable_execute) info->expected_iamr |= 1ul << pkeyshift(pkey1); @@ -111,17 +110,12 @@ static int child(struct shared_info *info) info->expected_uamor |= 3ul << pkeyshift(pkey1) | 3ul << pkeyshift(pkey2); - info->invalid_iamr |= 1ul << pkeyshift(pkey1) | 1ul << pkeyshift(pkey2); - info->invalid_uamor |= 3ul << pkeyshift(pkey1); - /* - * We won't use pkey3. We just want a plausible but invalid key to test - * whether ptrace will let us write to AMR bits we are not supposed to. - * - * This also tests whether the kernel restores the UAMOR permissions - * after a key is freed. + * Create an IAMR value different from expected value. + * Kernel will reject an IAMR and UAMOR change. */ - sys_pkey_free(pkey3); + info->invalid_iamr = info->expected_iamr | (1ul << pkeyshift(pkey1) | 1ul << pkeyshift(pkey2)); + info->invalid_uamor = info->expected_uamor & ~(0x3ul << pkeyshift(pkey1)); printf("%-30s AMR: %016lx pkey1: %d pkey2: %d pkey3: %d\n", user_write, info->amr1, pkey1, pkey2, pkey3); @@ -196,9 +190,9 @@ static int parent(struct shared_info *info, pid_t pid) PARENT_SKIP_IF_UNSUPPORTED(ret, &info->child_sync); PARENT_FAIL_IF(ret, &info->child_sync); - info->amr1 = info->amr2 = info->invalid_amr = regs[0]; - info->expected_iamr = info->invalid_iamr = regs[1]; - info->expected_uamor = info->invalid_uamor = regs[2]; + info->amr1 = info->amr2 = regs[0]; + info->expected_iamr = regs[1]; + info->expected_uamor = regs[2]; /* Wake up child so that it can set itself up. */ ret = prod_child(&info->child_sync); -- 2.25.1