From: Cheng Xu <chengyou@linux.alibaba.com>
To: Kees Bakker <kees@ijzerbout.nl>,
Boshi Yu <boshiyu@linux.alibaba.com>,
Leon Romanovsky <leon@kernel.org>
Cc: linux-rdma@vger.kernel.org
Subject: Re: Potential use of NULL pointer in erdma/erdma_verbs.c
Date: Fri, 20 Dec 2024 10:06:35 +0800 [thread overview]
Message-ID: <7a262ba9-e4fa-c53d-7616-d217fbfa0f77@linux.alibaba.com> (raw)
In-Reply-To: <6975f57c-8053-4ff1-b1ac-cd985e254ecb@ijzerbout.nl>
On 12/20/24 3:02 AM, Kees Bakker wrote:
> Hi,
>
> As identified by Coverity Scan (CID 1602609) there is a potential
> use of a NULL pointer.
>
> It was introduced in commit 6534de1fe385
> Author: Cheng Xu <chengyou@linux.alibaba.com>
> Date: Tue Jun 6 13:50:04 2023 +0800
>
> RDMA/erdma: Associate QPs/CQs with doorbells for authorization
>
> For the isolation requirement, each QP/CQ can only issue doorbells from the
> allocated mmio space. Configure the relationship between QPs/CQs and
> mmio doorbell spaces to hardware in create_qp/create_cq interfaces.
>
> Signed-off-by: Cheng Xu <chengyou@linux.alibaba.com>
> Link: https://lore.kernel.org/r/20230606055005.80729-4-chengyou@linux.alibaba.com
> Signed-off-by: Leon Romanovsky <leon@kernel.org>
>
> int erdma_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs,
> struct ib_udata *udata)
> {
> struct erdma_qp *qp = to_eqp(ibqp);
> struct erdma_dev *dev = to_edev(ibqp->device);
> struct erdma_ucontext *uctx = rdma_udata_to_drv_context(
> udata, struct erdma_ucontext, ibucontext);
> [...]
> if (uctx) {
> ret = ib_copy_from_udata(&ureq, udata,
> min(sizeof(ureq), udata->inlen));
> [...]
> } else {
> init_kernel_qp(dev, qp, attrs);
> }
>
> qp->attrs.max_send_sge = attrs->cap.max_send_sge;
> qp->attrs.max_recv_sge = attrs->cap.max_recv_sge;
>
> if (erdma_device_iwarp(qp->dev))
> qp->attrs.iwarp.state = ERDMA_QPS_IWARP_IDLE;
> else
> qp->attrs.rocev2.state = ERDMA_QPS_ROCEV2_RESET;
>
> INIT_DELAYED_WORK(&qp->reflush_dwork, erdma_flush_worker);
>
> ret = create_qp_cmd(uctx, qp);
> [...]
> This shows that `uctx` can be NULL. The problem is that `uctx` can be
> dereferenced in create_qp_cmd(). There is no guard against NULL.
>
> Can one of you have a look and say that it OK to potential pass a
> NULL pointer in `uctx`?
>
static int create_qp_cmd(struct erdma_ucontext *uctx, struct erdma_qp *qp)
{
[...]
if (rdma_is_kernel_res(&qp->ibqp.res)) {
[...]
} else {
// uctx used here...
}
[...]
}
When uctx == NULL, rdma_is_kernel_res() will always return false and uctx will not be
dereferenced. So the current implementation is OK.
Thanks,
Cheng Xu
> Kind regards,
> Kees Bakker
next prev parent reply other threads:[~2024-12-20 2:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 19:02 Potential use of NULL pointer in erdma/erdma_verbs.c Kees Bakker
2024-12-20 2:06 ` Cheng Xu [this message]
2024-12-20 2:25 ` Cheng Xu
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=7a262ba9-e4fa-c53d-7616-d217fbfa0f77@linux.alibaba.com \
--to=chengyou@linux.alibaba.com \
--cc=boshiyu@linux.alibaba.com \
--cc=kees@ijzerbout.nl \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox