Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp711161rdh; Wed, 14 Feb 2024 09:06:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVjHnqgIMoxX7jJHub8JnAOITY4m7VtSd8bWGbeW3mziFzXJeIVlqRd/mMCsyfnUOEeYE3X9RZpJVRLY+D1Dq+C1bjsiZWGIt7VEhl3UA== X-Google-Smtp-Source: AGHT+IEIOA/wP/0840UNlPG4UYEUguoCxpepVqL993O/dfpj8sYFHf+SYIzjUEUdlzVtEMivkcfE X-Received: by 2002:a05:6a20:9f07:b0:19e:4e58:b4aa with SMTP id mk7-20020a056a209f0700b0019e4e58b4aamr3804388pzb.54.1707930396866; Wed, 14 Feb 2024 09:06:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707930396; cv=pass; d=google.com; s=arc-20160816; b=TsI73NB3/yER8DajhLXsl+6xWmStu/Ge3IKqIpes9iMYvMTt6mJAzhid37WSrMMuD0 DXM3+li0MujSc9+LuRSLftmFVEwONcDExrIlknEkS1RfY7mYllnOZIwwZ3DJ/XVlXOQO cbGC9RWtmMlRknch7ddtrU+zKaHARApQdreNvX70/jVuoOqGFCagdUCPlnwPk+gsRvxN FgNgXl91KrLtKwuHFkMELsRqNRNqxM9VkY1QcLPmh5yNc5M+sT4ut5+NFLAxaVI5hO+C drdSTY3bbZFnKW/NctNA02cvowLK4XiFVN0uVM6Gn2U1dAWqzpV6r6dtcNe5Ghnmdpmh sBsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gjHliDjaeUpRoyF3DIVnTOoHY/LcPuUweXzNonR4Zs4=; fh=ykmGHumVtRhSMAOGWuL/3k6ItYIxpjd3OY64risuhQM=; b=V70aLLC3qnXhaOAQdUWuDwMPYHuHuc5GrUg3cNq/3a8jiaaBWii8OhhWDT59OuwHH3 Xqk816YaEqBnehgXA1Gyz/u7YDp7mvzpyqWT7/T8FrYDAINwHyjESnm85uigfvY8x4pE 1Upp2OWmhQMtJed2oCoQjrM/99b9+nDUv1EyDem9D6ofscrii0/Hn1Cqii8ksJMg1Hnz iQExK3ByGcd70xlg4FvB6tK50XH4PVZChg7Wrlx5pNj48MUSXTlRy2Iqu0OlTF72Kpe9 0HHofG39JO4EoJYmMuu76wJU9bTQHWq4jh11oBN4JiQbZMNVItQGBssj+78ptDfZgABO M9XA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=rlNYvQ0G; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65554-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65554-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWMlJIDHzi6bRlb/KOGDsX1QoYkfqaPUu0VEDasvSgl+zoJWzurfqupYLGC0Rzh/f11k3b744v3919YlSxeEg637vkwvP7324Z1lGDNwg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z27-20020a637e1b000000b005dc484eaff9si3912493pgc.483.2024.02.14.09.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:06:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65554-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=rlNYvQ0G; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65554-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65554-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AF631B2D39B for ; Wed, 14 Feb 2024 16:36:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01A1B62171; Wed, 14 Feb 2024 16:34:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="rlNYvQ0G" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F78060EE5; Wed, 14 Feb 2024 16:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; cv=none; b=pPhXplVwxQ/GWZ9bCZb8Lkk4OX1YuNts0I55DETSYmGUdyq1/eMbuaxJnxNJtYNX7sae2ydM+SwP7FmTDb1c0gRAzXgR3RK8fIDUtETPAADLk4RwYWhZMhs2C6NZcceCnFjDDgek/S/LSWEUdH7C2eBCUZWSjrPsl7xC4jr4pf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; c=relaxed/simple; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RGpFaEAJPRQleEu4Z0hwdM8Ps1+neZckYmevN/T7TeWrZX3QikUbDRSYCueWdaAYWmq4hTJg8raN+BLEILO/+8f8cc+2+fgCl5259MtKdiixUxD85ySRkYxy8gop6KqK5LxfjE8Gmmlpbo6xKn+1BZkRL5Vzyo727oKHT42FowY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=rlNYvQ0G; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928442; bh=RLw0Ke+gAZcjvLomlJhUe4+W8YYZZSg0ARVq9aMVCrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rlNYvQ0GW/S/jXNaAYENVYlNVf23pL9YeFrT0eWgiytcNZT60OP/wdnkHkTCCOif8 VWOOPEtMhrEVmGABPOn3H/AfPxUBKHwvhvVHkisAOM+jXlQx3QdZXAqSzKe3DF/xTr fmniFaUIbwsr6uNI8YNTQc8QnakMysFZIWzPOcQg= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 4A01D601C2; Thu, 15 Feb 2024 00:34:02 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 2/4] KVM: LoongArch: Fix kvm_check_cpucfg incorrectly accepting bad CPUCFG IDs Date: Thu, 15 Feb 2024 00:33:55 +0800 Message-ID: <20240214163358.2913090-3-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: WANG Xuerui The return value of _kvm_get_cpucfg is meant to be checked, but this was not done, so bad CPUCFG IDs wrongly fall back to the default case and 0 is returned. Check the return value to fix the UAPI behavior. While at it, also remove the redundant range check, because _kvm_get_cpucfg already rejects all unrecognized input CPUCFG IDs. It was also wrong and no-op, in the same way as the former identical check in _kvm_get_cpucfg. Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support") Signed-off-by: WANG Xuerui --- arch/loongarch/kvm/vcpu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index c4a592623da6..cc2332b056ba 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -328,12 +328,10 @@ static int _kvm_get_cpucfg(int id, u64 *v) static int kvm_check_cpucfg(int id, u64 val) { u64 mask; - int ret = 0; - - if (id < 0 && id >= KVM_MAX_CPUCFG_REGS) - return -EINVAL; + int ret; - if (_kvm_get_cpucfg(id, &mask)) + ret = _kvm_get_cpucfg(id, &mask); + if (ret) return ret; switch (id) { -- 2.43.0