All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: David Laight <David.Laight@aculab.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Juergen Gross <jgross@suse.com>, Nicolas Pitre <nico@linaro.org>,
	Andi Kleen <ak@linux.intel.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Jan Beulich <jbeulich@suse.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xen: hypercall: fix out-of-bounds memcpy
Date: Mon, 5 Feb 2018 13:37:25 +0100	[thread overview]
Message-ID: <CAK8P3a0z72S6mY7Q7RBJ_EMCbF9DOi+RdVaUEsB_qo+rGurQ1g@mail.gmail.com> (raw)
In-Reply-To: <1eddce614f604c518b9bf238a2f92e4b@AcuMS.aculab.com>

On Mon, Feb 5, 2018 at 1:11 PM, David Laight <David.Laight@aculab.com> wrote:
> From: Boris Ostrovsky
>> Sent: 02 February 2018 23:34
> ...
>> >     switch (cmd) {
>> > +   case EVTCHNOP_bind_interdomain:
>> > +           len = sizeof(struct evtchn_bind_interdomain);
>> > +           break;
>> > +   case EVTCHNOP_bind_virq:
>> > +           len = sizeof(struct evtchn_bind_virq);
>> > +           break;
>> > +   case EVTCHNOP_bind_pirq:
>> > +           len = sizeof(struct evtchn_bind_pirq);
>> > +           break;
>> >     case EVTCHNOP_close:
>> > +           len = sizeof(struct evtchn_close);
>> > +           break;
>> >     case EVTCHNOP_send:
>> > +           len = sizeof(struct evtchn_send);
>> > +           break;
>> > +   case EVTCHNOP_alloc_unbound:
>> > +           len = sizeof(struct evtchn_alloc_unbound);
>> > +           break;
>> > +   case EVTCHNOP_bind_ipi:
>> > +           len = sizeof(struct evtchn_bind_ipi);
>> > +           break;
>> > +   case EVTCHNOP_status:
>> > +           len = sizeof(struct evtchn_status);
>> > +           break;
>> >     case EVTCHNOP_bind_vcpu:
>> > +           len = sizeof(struct evtchn_bind_vcpu);
>> > +           break;
>> >     case EVTCHNOP_unmask:
>> > -           /* no output */
>> > +           len = sizeof(struct evtchn_unmask);
>> >             break;
>
> Are the EVTCHNOP_xxx values dense?
> In which case an array is almost certainly better than the switch statement.

They are, yes. PHYSDEVOP_xxx are also consecutive by start at '4'.
Dan made the same comment earlier, and I replied that my I had
considered it but went for the more failsafe route. I also verified my
assumption now that gcc in fact is smart enough to turn this
into a table by itself:

xen_physdev_op_compat:
        pushq   %r13    #
        leal    -4(%rdi), %eax  #, _2
        pushq   %r12    #
        pushq   %rbp    #
        pushq   %rbx    #
        subq    $24, %rsp       #,
# /git/arm-soc/drivers/xen/fallback.c:59:       struct physdev_op op =
{ .cmd = cmd, };
        movq    $0, 4(%rsp)     #, MEM[(struct physdev_op *)&op + 4B]
        movq    $0, 12(%rsp)    #, MEM[(struct physdev_op *)&op + 4B]
        movl    $0, 20(%rsp)    #, MEM[(struct physdev_op *)&op + 4B]
        movl    %edi, (%rsp)    # cmd, op.cmd
        cmpl    $6, %eax        #, _2
        ja      .L8     #,
        movl    %eax, %edi      # _2, _2
# /git/arm-soc/drivers/xen/fallback.c:87:       memcpy(&op.u, arg, len);
        leaq    8(%rsp), %r12   #, tmp98
        movq    %rsi, %rbx      # arg, arg
        movq    CSWTCH.17(,%rdi,8), %r13        # CSWTCH.17, _5
        movq    %r12, %rdi      # tmp98,
        movq    %r13, %rdx      # _5,
        call    __memcpy        #
# /git/arm-soc/drivers/xen/fallback.c:88:       rc = _hypercall1(int,
physdev_op_compat, &op);
        movq    %rsp, %rdi      #, __arg1
#APP
# 88 "/git/arm-soc/drivers/xen/fallback.c" 1
        call hypercall_page+608 #


     Arnd

  parent reply	other threads:[~2018-02-05 12:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 15:32 [PATCH] xen: hypercall: fix out-of-bounds memcpy Arnd Bergmann
2018-02-02 15:53 ` Dan Carpenter
2018-02-02 15:53 ` Dan Carpenter
2018-02-02 16:11   ` Arnd Bergmann
2018-02-02 16:34     ` Dan Carpenter
2018-02-02 16:34     ` Dan Carpenter
2018-02-02 16:11   ` Arnd Bergmann
2018-02-02 23:33 ` Boris Ostrovsky
2018-02-03 15:12   ` Arnd Bergmann
2018-02-03 15:12   ` Arnd Bergmann
2018-02-03 17:08     ` Boris Ostrovsky
2018-02-04 15:35       ` Arnd Bergmann
2018-02-04 18:55         ` Boris Ostrovsky
2018-02-04 18:55         ` Boris Ostrovsky
2018-02-04 15:35       ` Arnd Bergmann
2018-02-03 17:08     ` Boris Ostrovsky
2018-02-05 12:11   ` David Laight
2018-02-05 12:11   ` David Laight
2018-02-05 12:37     ` Arnd Bergmann
2018-02-05 12:37     ` Arnd Bergmann [this message]
2018-02-05 13:58       ` David Laight
2018-02-05 14:18         ` Arnd Bergmann
2018-02-05 14:18         ` Arnd Bergmann
2018-02-05 13:58       ` David Laight
2018-02-02 23:33 ` Boris Ostrovsky
2018-02-02 15:32 Arnd Bergmann

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=CAK8P3a0z72S6mY7Q7RBJ_EMCbF9DOi+RdVaUEsB_qo+rGurQ1g@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=David.Laight@aculab.com \
    --cc=ak@linux.intel.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=dan.carpenter@oracle.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico@linaro.org \
    --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.