Message ID | 20240226190344.787149-3-pbonzini@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2277213dyb; Mon, 26 Feb 2024 11:06:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8jCNREb1up/wNosux+emq/MxjnhwFerkhEJl0BeeD6i3Yb41RSV2cRqLBQz6fngrhXYA4KcTk7LuEkjh8T9hwqvdo0Q== X-Google-Smtp-Source: AGHT+IGS5wtJOee03M1H7mPfzu4zbPaXDBJBtBb5etrAUYSuJVy6TWXidrGlLzQ378iffKKoRaX3 X-Received: by 2002:a05:6a00:4f82:b0:6e5:32e9:9fc6 with SMTP id ld2-20020a056a004f8200b006e532e99fc6mr3361700pfb.34.1708974375368; Mon, 26 Feb 2024 11:06:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708974375; cv=pass; d=google.com; s=arc-20160816; b=VhimJOdgyTqSUWgEUzc6nrJd3GsZZpv9FA9siGOKK8tWlfMUsfkMu39n5utEKg8t9g Lnb7fXuAXqU5qbSsXEIUkiWgKow2LiswAblsIpj+RKfC94KzJiZEU+mMBJJSf20EmulM sp+zaSi89KbozTGjkfJtt8wlpvxd4BAA7I7/jhoQ8T3M7/BTdYmF4P9o8LKj6e8NUMAQ qXZ52NxJONe6mXieVlAaIG5BWLtSQgMVSFkQlETHiaIrrgj950hbYaN/xNN9V7txGtIy uHHfA7Qcqw0TH+v3SSATbCUViCHwTjT4Kk8UvDtULyieaNoCergJCpwQCM+2ilAh+rxW kNZg== 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=SrpFxJCexxYzP/66dv8sDZ2xWIWJ/QIQbY4Xg6TPt7Q=; fh=TLdZJsFzSA0fpm6Q4iUv+uB0sG0oU+h3Bp6HiSGyZm8=; b=iLiN0yEjRKB16M+PocvB5UdrkBJyO8HnnGDzxgDzQ6mAETjWLfWcOd3GPM2tLZ6kxA FV9nGDy0NHuBaUNeEM+YbGjHBRhyo++06kaw8C0GYq2b8IVX64juutDacC6KB8SGMVpW twLpgZwlsK7xJ6+7YMUSdM2duiyWbLCCKxVA9FIhJOBFCaSlRtP3OiBsuBFZiE8MlGOU 5/Ox1XMkJOF2tAQvUljJHaEbrreu4HupjgyidrKeJFmGwYKsMPmjpsVXqccB0Kot2A0+ mkpKJ8QZ6TYI6sKjTP0JFYcAgTtBhPmp+SGnevM53mvOA9NwRnokWILsr/S/gOuYVUNw GG+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R5WMXILR; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h3-20020a056a00230300b006e0f90ac3b8si4207072pfh.141.2024.02.26.11.06.15 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 11:06:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R5WMXILR; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82184-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 81298290A96 for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 19:05:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85BE3131E3E; Mon, 26 Feb 2024 19:03:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R5WMXILR" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A93FE12F39B for <linux-kernel@vger.kernel.org>; Mon, 26 Feb 2024 19:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708974233; cv=none; b=EFNVkHfiJoLFDSCL+MwzvirlI/D5U2+H6kBvJH8yraJlBuHPkhHZ9T5hSBo/pkcc3tDLFln4ZzwTqnsc03JGtuHz5F2ELukc7uTCWSGZpLBId5ghzGvZ0apvIvz+niyAWHpXX2uYtfxUbJ7kl3womp0oE2OGvpdt5UbuQgoBa+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708974233; c=relaxed/simple; bh=365HX1koM5s1rKiT2wfEYWXzusfKgDR6HIIYyfQCgvI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=OzzgD2Ec+E2BUPldzTdcaDEBbv+HcoPXR3hhUfEmeOIuCszIX+g7pEZeoMpDtCWgh5hpXTQ3Uim1uYrnXNMiOlmp0XQwRZQFRbCnqYbdyzlXEjnLmofNHeUXQnYJQFeavwHaIjVEiE8mwLmN9JcAINaqshr6RRENk8ZeeAcxZgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=R5WMXILR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708974229; 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: in-reply-to:in-reply-to:references:references; bh=SrpFxJCexxYzP/66dv8sDZ2xWIWJ/QIQbY4Xg6TPt7Q=; b=R5WMXILRFz0LXmwV/1W1G37zd5Cct7TS8F2KYvaPY+SCcC+QnjvZObEpqdMBY82M6pBAPR YROG6HJDGrjytcZy+ncV8lvZUT2gTKfUphZFxG7WJWg/pjOeY0FSkbbRCOyMC7OrmZfsaj 2StHDnI1K2D61fD5mkwT/4YT+G3J3bY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-38gKcZKRMhiuJsCSNaeXIQ-1; Mon, 26 Feb 2024 14:03:46 -0500 X-MC-Unique: 38gKcZKRMhiuJsCSNaeXIQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 130A388D543; Mon, 26 Feb 2024 19:03:46 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE074492BC6; Mon, 26 Feb 2024 19:03:45 +0000 (UTC) From: Paolo Bonzini <pbonzini@redhat.com> To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, michael.roth@amd.com, aik@amd.com Subject: [PATCH v3 02/15] KVM: x86: use u64_to_user_addr() Date: Mon, 26 Feb 2024 14:03:31 -0500 Message-Id: <20240226190344.787149-3-pbonzini@redhat.com> In-Reply-To: <20240226190344.787149-1-pbonzini@redhat.com> References: <20240226190344.787149-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791989514330053623 X-GMAIL-MSGID: 1791989514330053623 |
Series |
KVM: SEV: allow customizing VMSA features
|
|
Commit Message
Paolo Bonzini
Feb. 26, 2024, 7:03 p.m. UTC
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
address that has something mapped there. KVM uses the checked version
of put_user() in kvm_x86_dev_get_attr().
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/x86.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
Comments
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 <seanjc@google.com> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > 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 > > >
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;