From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80F6AC4743C for ; Wed, 23 Jun 2021 12:24:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C11261076 for ; Wed, 23 Jun 2021 12:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231555AbhFWM04 (ORCPT ); Wed, 23 Jun 2021 08:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbhFWM0W (ORCPT ); Wed, 23 Jun 2021 08:26:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1BEBC061760 for ; Wed, 23 Jun 2021 05:24:04 -0700 (PDT) Message-Id: <20210623121453.635764326@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1624451043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=12h4JTTW0YJqkmMVMRoBj49CzVR9KDBA7AcXATEmIV8=; b=ycAv7JMnbK/KhvR0FP66cMwMDirZ3+fo0QT0ExH41SKQzeDTH2B94SCFphS90H/BGipT3i VjB7g8q8nlrPwAtL0Dbif2TL9hoaDAHzq3BSB4TxwSC3GOW72rUCWILxiLGBuuTCdALIqq lD6j0/EaY1X4y+rJ9ovKlRcacG1dKGpPcOCL0XrG+bbJ8feXmstOu0iZKHwpfhLwQWVAnT uZW5xBqxBCnjtXn/ll2LemIKXfG8aUllkeSnTXWfuFX0xUkaCzfKq2pP5tGcsDIGwm3o09 NwXp4QNkQyxWbBnfgQgDs5ZxEdP6am4S7uxzjK7mVTWZlRjNbVLzD3j/hojFkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1624451043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=12h4JTTW0YJqkmMVMRoBj49CzVR9KDBA7AcXATEmIV8=; b=qiggz81nNHXIDwP+qYbKYbTRVCJ7ZTzN+FMQarsB/mCsgi0EsqBNLlOB3PaC9znqdUQDfx RWlDixaqNO8coGCw== Date: Wed, 23 Jun 2021 14:01:50 +0200 From: Thomas Gleixner To: LKML Cc: Andy Lutomirski , Dave Hansen , Fenghua Yu , Tony Luck , Yu-cheng Yu , Sebastian Andrzej Siewior , Borislav Petkov , Peter Zijlstra , Kan Liang , "Chang Seok Bae" , Megha Dey , Oliver Sang Subject: [patch V4 23/65] x86/fpu: Cleanup arch_set_user_pkey_access() References: <20210623120127.327154589@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function does a sanity check with a WARN_ON_ONCE() but happily proceeds when the pkey argument is out of range. Clean it up. Signed-off-by: Thomas Gleixner Reviewed-by: Borislav Petkov --- arch/x86/kernel/fpu/xstate.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -912,11 +912,10 @@ EXPORT_SYMBOL_GPL(get_xsave_addr); * rights for @pkey to @init_val. */ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, - unsigned long init_val) + unsigned long init_val) { - u32 old_pkru; - int pkey_shift = (pkey * PKRU_BITS_PER_PKEY); - u32 new_pkru_bits = 0; + u32 old_pkru, new_pkru_bits = 0; + int pkey_shift; /* * This check implies XSAVE support. OSPKE only gets @@ -930,7 +929,8 @@ int arch_set_user_pkey_access(struct tas * values originating from in-kernel users. Complain * if a bad value is observed. */ - WARN_ON_ONCE(pkey >= arch_max_pkey()); + if (WARN_ON_ONCE(pkey >= arch_max_pkey())) + return -EINVAL; /* Set the bits we need in PKRU: */ if (init_val & PKEY_DISABLE_ACCESS) @@ -939,6 +939,7 @@ int arch_set_user_pkey_access(struct tas new_pkru_bits |= PKRU_WD_BIT; /* Shift the bits in to the correct place in PKRU for pkey: */ + pkey_shift = pkey * PKRU_BITS_PER_PKEY; new_pkru_bits <<= pkey_shift; /* Get old PKRU and mask off any old bits in place: */