All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuval Shaia <yuval.shaia@oracle.com>
To: Marcel Apfelbaum <marcel@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	yuval.shaia@oracle.com
Subject: Re: [Qemu-devel] [PATCH PULL v2 08/10] hw/rdma: PVRDMA commands and data-path ops
Date: Sun, 29 Apr 2018 10:42:49 +0300	[thread overview]
Message-ID: <20180429074249.GC2597@yuvallap> (raw)
In-Reply-To: <cb93c688-55f4-3e0c-b9ff-f30f19c6b452@redhat.com>

On Fri, Apr 27, 2018 at 09:20:44PM +0300, Marcel Apfelbaum wrote:
> Hi Peter,
> 
> On 27/04/2018 17:31, Peter Maydell wrote:
> > On 19 February 2018 at 11:43, Marcel Apfelbaum <marcel@redhat.com> wrote:
> >> From: Yuval Shaia <yuval.shaia@oracle.com>
> >>
> >> First PVRDMA sub-module - implementation of the PVRDMA device.
> >> - PVRDMA commands such as create CQ and create MR.
> >> - Data path QP operations - post_send and post_recv.
> >> - Completion handler.
> >>
> >> Reviewed-by: Dotan Barak <dotanb@mellanox.com>
> >> Reviewed-by: Zhu Yanjun <yanjun.zhu@oracle.com>
> >> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> >> Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
> > 
> > Hi; Coverity points out an array bounds overrun in this code:
> > 
> > 
> >> +static int create_bind(PVRDMADev *dev, union pvrdma_cmd_req *req,
> >> +                       union pvrdma_cmd_resp *rsp)
> >> +{
> >> +    struct pvrdma_cmd_create_bind *cmd = &req->create_bind;
> >> +#ifdef PVRDMA_DEBUG
> >> +    __be64 *subnet = (__be64 *)&cmd->new_gid[0];
> >> +    __be64 *if_id = (__be64 *)&cmd->new_gid[8];
> >> +#endif
> >> +
> >> +    pr_dbg("index=%d\n", cmd->index);
> >> +
> >> +    if (cmd->index > MAX_PORT_GIDS) {
> >> +        return -EINVAL;
> >> +    }
> > 
> > This bounds check allows cmd->index == MAX_PORT_GIDS...
> > 
> >> +
> >> +    pr_dbg("gid[%d]=0x%llx,0x%llx\n", cmd->index,
> >> +           (long long unsigned int)be64_to_cpu(*subnet),
> >> +           (long long unsigned int)be64_to_cpu(*if_id));
> >> +
> >> +    /* Driver forces to one port only */
> >> +    memcpy(dev->rdma_dev_res.ports[0].gid_tbl[cmd->index].raw, &cmd->new_gid,
> >> +           sizeof(cmd->new_gid));
> > 
> > ...but the gid_tbl[] array we index into is declared with
> > 
> >     union ibv_gid gid_tbl[MAX_PORT_GIDS];
> > 
> > so using MAX_PORT_GIDS as an index is off the end of it.
> > 
> > Presumably the check should be ">=".
> > 
> 
> Right, thanks for finding it!
> 
> >> +static int destroy_bind(PVRDMADev *dev, union pvrdma_cmd_req *req,
> >> +                        union pvrdma_cmd_resp *rsp)
> >> +{
> >> +    struct pvrdma_cmd_destroy_bind *cmd = &req->destroy_bind;
> >> +
> >> +    pr_dbg("clear index %d\n", cmd->index);
> >> +
> >> +    memset(dev->rdma_dev_res.ports[0].gid_tbl[cmd->index].raw, 0,
> >> +           sizeof(dev->rdma_dev_res.ports[0].gid_tbl[cmd->index].raw));
> > 
> > I'm assuming this function can't be called unless create_bind()
> > has previously succeeded and so it doesn't need its own
> > bounds check.
> > 
> 
> The index is provided by the guest, so we should check it,
> right Yuval?

Right,
Guest driver is considered trusted but we don't want a faulty driver to
crash the entire VM.

> 
> I'll take care of it.
> Thanks,
> Marcel
> 
> >> +
> >> +    return 0;
> >> +}
> > 
> > thanks
> > -- PMM
> > 
> 

  reply	other threads:[~2018-04-29  7:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19 11:43 [Qemu-devel] [PATCH PULL v2 00/10] RDMA patches Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 01/10] mem: add share parameter to memory-backend-ram Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 02/10] docs: add pvrdma device documentation Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 03/10] scripts/update-linux-headers: import pvrdma headers Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 04/10] include/standard-headers: add pvrdma related headers Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 05/10] hw/rdma: Add wrappers and macros Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 06/10] hw/rdma: Definitions for rdma device and rdma resource manager Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 07/10] hw/rdma: Implementation of generic rdma device layers Marcel Apfelbaum
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 08/10] hw/rdma: PVRDMA commands and data-path ops Marcel Apfelbaum
2018-04-27 14:31   ` Peter Maydell
2018-04-27 18:20     ` Marcel Apfelbaum
2018-04-29  7:42       ` Yuval Shaia [this message]
2018-04-27 14:43   ` Peter Maydell
2018-04-27 18:22     ` Marcel Apfelbaum
2018-04-27 14:58   ` Peter Maydell
2018-04-27 18:28     ` Marcel Apfelbaum
2018-04-27 15:01   ` Peter Maydell
2018-04-27 18:31     ` Marcel Apfelbaum
2023-06-20 12:35   ` Peter Maydell
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 09/10] hw/rdma: Implementation of PVRDMA device Marcel Apfelbaum
2018-04-27 14:49   ` Peter Maydell
2018-04-27 19:36     ` Marcel Apfelbaum
2018-04-29  9:38       ` Yuval Shaia
2018-04-27 14:55   ` Peter Maydell
2018-04-27 19:46     ` Marcel Apfelbaum
2018-04-29  7:18     ` Yuval Shaia
2018-02-19 11:43 ` [Qemu-devel] [PATCH PULL v2 10/10] MAINTAINERS: add entry for hw/rdma Marcel Apfelbaum
2018-02-19 16:43 ` [Qemu-devel] [PATCH PULL v2 00/10] RDMA patches Peter Maydell

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=20180429074249.GC2597@yuvallap \
    --to=yuval.shaia@oracle.com \
    --cc=marcel@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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.