Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1912355lqg; Mon, 4 Mar 2024 07:29:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXJkzgQ0+0nvAT9E1en8neWxtfaLOYbTDea7V8yP1PeZNHmbxgR1ONBFYVnMPklxsWThqBA3QXsBoIdIRfKs//4DjsKccFJHnORMUHpzA== X-Google-Smtp-Source: AGHT+IFpwpn6YrMho8VpQ2WZw/r3uotjl+ElICBH+FVbzJD8MxSdUdWWYMxp40+ech9VTtuZGkA4 X-Received: by 2002:a05:6830:120f:b0:6e4:f43c:54df with SMTP id r15-20020a056830120f00b006e4f43c54dfmr426440otp.22.1709566148135; Mon, 04 Mar 2024 07:29:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709566148; cv=pass; d=google.com; s=arc-20160816; b=M6b6kLPZK8NlNzMD5UPIcMUgkllBdU1J0prAB3KbKLQZA8x9XEDAKmeWUqp6N9vkSr 1B+aktWHDXLyUsf0z7tUCRupeYs4w/TQ8YhwzoYG11bQJY1H3cKUUYmaNTrWAylm6VoD tTd0VJeq1OCbbT5NydEzENBSYoSNg7WI1sQvefeN3pYD0kXBV3J7M2x+mUk46NL9mLmV sgqQA8IQdxJzAPptQK9dvBgPxNr6hd8ZGxfQpInILDBd8nyifiWjfdmnyIdWTd80Hshd dhaE1+ehmuWwsAYot1LOtDzXzZQa5ip9evNIzyVDdujIYULqXefngiLA4nM7UjIEWt2+ VnWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Za6OurAMDFiyh38OBWdLtTGAh47kZvImvfNxaO/XtWo=; fh=F47Ybu+UOx/E0FNkzSd3HKot3TWBjf0z/zMpLphV8ZE=; b=Pf7jIvcAMjreQKVeJ4fYVZre9A4Di0vZJIsJEw0c2kVgWPygEbz6XKw8oWpmKcPxLR wQeszhSIFePONdXFKn2KhWUIGYZz9EYM30OL7ZOs06Taj0tyKxt0oGX2vNnrtqAgmrrZ 7rl/7zYAd1ZN0onvPPlFfTAS6tb3TJtmtTt6ITnLZXckfNct7lSBf4y4vrdrp0+XDFKG Cu4MO+iN+UGjoRJt8/oIn4OE/q8sleq4NizFwvBW3c51tvH7/9oqwwU7dHc5/hExnmCy N+yNp10nvRA9W5SNSSOARiol/bHasiBWcg1yi8G9erZJIQDcWUiOFnFtnq8JC3WKg8uT Oqdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B16j+h9G; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g125-20020a636b83000000b005dc529b708asi8175169pgc.743.2024.03.04.07.29.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:29:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B16j+h9G; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-90281-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CABA72832CE for ; Mon, 4 Mar 2024 09:13:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D89A81B976; Mon, 4 Mar 2024 09:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="B16j+h9G" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 52B6C1B7E8; Mon, 4 Mar 2024 09:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709543574; cv=none; b=nYFjbR6dINV4hwe2oqqwUYtowcHU6+GgJ+NVD6ejRXpd+xf7XWDZnb9MvjzbfNH1dYYyN1EkIO5pxJ2uOYYsIkFwCn76NW0F9ePmkzsifPjlsNdYijy1rrKM/xLvsV73NKquZPN61qUiijEOsFk33UjrsKkQQfZ6A7/iOcB84y0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709543574; c=relaxed/simple; bh=fYUc9MBfCK5M1i9aW28WCU7ziu1UFtyPbddQMGeFd2w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=e/RD3ogXrUDznDwGKtOVVbE9vLtoHWkeXIqoTwTNCstY30r2r19hrNHEj62eWA1h35KgZD45a6eakXOpn6tY2Qjbkm+4xFWnlJ0hrxfoyrSBNc7d0Y4tTCkZtk1HbbCQr1gyh16BFtHtO2zPbmyP5DTwI0CAiCDPJ8t7j4E7rWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=B16j+h9G; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709543572; x=1741079572; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=fYUc9MBfCK5M1i9aW28WCU7ziu1UFtyPbddQMGeFd2w=; b=B16j+h9GsWu01gWbv8pxEX4znck67+f1QR942Aqb9MYKyg5Xs+um3uv8 o3OKT2yDiHHJ6zOPeBLKfh3gcX5HUI+H7cbMh2OW2fpGqtG0lbpHuGzMg 6EowJRv85TmN1xizGgeGGNPLqk7CYU+8pm9pda6DrGxDB7WmW4KWMeUno JGJ4HpR+PyD0fuHAFlAROQQXRrfd9QRhA+iKI9ce8EVVjpFEwapolaxwg Rd3/CQaGALy+Fq/otnxoZAGQnCJv6Es/fk4FJRKjUjivc3PBBSlRhkFGG fYBY3N5+EXUD5C7p1OWqO52gjEfNxUFTBSQvZ1GFAgRjCCkDqBPjzBEbr A==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="4188817" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="4188817" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 01:12:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="13589213" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orviesa004.jf.intel.com with ESMTP; 04 Mar 2024 01:12:49 -0800 Date: Mon, 4 Mar 2024 17:08:38 +0800 From: Xu Yilun To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, seanjc@google.com, michael.roth@amd.com, aik@amd.com Subject: Re: [PATCH v3 02/15] KVM: x86: use u64_to_user_addr() Message-ID: References: <20240226190344.787149-1-pbonzini@redhat.com> <20240226190344.787149-3-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240226190344.787149-3-pbonzini@redhat.com> On Mon, Feb 26, 2024 at 02:03:31PM -0500, Paolo Bonzini wrote: > There is no danger to the kernel if userspace provides a 64-bit value that > has the high bits set, but for whatever reason happ[ens to resolve to an ^ remove the messy char. > address that has something mapped there. KVM uses the checked version > of put_user() in kvm_x86_dev_get_attr(). See from the code change, not just kvm_x86_dev_get_attr(). Thanks, Yilun > > Suggested-by: Sean Christopherson > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 24 +++--------------------- > 1 file changed, 3 insertions(+), 21 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index f3f7405e0628..14c969782d73 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4791,25 +4791,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) > return r; > } > > -static inline void __user *kvm_get_attr_addr(struct kvm_device_attr *attr) > -{ > - void __user *uaddr = (void __user*)(unsigned long)attr->addr; > - > - if ((u64)(unsigned long)uaddr != attr->addr) > - return ERR_PTR_USR(-EFAULT); > - return uaddr; > -} > - > static int kvm_x86_dev_get_attr(struct kvm_device_attr *attr) > { > - u64 __user *uaddr = kvm_get_attr_addr(attr); > + u64 __user *uaddr = u64_to_user_ptr(attr->addr); > > if (attr->group) > return -ENXIO; > > - if (IS_ERR(uaddr)) > - return PTR_ERR(uaddr); > - > switch (attr->attr) { > case KVM_X86_XCOMP_GUEST_SUPP: > if (put_user(kvm_caps.supported_xcr0, uaddr)) > @@ -5664,12 +5652,9 @@ static int kvm_arch_tsc_has_attr(struct kvm_vcpu *vcpu, > static int kvm_arch_tsc_get_attr(struct kvm_vcpu *vcpu, > struct kvm_device_attr *attr) > { > - u64 __user *uaddr = kvm_get_attr_addr(attr); > + u64 __user *uaddr = u64_to_user_ptr(attr->addr); > int r; > > - if (IS_ERR(uaddr)) > - return PTR_ERR(uaddr); > - > switch (attr->attr) { > case KVM_VCPU_TSC_OFFSET: > r = -EFAULT; > @@ -5687,13 +5672,10 @@ static int kvm_arch_tsc_get_attr(struct kvm_vcpu *vcpu, > static int kvm_arch_tsc_set_attr(struct kvm_vcpu *vcpu, > struct kvm_device_attr *attr) > { > - u64 __user *uaddr = kvm_get_attr_addr(attr); > + u64 __user *uaddr = u64_to_user_ptr(attr->addr); > struct kvm *kvm = vcpu->kvm; > int r; > > - if (IS_ERR(uaddr)) > - return PTR_ERR(uaddr); > - > switch (attr->attr) { > case KVM_VCPU_TSC_OFFSET: { > u64 offset, tsc, ns; > -- > 2.39.1 > > >