From: liweihang <liweihang@huawei.com>
To: "Saleem, Shiraz" <shiraz.saleem@intel.com>,
"dledford@redhat.com" <dledford@redhat.com>,
"jgg@nvidia.com" <jgg@nvidia.com>
Cc: "leon@kernel.org" <leon@kernel.org>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
Linuxarm <linuxarm@huawei.com>
Subject: Re: [PATCH for-next 1/6] RDMA/core: Use refcount_t instead of atomic_t for reference counting
Date: Tue, 18 May 2021 03:34:29 +0000 [thread overview]
Message-ID: <6328764d6be74e3f804ed13f70cf76df@huawei.com> (raw)
In-Reply-To: c90bd7a612c64f26bc5caa95179e7de7@intel.com
On 2021/5/18 7:03, Saleem, Shiraz wrote:
>> Subject: [PATCH for-next 1/6] RDMA/core: Use refcount_t instead of atomic_t for
>> reference counting
>>
>> The refcount_t API will WARN on underflow and overflow of a reference counter,
>> and avoid use-after-free risks. Increase refcount_t from 0 to 1 is regarded as there
>> is a risk about use-after-free. So it should be set to 1 directly during initialization.
>>
>> Signed-off-by: Weihang Li <liweihang@huawei.com>
>> ---
>> drivers/infiniband/core/iwcm.c | 9 ++++-----
>> drivers/infiniband/core/iwcm.h | 2 +-
>> drivers/infiniband/core/iwpm_util.c | 12 ++++++++----
>> drivers/infiniband/core/iwpm_util.h | 2 +-
>> drivers/infiniband/core/mad_priv.h | 2 +-
>> drivers/infiniband/core/multicast.c | 30 +++++++++++++++---------------
>> drivers/infiniband/core/uverbs.h | 2 +-
>> drivers/infiniband/core/uverbs_main.c | 12 ++++++------
>> 8 files changed, 37 insertions(+), 34 deletions(-)
>>
>
> [...]
>
>> @@ -589,9 +589,9 @@ static struct mcast_group *acquire_group(struct
>> mcast_port *port,
>> kfree(group);
>> group = cur_group;
>> } else
>> - atomic_inc(&port->refcount);
>> + refcount_inc(&port->refcount);
>> found:
>> - atomic_inc(&group->refcount);
>> + refcount_inc(&group->refcount);
>
> Seems like there is refcount_inc with refcount = 0 when the group is first created?
Yes, one of "refcount_inc(&group->refcount)" led to the issue that Leon had
reported. I will fix it, thank you.
Weihang
>
>> spin_unlock_irqrestore(&port->lock, flags);
>> return group;
>> }
>
>
next prev parent reply other threads:[~2021-05-18 3:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 2:11 [PATCH for-next 0/6] RDMA: Use refcount_t for reference counting Weihang Li
2021-05-14 2:11 ` [PATCH for-next 1/6] RDMA/core: Use refcount_t instead of atomic_t " Weihang Li
2021-05-14 12:34 ` Jason Gunthorpe
2021-05-15 3:07 ` liweihang
2021-05-17 16:04 ` Jason Gunthorpe
2021-05-18 3:30 ` liweihang
2021-05-17 23:03 ` Saleem, Shiraz
2021-05-18 3:34 ` liweihang [this message]
2021-05-14 2:11 ` [PATCH for-next 2/6] RDMA/hns: " Weihang Li
2021-05-14 2:11 ` [PATCH for-next 3/6] RDMA/hns: Use refcount_t APIs for HEM Weihang Li
2021-05-14 2:11 ` [PATCH for-next 4/6] RDMA/cxgb4: Use refcount_t instead of atomic_t for reference counting Weihang Li
2021-05-14 2:11 ` [PATCH for-next 5/6] RDMA/i40iw: " Weihang Li
2021-05-14 2:11 ` [PATCH for-next 6/6] RDMA/ipoib: " Weihang Li
2021-05-16 10:18 ` [PATCH for-next 0/6] RDMA: Use refcount_t " Leon Romanovsky
2021-05-17 7:21 ` liweihang
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=6328764d6be74e3f804ed13f70cf76df@huawei.com \
--to=liweihang@huawei.com \
--cc=dledford@redhat.com \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=shiraz.saleem@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox