All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Yuval Shaia <yuval.shaia.ml@gmail.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Subject: Re: [Qemu-devel] [PATCH PULL v2 08/10] hw/rdma: PVRDMA commands and data-path ops
Date: Tue, 20 Jun 2023 13:35:18 +0100	[thread overview]
Message-ID: <CAFEAcA-ghxbM_mjv2UpXVg9uRh30q6Pt+kxK8xw7sy2hAN6G1g@mail.gmail.com> (raw)
In-Reply-To: <20180219114332.70443-9-marcel@redhat.com>

On Mon, 19 Feb 2018 at 11:44, 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; I know this is a 5 year old commit, but Coverity has just
noticed something odd in this code (CID 1507146):

> +static int query_port(PVRDMADev *dev, union pvrdma_cmd_req *req,
> +                      union pvrdma_cmd_resp *rsp)
> +{
> +    struct pvrdma_cmd_query_port *cmd = &req->query_port;
> +    struct pvrdma_cmd_query_port_resp *resp = &rsp->query_port_resp;
> +    struct pvrdma_port_attr attrs = {0};
> +
> +    pr_dbg("port=%d\n", cmd->port_num);
> +
> +    if (rdma_backend_query_port(&dev->backend_dev,
> +                                (struct ibv_port_attr *)&attrs)) {

rdma_backend_query_port() wants a pointer to a struct ibv_port_attr.
But instead of passing it one, we have a local struct
pvrdma_port_attr and then explicitly cast it to the
other type.

Unfortunately, ibv_port_attr is larger than pvrdma_port_attr
(50 bytes vs 48 bytes), so this could overrun the local
variable.

What's going on here, and what should the code be doing instead?

Given that we are just copying fields out of the structure,
and (other than the extra field at the end of ibv_port_attr)
the struct layout is identical, it looks to me that the simple
fix would be to make the local variable have the correct type
'struct ibv_port_attr' and drop the cast.

> +        return -ENOMEM;
> +    }
> +
> +    memset(resp, 0, sizeof(*resp));
> +    resp->hdr.response = cmd->hdr.response;
> +    resp->hdr.ack = PVRDMA_CMD_QUERY_PORT_RESP;
> +    resp->hdr.err = 0;
> +
> +    resp->attrs.state = attrs.state;
> +    resp->attrs.max_mtu = attrs.max_mtu;
> +    resp->attrs.active_mtu = attrs.active_mtu;
> +    resp->attrs.phys_state = attrs.phys_state;
> +    resp->attrs.gid_tbl_len = MIN(MAX_PORT_GIDS, attrs.gid_tbl_len);
> +    resp->attrs.max_msg_sz = 1024;
> +    resp->attrs.pkey_tbl_len = MIN(MAX_PORT_PKEYS, attrs.pkey_tbl_len);
> +    resp->attrs.active_width = 1;
> +    resp->attrs.active_speed = 1;
> +
> +    return 0;
> +}

thanks
-- PMM


  parent reply	other threads:[~2023-06-20 12:35 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
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 [this message]
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=CAFEAcA-ghxbM_mjv2UpXVg9uRh30q6Pt+kxK8xw7sy2hAN6G1g@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yuval.shaia.ml@gmail.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.