From: Avi Kivity <avi@qumranet.com>
To: Andrew Morton <akpm@osdl.org>
Cc: kvm-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
uril@qumranet.com
Subject: Re: [PATCH 3/3] KVM: Expose MSRs to userspace
Date: Fri, 17 Nov 2006 09:20:49 +0200 [thread overview]
Message-ID: <455D62D1.6040203@qumranet.com> (raw)
In-Reply-To: <20061116170214.b7785bd0.akpm@osdl.org>
Andrew Morton wrote:
> On Thu, 16 Nov 2006 18:04:22 -0000
> Avi Kivity <avi@qumranet.com> wrote:
>
>
>> +static int kvm_dev_ioctl_set_msrs(struct kvm *kvm, struct kvm_msrs *msrs)
>> +{
>> + struct kvm_vcpu *vcpu;
>> + struct kvm_msr_entry *entry, *entries;
>> + int rc;
>> + u32 size, num_entries, i;
>> +
>> + if (msrs->vcpu < 0 || msrs->vcpu >= KVM_MAX_VCPUS)
>> + return -EINVAL;
>> +
>> + num_entries = ARRAY_SIZE(msrs_to_save);
>> + if (msrs->nmsrs < num_entries) {
>> + msrs->nmsrs = num_entries; /* inform actual size */
>> + return -EINVAL;
>> + }
>> +
>> + vcpu = vcpu_load(kvm, msrs->vcpu);
>> + if (!vcpu)
>> + return -ENOENT;
>> +
>> + size = msrs->nmsrs * sizeof(struct kvm_msr_entry);
>> + rc = -E2BIG;
>> + if (size > 4096)
>> + goto out_vcpu;
>>
>
> Classic mutiplicative overflow bug.
Right, will fix. The 4096 limit is arbitrary anyway, and can be
replaced by an arbitrary limit on nmsrs.
> Only msrs->nmsrs doesn't get used
> again, so there is no bug here. Yet.
>
>
But why isn't it used again? Looks like the kernel is forcing the user
to send at least num_entries for no good reason, and ignoring any
entries beyond num_entries.
>> + rc = -ENOMEM;
>> + entries = vmalloc(size);
>> + if (entries == NULL)
>> + goto out_vcpu;
>> +
>> + rc = -EFAULT;
>> + if (copy_from_user(entries, msrs->entries, size))
>> + goto out_free;
>> +
>> + rc = -EINVAL;
>> + for (i=0; i<num_entries; i++) {
>> + entry = &entries[i];
>> + if (set_msr(vcpu, entry->index, entry->data))
>> + goto out_free;
>> + }
>> +
>> + rc = 0;
>> +out_free:
>> + vfree(entries);
>> +
>> +out_vcpu:
>> + vcpu_put(vcpu);
>> +
>> + return rc;
>> +}
>>
>
> This function returns no indication of how many msrs it actually did set.
> Should it?
>
It can't hurt. Is returning the number of msrs set in the return code
(ala short write) acceptable, or do I need to make this a read/write ioctl?
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
WARNING: multiple messages have this Message-ID (diff)
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Andrew Morton <akpm-3NddpPZAyC0@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
uril-atKUWr5tajBWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH 3/3] KVM: Expose MSRs to userspace
Date: Fri, 17 Nov 2006 09:20:49 +0200 [thread overview]
Message-ID: <455D62D1.6040203@qumranet.com> (raw)
In-Reply-To: <20061116170214.b7785bd0.akpm-3NddpPZAyC0@public.gmane.org>
Andrew Morton wrote:
> On Thu, 16 Nov 2006 18:04:22 -0000
> Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
>
>
>> +static int kvm_dev_ioctl_set_msrs(struct kvm *kvm, struct kvm_msrs *msrs)
>> +{
>> + struct kvm_vcpu *vcpu;
>> + struct kvm_msr_entry *entry, *entries;
>> + int rc;
>> + u32 size, num_entries, i;
>> +
>> + if (msrs->vcpu < 0 || msrs->vcpu >= KVM_MAX_VCPUS)
>> + return -EINVAL;
>> +
>> + num_entries = ARRAY_SIZE(msrs_to_save);
>> + if (msrs->nmsrs < num_entries) {
>> + msrs->nmsrs = num_entries; /* inform actual size */
>> + return -EINVAL;
>> + }
>> +
>> + vcpu = vcpu_load(kvm, msrs->vcpu);
>> + if (!vcpu)
>> + return -ENOENT;
>> +
>> + size = msrs->nmsrs * sizeof(struct kvm_msr_entry);
>> + rc = -E2BIG;
>> + if (size > 4096)
>> + goto out_vcpu;
>>
>
> Classic mutiplicative overflow bug.
Right, will fix. The 4096 limit is arbitrary anyway, and can be
replaced by an arbitrary limit on nmsrs.
> Only msrs->nmsrs doesn't get used
> again, so there is no bug here. Yet.
>
>
But why isn't it used again? Looks like the kernel is forcing the user
to send at least num_entries for no good reason, and ignoring any
entries beyond num_entries.
>> + rc = -ENOMEM;
>> + entries = vmalloc(size);
>> + if (entries == NULL)
>> + goto out_vcpu;
>> +
>> + rc = -EFAULT;
>> + if (copy_from_user(entries, msrs->entries, size))
>> + goto out_free;
>> +
>> + rc = -EINVAL;
>> + for (i=0; i<num_entries; i++) {
>> + entry = &entries[i];
>> + if (set_msr(vcpu, entry->index, entry->data))
>> + goto out_free;
>> + }
>> +
>> + rc = 0;
>> +out_free:
>> + vfree(entries);
>> +
>> +out_vcpu:
>> + vcpu_put(vcpu);
>> +
>> + return rc;
>> +}
>>
>
> This function returns no indication of how many msrs it actually did set.
> Should it?
>
It can't hurt. Is returning the number of msrs set in the return code
(ala short write) acceptable, or do I need to make this a read/write ioctl?
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
next prev parent reply other threads:[~2006-11-17 7:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-16 17:59 [PATCH 0/3] KVM: Save/resume support Avi Kivity
2006-11-16 17:59 ` Avi Kivity
2006-11-16 18:02 ` [PATCH 1/3] KVM: Expose interrupt bitmap Avi Kivity
2006-11-16 18:02 ` Avi Kivity
2006-11-16 18:03 ` [PATCH 2/3] KVM: Add time stamp counter msr and accessors Avi Kivity
2006-11-16 18:03 ` Avi Kivity
2006-11-16 18:04 ` [PATCH 3/3] KVM: Expose MSRs to userspace Avi Kivity
2006-11-16 18:04 ` Avi Kivity
2006-11-16 19:08 ` [kvm-devel] " Arnd Bergmann
2006-11-16 19:08 ` Arnd Bergmann
2006-11-16 19:17 ` [kvm-devel] " Avi Kivity
2006-11-17 8:06 ` Christoph Hellwig
2006-11-17 8:06 ` Christoph Hellwig
2006-11-17 1:02 ` Andrew Morton
2006-11-17 7:20 ` Avi Kivity [this message]
2006-11-17 7:20 ` Avi Kivity
2006-11-17 8:15 ` Andrew Morton
2006-11-17 8:15 ` Andrew Morton
2006-11-17 8:17 ` Avi Kivity
2006-11-17 8:17 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=455D62D1.6040203@qumranet.com \
--to=avi@qumranet.com \
--cc=akpm@osdl.org \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=uril@qumranet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.