public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: mtosatti@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH 5/8] KVM: Check IOPL level during io instruction emulation.
Date: Tue, 09 Feb 2010 16:51:12 +0200	[thread overview]
Message-ID: <4B717660.60506@redhat.com> (raw)
In-Reply-To: <1265724844-11112-6-git-send-email-gleb@redhat.com>

On 02/09/2010 04:14 PM, Gleb Natapov wrote:
> Make emulator check that vcpu is allowed to execute IN, INS, OUT,
> OUTS, CLI, STI.
>
>
>
> +bool kvm_check_iopl(struct kvm_vcpu *vcpu)
> +{
> +	int iopl;
> +	if (!is_protmode(vcpu))
> +		return false;
> +	if (kvm_get_rflags(vcpu)&  X86_EFLAGS_VM)
> +		return true;
> +	iopl = (kvm_get_rflags(vcpu)&  X86_EFLAGS_IOPL)>>  IOPL_SHIFT;
> +	return kvm_x86_ops->get_cpl(vcpu)>  iopl;
> +}
>    

Confusingly named -  check doesn't imply what the return value means 
(and 'true' is surprising for a failure).  Suggest kvm_bad_iopl() or 
similar.

> +
> +bool kvm_check_io_port_access_allowed(struct kvm_vcpu *vcpu, u16 port, u16 len)
> +{
>    

Similarly, can drop check_ from the name.

> +	struct kvm_segment tr_seg;
> +	int r;
> +	u16 io_bitmap_ptr;
> +	u8 perm, bit_idx = port&  0x7;
> +	unsigned mask = (1<<  len) - 1;
> +
> +	kvm_get_segment(vcpu,&tr_seg, VCPU_SREG_TR);
> +	if (tr_seg.unusable)
> +		return false;
> +	if (tr_seg.limit<  103)
> +		return false;
> +	r = kvm_read_guest_virt_system(tr_seg.base + 102,&io_bitmap_ptr, 2,
> +				       vcpu, NULL);
> +	if (r != X86EMUL_CONTINUE)
> +		return false;
> +	if (io_bitmap_ptr + port/8>= tr_seg.limit)
> +		return false;
>    

Should this be '>'?  limits are generally inclusive of the byte read 
(i.e. they aren't the size of the segment, but the offset of the last byte).

> +	r = kvm_read_guest_virt_system(tr_seg.base + io_bitmap_ptr + port/8,
> +				&perm, 1, vcpu, NULL);
> +	if (r != X86EMUL_CONTINUE)
> +		return false;
> +	if ((perm>>  bit_idx)&  mask)
> +		return false;
> +	return true;
> +}
> +
>    

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2010-02-09 14:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-09 14:13 [PATCH 0/8] Miscellaneous x86 emulator fixes Gleb Natapov
2010-02-09 14:13 ` [PATCH 1/8] KVM: Add group8 instruction decoding Gleb Natapov
2010-02-09 14:13 ` [PATCH 2/8] KVM: Add group9 " Gleb Natapov
2010-02-09 14:13 ` [PATCH 3/8] KVM: Add Virtual-8086 mode of emulation Gleb Natapov
2010-02-09 14:14 ` [PATCH 4/8] KVM: fix memory access during x86 emulation Gleb Natapov
2010-02-09 14:14 ` [PATCH 5/8] KVM: Check IOPL level during io instruction emulation Gleb Natapov
2010-02-09 14:51   ` Avi Kivity [this message]
2010-02-09 14:14 ` [PATCH 6/8] KVM: Fix popf emulation Gleb Natapov
2010-02-09 14:14 ` [PATCH 7/8] KVM: Check CPL level during privilege instruction emulation Gleb Natapov
2010-02-09 14:14 ` [PATCH 8/8] KVM: Add LOCK prefix validity checking Gleb Natapov

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=4B717660.60506@redhat.com \
    --to=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox