Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2299061pxm; Fri, 4 Mar 2022 13:24:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJydLtnOuoEuGT+MHi40KVdffoTzlMBHk9scLXGHqf76HQneC8yb3LQO1O5OubYNBDfmYwFd X-Received: by 2002:aa7:c244:0:b0:416:46b:6237 with SMTP id y4-20020aa7c244000000b00416046b6237mr419935edo.139.1646429045645; Fri, 04 Mar 2022 13:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646429045; cv=none; d=google.com; s=arc-20160816; b=nDTioHCwDmcZ//CgLxDINO1/VlIzNc7vcYTzlWZxbObjANYLcX58lqrQD5vcWz0w7D h5RZXZo/R5nXNlyJdMdRMYWqA1QpkvvbK6D308rE+cItA66WjqRorwseB4NFWcmA+q1e rdvlrNV8ecNi7F+KvvDTsIUVz9D5EgNSoQtAX9/8ZV273aJe9Ms0piAwgMYBjqIIYhlu kA2Vgn+GPmMiQFbzXS8YPCEI9Q6EF3VzkDWH38X4/3x//Qjg2hTqFkj6J7cvmLv15lWa 7gT5q2SxrgpMXPPHFaa4BAWbWVVWZTcaJzIlBDvVJz8/Epyi1Mpy/GrjwjKQfcVh91pP r/GA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=a8fHih0Us7SdMTTUY/BPLu/APJVVKHVuro+Uf3y4xqM=; b=nRh/cG1a9AllamKPD7qsKyW6ElzOwLy5a66B+ObrK36kFHqDP7SoWzv/ptiassA+VS XRhGS0eKrXuSxxGolQx6VKr4cYp5gq3V9MIMpCD8fm/l53it+NA2iqyEBoesnnkiFhFY 293k4LdHqeFVCfNbXLYvsxWR5NnRIFBGCmIcZ8PerNhurIwBXVbWNf115i1Mz5rBBj0O cKWo2OfEQBIXTJJpwQxCFfgDJYqm/O+NDJGLSH3pc5N95LTr5VhSZ2VlAeeR1WEO/t4T WL2ij09qY9Ijk75BOyHWIm164luranccLbJLIG7vgaLVd1Uwjp96jMp7OAFF657q21yh cFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QmEzqadH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a05640250d400b00415ecdbbb41si3513945edb.160.2022.03.04.13.23.41; Fri, 04 Mar 2022 13:24:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QmEzqadH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiCDVGi (ORCPT + 99 others); Fri, 4 Mar 2022 16:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiCDVGh (ORCPT ); Fri, 4 Mar 2022 16:06:37 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05F44DF497 for ; Fri, 4 Mar 2022 13:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646427949; x=1677963949; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Y39UWfeG5t/f8koENMZSdik7oyaXSsbs1Bgp7FvTwlY=; b=QmEzqadHZSkha2QtZRjuMC7q8Z2di6L/1bqE7vPcqSrUffeqxsTFiumw WYXoBGNEBDYp97GRP0T9lO6/Ow8yCCv6ls0BMRXArfOdVCqPRTyiFnMpk PMrVRbLheKQVx8vK2QJYfNqobEqMJj+8ma54O7fulirxcEFbArB8lUGAj vKN/2ctWBlvk5EjeynLA5igi68va318iU0Z5okkLmCFTuroYCGZw0TSSs CPuCcOaDig29g69YtjVCRLUvmEzgEbKAWEzDsy0P5baY+XMw+0HysR/f/ oTbWuWcnZVPmIaTngNb3hTdMsjoY5ZijLdAKNuGuCOcZN8Nv1FLY/+o5I g==; X-IronPort-AV: E=McAfee;i="6200,9189,10276"; a="252891284" X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="252891284" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 13:05:48 -0800 X-IronPort-AV: E=Sophos;i="5.90,156,1643702400"; d="scan'208";a="810884761" Received: from fushengl-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.64.239]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2022 13:05:48 -0800 From: ira.weiny@intel.com To: Michael Ellerman , Dave Hansen Cc: Ira Weiny , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Aneesh Kumar K.V" Subject: [PATCH] pkeys: Make pkey unsigned in arch_set_user_pkey_access() Date: Fri, 4 Mar 2022 13:05:43 -0800 Message-Id: <20220304210543.3490880-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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. It is always best to use correct types when possible. 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 --- 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 753e62ba67af..c048467669df 100644 --- a/arch/powerpc/mm/book3s64/pkeys.c +++ b/arch/powerpc/mm/book3s64/pkeys.c @@ -333,7 +333,7 @@ static inline void init_iamr(int 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 5292e6dfe2a7..48efb81f6cc6 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -9,7 +9,7 @@ */ #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, +extern int arch_set_user_pkey_access(struct task_struct *tsk, u8 pkey, unsigned long init_val); static inline bool arch_pkeys_enabled(void) @@ -115,7 +115,7 @@ int mm_pkey_free(struct mm_struct *mm, int pkey) return 0; } -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 vma_pkey(struct vm_area_struct *vma) 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