Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp237055rdb; Thu, 22 Feb 2024 02:00:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWp+iBriSGdSPuzWTHbqVznrvHBZFLY9PMf2lqM3mL+kra6mlistC8jIoi8BSJ9GHc3crlhWXRSeYuFNFDkuQfqaT5bhf/A5Ow+ToIHag== X-Google-Smtp-Source: AGHT+IGNkPSf3Hmqu0/j/VYaVvOdQ+tQFB8tEs2n1ApjgYh4iY+1LUoRWalqj3EUp42LLPEZr9Cv X-Received: by 2002:aa7:838f:0:b0:6e4:ce12:fa7a with SMTP id u15-20020aa7838f000000b006e4ce12fa7amr968285pfm.20.1708596032583; Thu, 22 Feb 2024 02:00:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708596032; cv=pass; d=google.com; s=arc-20160816; b=nedce7X6n5esVWinz09w7Smoyboq2WJBRHkY6o3OtaJdMiFJTDwX59GvNzgqgcH5Y0 yvQ6/zO6v57VlVhEN/aL9d5trmXQmz20BR1gWrOeEq2k/nPdQIXTPkwViJpf6B1pKayy OJYU3Gehrjgltc2uWQ3VhEJRJZwprq7wz5mMRAMtVXv3eQ7xmRct/bbAezh2F8zDxj19 xM/3z2n//EAuAnCf1sxhbO4dpMx0UnUepq2PIhYDq/Pg1BVMML9gGhNSR7eCKP8QkyJY KehkL+cTBqeTPNRaAFmCu4EZzS66RHb4Lb5Y96p0jzQN2aG3ymNFtcOrJWc3Ema2ms3L 1Xaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=PYP18IaNNjPhtmhGSrzlnTu/jaHHbVI75HhQgfR3Kng=; fh=FqE1TIpHzeJwB8uy/2rCEG/vb1NUWKUrKWmHEEMelFU=; b=UQ7F5qTRgzrwSATXo8R+nhpgPx22YYFTvbCVpCQDOXyXSXU9MqLzwNXX9tcOkDSGaj LCyPzVvNGTy8XfQAKZ2uhkxTo3d+QELYGs2pshGueHDubUqDSnmoEMEmFtCyQoyrZ17N n6krCqSWDzGTAN/bDzuIvgxYjYnEji+Ow9IuC1/rzYea0perxpxHugZEhqt+Qt/V97Kf BcyLXEzA15F5J6D8ejKylmbof2deLbuIq13VxmfYrUNs8XSVV1pfVfRgqH1K9imE6xgu GSkoJoEy7fFcbn9aUIhsLv1RPZuUUgXG1xL0qd4QKvlw9govDXl7x4IZ1tRRLuCRIb5D cPog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=eHXbV8aG; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-76265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76265-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x5-20020a654145000000b005dc556a8765si9922042pgp.466.2024.02.22.02.00.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 02:00:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=eHXbV8aG; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-76265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76265-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 9EDB8B275BB for ; Thu, 22 Feb 2024 09:47:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5D363EA6C; Thu, 22 Feb 2024 09:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="eHXbV8aG" 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 787D83D99C; Thu, 22 Feb 2024 09:45:59 +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=1708595161; cv=none; b=Oe0CG9L5UgvQiFhGqm9IrOZdkRjA6Rc6besU1uCFfUkiQM3LAsNlPAwFZ0hI8WLQBaUbSaQQsTsUH5sJXjrC7FMc69W6vnOOYz4MT7ofwIneDczjz8MNzFu0g1zWIGAhG9J0oCFq0jH8PljEk8c1X+JBzedNqo2zqd7jBMr9x70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708595161; c=relaxed/simple; bh=OATWuTBcSrRQnsAQcEJVtWvg5kuTMiuCytgedBHWqcI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JoutQAYhJfQqs0yxR857Hmp2pjdJ6apy9hf1uYTudddwQG9Zm7DomUQz1OTMXHTAJpZYgb3neYA2ML2puKi7HRcagj5Nkveu/UNI2PfXO3Bn1BI5uJ4jMq3LAOPqhUTwhvUsIap4VAIqvxeCWvZtlntz5QwZ+tpoFPTC01WQTOg= 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=eHXbV8aG; 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=1708595157; bh=OATWuTBcSrRQnsAQcEJVtWvg5kuTMiuCytgedBHWqcI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=eHXbV8aGJB0ujrUWJGnfgMm6WOMvBvd3BoCoGQorjtnCQgvZNr5siYU8QCq8HHiYg nuJ2/PCENj+1bYr0jDK/3478D+blyJfmeAf43QnwnqUEVSAFZ3HYMyKuakuNXZWwlf vSCUFn/tH+H5+rkS5Oql+SFyKzP/h09m+MzM5Rsw= Received: from [IPV6:240e:688:100:1:5f9c:42f0:f9f2:a909] (unknown [IPv6:240e:688:100:1:5f9c:42f0:f9f2:a909]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 0376660094; Thu, 22 Feb 2024 17:45:56 +0800 (CST) Message-ID: <4a12394a-8ebf-40b8-b0bc-65b5a66967cd@xen0n.name> Date: Thu, 22 Feb 2024 17:45:56 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH for-6.8 v3 1/3] LoongArch: KVM: Fix input validation of _kvm_get_cpucfg and kvm_check_cpucfg Content-Language: en-US To: maobibo , Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui References: <20240216085822.3032984-1-kernel@xen0n.name> <20240216085822.3032984-2-kernel@xen0n.name> <412ea29b-7a53-1f91-1cdb-5a256e74826b@loongson.cn> From: WANG Xuerui In-Reply-To: <412ea29b-7a53-1f91-1cdb-5a256e74826b@loongson.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 2/17/24 11:03, maobibo wrote: > Hi Xuerui, > > Good catch, and thank for your patch. > > On 2024/2/16 下午4:58, WANG Xuerui wrote: >> [snip] >> @@ -324,31 +319,33 @@ static int _kvm_get_cpucfg(int id, u64 *v) >>           if (cpu_has_lasx) >>               *v |= CPUCFG2_LASX; >> -        break; >> +        return 0; >> +    case 0 ... 1: >> +    case 3 ... KVM_MAX_CPUCFG_REGS - 1: >> +        /* no restrictions on other CPUCFG IDs' values */ >> +        *v = U64_MAX; >> +        return 0; > how about something like this? >     default: >         /* no restrictions on other CPUCFG IDs' values */ >         *v = U64_MAX; >         return 0; I don't think this version correctly expresses the intent. Note that the CPUCFG ID range check is squashed into the switch as well, so one switch conveniently expresses the three intended cases at once: * the special treatment of CPUCFG2, * all-allow rules for other in-range CPUCFG IDs, and * rejection for out-of-range IDs. Yet the suggestion here is conflating the latter two cases, with the effect of allowing every ID that's not 2 to take any value (as expressed by the U64_MAX mask), and *removing the range check* (because no return path returns -EINVAL with this change). So I'd like to stick to the current version, but thanks anyway for your kind review and suggestion. -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/