From: Leon Romanovsky <leon@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Chiara Meiohas <cmeiohas@nvidia.com>, linux-rdma@vger.kernel.org
Subject: Re: [bug report] RDMA/uverbs: Introduce UCAP (User CAPabilities) API
Date: Wed, 12 Mar 2025 10:07:17 +0200 [thread overview]
Message-ID: <20250312080717.GH7027@unreal> (raw)
In-Reply-To: <9f676f55-f5d7-4be5-88a5-4f1f5c5c997a@stanley.mountain>
On Wed, Mar 12, 2025 at 09:53:17AM +0300, Dan Carpenter wrote:
> Hello Chiara Meiohas,
>
> Commit 61e51682816d ("RDMA/uverbs: Introduce UCAP (User CAPabilities)
> API") from Mar 6, 2025 (linux-next), leads to the following Smatch
> static checker warning:
>
> drivers/infiniband/core/ucaps.c:209 ib_release_ucap()
> error: buffer overflow 'ucaps_list' 2 <= 2 (assuming for loop doesn't break)
The thing is that we must have "break", so writing if(WARN_ON(type ==
"RDMA_UCAP_MAX)) return;" instead of existing WARN_ON is very
misleading.
Thanks
>
> drivers/infiniband/core/ucaps.c
> 198 static void ib_release_ucap(struct kref *ref)
> 199 {
> 200 struct ib_ucap *ucap = container_of(ref, struct ib_ucap, ref);
> 201 enum rdma_user_cap type;
> 202
> 203 for (type = RDMA_UCAP_FIRST; type < RDMA_UCAP_MAX; type++) {
> 204 if (ucaps_list[type] == ucap)
> 205 break;
> 206 }
> 207 WARN_ON(type == RDMA_UCAP_MAX);
>
> This prints a warning if we're out of bounds, but it doesn't handle the
> error. This is called from kref_put() and with kref_put() this could
> actually be done in a different thread with a delay from when
> ib_remove_ucap() is called. I wouldn't advise that for production systems
> but it's supposed to work.
>
> So this code makes me quite nervous.
>
> 208
> --> 209 ucaps_list[type] = NULL;
> 210 cdev_device_del(&ucap->cdev, &ucap->dev);
> 211 put_device(&ucap->dev);
> 212 }
>
> regards,
> dan carpenter
>
next prev parent reply other threads:[~2025-03-12 8:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-12 6:53 [bug report] RDMA/uverbs: Introduce UCAP (User CAPabilities) API Dan Carpenter
2025-03-12 8:07 ` Leon Romanovsky [this message]
2025-03-12 9:16 ` Dan Carpenter
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=20250312080717.GH7027@unreal \
--to=leon@kernel.org \
--cc=cmeiohas@nvidia.com \
--cc=dan.carpenter@linaro.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