Received: by 2002:ac2:48a3:0:0:0:0:0 with SMTP id u3csp574649lfg; Fri, 11 Mar 2022 13:47:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeRRxAngBI9DWp6PRqHI8vejTG6QnAqYn7k9j0/Fp+XBLMNdtSgftQ4ebHTQKz4EKjBcuB X-Received: by 2002:a17:902:8a97:b0:14a:c625:eb2d with SMTP id p23-20020a1709028a9700b0014ac625eb2dmr12516074plo.26.1647035244743; Fri, 11 Mar 2022 13:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647035244; cv=none; d=google.com; s=arc-20160816; b=fBIujcQH/TbTUJDSF3zKIckvVX8UE2tT4X/7gS6ZHmdK+OSMwRdSlo4P82G9lUrYBh u86uXzFBwcmRFwI9JpWoy4HM3qrlqz6v5EhjYNBebHxS7oPilT08vRuBixiTfKrIiQcq UR2ZVvcdQHUPA6ezOnYMsokUkCX0SyveW/vPkAwujQ60teGNq2JfZL+2okgZn59ylySi 0eIWA/5d2Uo+Li2o54tQW3XpgjS/JRXYnIytyT+MVGzA7TsjSQWsH4fON91a4R8Famj5 pwPdBfLj0lrs2a+k2CJeMuHygYAFI67SBlGKaAfKx7H+vy16tZamLKMWUiRSFsPW/ye5 mXUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g85D65JC8pK/zlZb1zmc0MmRpK4Pus91jz7UraXGiEU=; b=el0wHjm0WFzDQffMThftFxb/oRIEgvRdCRJmmuyO5dmcsj4igPDiFYIsbwxqHTRh3h 3426ZYOZV0AzntNdnQ02Ae3QavwtvQ+DfBDISAaGS5+nVuWtedkgBFSfrIRO1wQjLZrS XPH3rOsNy7Yp4fIGkMpmjMzwUn3F0TP+TWdXVVYDORxJkB5AYDT2n0S1iOukit1cirbp l4iJWvlJSyZxeBRjJWqanJ7ObQCcGPJlFSXUo5ziLz+0/uKEQr4RQc+76P7yihYaIcee iXiBiw1H1Ggy6LvIghPzFP10/kVtzc0vng1YSHsURzHxLisC2mafn+AQ/pfEA+4wwvtp 6Aiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UKFN6VOg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r14-20020a6560ce000000b0036c644f03casi8662482pgv.89.2022.03.11.13.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 13:47:24 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UKFN6VOg; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 587B61FB53E; Fri, 11 Mar 2022 13:09:29 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344383AbiCKA7n (ORCPT + 99 others); Thu, 10 Mar 2022 19:59:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242302AbiCKA7j (ORCPT ); Thu, 10 Mar 2022 19:59:39 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF9BE98E9 for ; Thu, 10 Mar 2022 16:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646960317; x=1678496317; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vM08ag580GDO+fflJK8POCmsH9pEVzp+hsefHBAzboI=; b=UKFN6VOggJXZZhr8qfbd/1cZb3GWMGD9TAhg7gZsylcIzUUQlyoLGTH1 TNHh2t2P7qjHER7oWOzDe+qsUykxUGHXR4NPRXOrzrtXoaCBIyImWK3MC U5Ksay+svtW67WQNpioyEGpXcswF4nfQt0NK5fAJO8ZXeBTCj7XyWTbpf Bv5KWzUqtyNOc+NE0Gdk273C74Ky3Mnw4wWqG8FAfAzK4FFjr5rw5JOw8 2VGh87Ua7Z1VstruYJZWm/PoLugGMP0t4dSn23L1ISr27nMMbus6ZsL2j ot14TdHFoXELgGU//4L/bW+YiDfzk8K5vuq+UvTqKosfc0drcP49JWgQ6 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10282"; a="255405822" X-IronPort-AV: E=Sophos;i="5.90,172,1643702400"; d="scan'208";a="255405822" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 16:57:48 -0800 X-IronPort-AV: E=Sophos;i="5.90,172,1643702400"; d="scan'208";a="511163178" Received: from gdavids1-mobl.amr.corp.intel.com (HELO localhost) ([10.212.65.108]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 16:57:48 -0800 From: ira.weiny@intel.com To: Dave Hansen , "Aneesh Kumar K.V" Cc: Ira Weiny , "Edgecombe, Rick P" , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mm/pkeys: Make pkey unsigned in arch_set_user_pkey_access() Date: Thu, 10 Mar 2022 16:57:41 -0800 Message-Id: <20220311005742.1060992-5-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220311005742.1060992-1-ira.weiny@intel.com> References: <20220311005742.1060992-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny The WARN_ON check in arch_set_user_pkey_access() in the x86 architecture fails to check for an invalid negative value. A simple check for less than 0 would fix this issue however, in the call stack below arch_set_user_pkey_access() the pkey should never be negative on any architecture. x86 only supports 16 keys while ppc supports 32, u8 is therefore large enough for all current architectures and likely those in the future. Change the type of the pkey passed to arch_set_user_pkey_access() to u8. To: Dave Hansen To: Michael Ellerman Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- Changes from V1: Make this part of a generic pkey clean up series. --- arch/powerpc/include/asm/pkeys.h | 4 ++-- arch/powerpc/mm/book3s64/pkeys.c | 2 +- arch/x86/include/asm/pkeys.h | 4 ++-- arch/x86/kernel/fpu/xstate.c | 2 +- include/linux/pkeys.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h index 59a2c7dbc78f..e70615a1da9b 100644 --- a/arch/powerpc/include/asm/pkeys.h +++ b/arch/powerpc/include/asm/pkeys.h @@ -143,9 +143,9 @@ static inline int arch_override_mprotect_pkey(struct vm_area_struct *vma, return __arch_override_mprotect_pkey(vma, prot, pkey); } -extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, +extern int __arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val); -static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, +static inline int arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val) { if (!mmu_has_feature(MMU_FTR_PKEY)) diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c index d6456f8846de..310feb9efd57 100644 --- a/arch/powerpc/mm/book3s64/pkeys.c +++ b/arch/powerpc/mm/book3s64/pkeys.c @@ -333,7 +333,7 @@ static inline void init_iamr(u8 pkey, u8 init_bits) * Set the access rights in AMR IAMR and UAMOR registers for @pkey to that * specified in @init_val. */ -int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, +int __arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val) { u64 new_amr_bits = 0x0ul; diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index 2e6c04d8a45b..3f5c236e34cd 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -9,8 +9,8 @@ */ #define arch_max_pkey() (cpu_feature_enabled(X86_FEATURE_OSPKE) ? 16 : 1) -extern int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, - unsigned long init_val); +extern int arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, + unsigned long init_val); static inline bool arch_pkeys_enabled(void) { diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 7c7824ae7862..db511bec57e5 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1068,7 +1068,7 @@ void *get_xsave_addr(struct xregs_state *xsave, int xfeature_nr) * This will go out and modify PKRU register to set the access * rights for @pkey to @init_val. */ -int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, +int arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val) { u32 old_pkru, new_pkru_bits = 0; diff --git a/include/linux/pkeys.h b/include/linux/pkeys.h index 86be8bf27b41..aa40ed2fb0fc 100644 --- a/include/linux/pkeys.h +++ b/include/linux/pkeys.h @@ -35,7 +35,7 @@ static inline int mm_pkey_free(struct mm_struct *mm, int pkey) return -EINVAL; } -static inline int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, +static inline int arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val) { return 0; -- 2.35.1