From: "Jan Beulich" <JBeulich@suse.com>
To: Paul Durrant <paul.durrant@citrix.com>
Cc: Ian Jackson <ian.jackson@citrix.com>,
Jennifer Herbert <jennifer.herbert@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v7 1/8] public / x86: Introduce __HYPERCALL_dm_op...
Date: Tue, 24 Jan 2017 02:59:41 -0700 [thread overview]
Message-ID: <5887339D020000780013334E@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1485179989-1763-2-git-send-email-paul.durrant@citrix.com>
>>> On 23.01.17 at 14:59, <paul.durrant@citrix.com> wrote:
> +static bool copy_buf_from_guest(xen_dm_op_buf_t bufs[],
> + unsigned int nr_bufs, void *dst,
> + unsigned int idx, size_t dst_size)
> +{
> + if ( dst_size != bufs[idx].size )
> + return false;
> +
> + return !copy_from_guest(dst, bufs[idx].h, dst_size);
> +}
> +
> +static bool copy_buf_to_guest(xen_dm_op_buf_t bufs[],
> + unsigned int nr_bufs, unsigned int idx,
> + void *src, size_t src_size)
> +{
> + if ( bufs[idx].size != src_size )
> + return false;
> +
> + return !copy_to_guest(bufs[idx].h, src, bufs[idx].size);
> +}
What are the "nr_bufs" parameters good for in both of these?
> +static int dm_op(domid_t domid,
> + unsigned int nr_bufs,
> + xen_dm_op_buf_t bufs[])
> +{
> + struct domain *d;
> + struct xen_dm_op op;
> + bool const_op = true;
> + long rc;
> +
> + rc = rcu_lock_remote_domain_by_id(domid, &d);
> + if ( rc )
> + return rc;
> +
> + if ( !has_hvm_container_domain(d) )
> + goto out;
> +
> + rc = xsm_dm_op(XSM_DM_PRIV, d);
> + if ( rc )
> + goto out;
> +
> + if ( !copy_buf_from_guest(bufs, nr_bufs, &op, 0, sizeof(op)) )
I'm afraid my request to have an exact size check in the copy
functions was going a little too far for this particular instance: Just
consider what would happen for a tool stack built with just this one
patch in place, but run against a hypervisor with at least one more
applied. We can of course keep things the way they are here, but
then we'll need a placeholder added to the structure right away
(like is e.g. the case for domctl/sysctl). Every sub-structure should
then be checked to not violate that constraint by a BUILD_BUG_ON()
in its respective function (I'd prefer that over a single verification
of the entire structure/union, as that would more clearly pinpoint
a possible offender).
> + {
> + rc = -EFAULT;
> + goto out;
> + }
> +
> + switch ( op.op )
> + {
> + default:
> + rc = -EOPNOTSUPP;
> + break;
> + }
> +
> + if ( !rc &&
> + !const_op &&
> + !copy_buf_to_guest(bufs, nr_bufs, 0, &op, sizeof(op)) )
> + rc = -EFAULT;
> +
> + out:
> + rcu_unlock_domain(d);
> +
> + return rc;
> +}
> +
> +#define MAX_NR_BUFS 1
> +
> +int compat_dm_op(domid_t domid,
> + unsigned int nr_bufs,
> + COMPAT_HANDLE_PARAM(compat_dm_op_buf_t) bufs)
> +{
> + struct xen_dm_op_buf nat[MAX_NR_BUFS];
> + unsigned int i;
> +
> + if ( nr_bufs > MAX_NR_BUFS )
> + return -EINVAL;
E2BIG (to make it distinguishable)?
> +long do_dm_op(domid_t domid,
> + unsigned int nr_bufs,
> + XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
> +{
> + struct xen_dm_op_buf nat[MAX_NR_BUFS];
> +
> + if ( nr_bufs > MAX_NR_BUFS )
> + return -EINVAL;
Same here then.
> --- a/xen/include/xlat.lst
> +++ b/xen/include/xlat.lst
> @@ -56,6 +56,7 @@
> ? grant_entry_header grant_table.h
> ? grant_entry_v2 grant_table.h
> ? gnttab_swap_grant_ref grant_table.h
> +! dm_op_buf hvm/dm_op.h
> ? vcpu_hvm_context hvm/hvm_vcpu.h
> ? vcpu_hvm_x86_32 hvm/hvm_vcpu.h
> ? vcpu_hvm_x86_64 hvm/hvm_vcpu.h
While for this patch the addition here is sufficient, subsequent
patches should add their sub-structures here with a leading ?,
and you'd then need to invoke the resulting CHECK_* macros
somewhere. I don't think we should leave those structures
unchecked.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-24 9:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-23 13:59 [PATCH v7 0/8] New hypercall for device models Paul Durrant
2017-01-23 13:59 ` [PATCH v7 1/8] public / x86: Introduce __HYPERCALL_dm_op Paul Durrant
2017-01-24 9:59 ` Jan Beulich [this message]
2017-01-24 10:19 ` Paul Durrant
2017-01-24 10:55 ` Jan Beulich
2017-01-24 11:02 ` Paul Durrant
2017-01-23 13:59 ` [PATCH v7 2/8] dm_op: convert HVMOP_*ioreq_server* Paul Durrant
2017-01-23 13:59 ` [PATCH v7 3/8] dm_op: convert HVMOP_track_dirty_vram Paul Durrant
2017-01-23 13:59 ` [PATCH v7 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and Paul Durrant
2017-01-23 13:59 ` [PATCH v7 5/8] dm_op: convert HVMOP_modified_memory Paul Durrant
2017-01-23 13:59 ` [PATCH v7 6/8] dm_op: convert HVMOP_set_mem_type Paul Durrant
2017-01-23 13:59 ` [PATCH v7 7/8] dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi Paul Durrant
2017-01-23 13:59 ` [PATCH v7 8/8] x86/hvm: serialize trap injecting producer and consumer Paul Durrant
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=5887339D020000780013334E@prv-mh.provo.novell.com \
--to=jbeulich@suse.com \
--cc=ian.jackson@citrix.com \
--cc=jennifer.herbert@citrix.com \
--cc=paul.durrant@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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.