From: liweihang <liweihang@huawei.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "dledford@redhat.com" <dledford@redhat.com>,
"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:30:00 +0000 [thread overview]
Message-ID: <74a596dd3d204674a89818f4537d78db@huawei.com> (raw)
In-Reply-To: 20210517160420.GQ1096940@ziepe.ca
On 2021/5/18 0:56, Jason Gunthorpe wrote:
> On Sat, May 15, 2021 at 03:07:58AM +0000, liweihang wrote:
>> On 2021/5/14 20:34, Jason Gunthorpe wrote:
>>> On Fri, May 14, 2021 at 10:11:34AM +0800, Weihang Li wrote:
>>>> 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.
>>>
>>> What does this comment about 0 to 1 mean?
>>>
>>
>> Hi Jason,
>>
>> I first thought refcount_inc() and atomic_inc() are exactly the same, but I got
>> a warning about refcount_t on iwpm_init() after the replacement:
>>
>> [ 16.882939] refcount_t: addition on 0; use-after-free.
>> [ 16.888065] WARNING: CPU: 2 PID: 1 at lib/refcount.c:25
>> refcount_warn_saturate+0xa0/0x144
>> ...
>> [ 17.014698] Call trace:
>> [ 17.017135] refcount_warn_saturate+0xa0/0x144
>> [ 17.021559] iwpm_init+0x104/0x12c
>> [ 17.024948] iw_cm_init+0x24/0xd0
>> [ 17.028248] do_one_initcall+0x54/0x2d0
>> [ 17.032068] kernel_init_freeable+0x224/0x294
>> [ 17.036407] kernel_init+0x20/0x12c
>> [ 17.039880] ret_from_fork+0x10/0x18
>>
>> Then I noticed that the comment of refcount_inc() says:
>>
>> * Will WARN if the refcount is 0, as this represents a possible use-after-free
>> * condition.
>>
>> so I made changes:
>>
>> @@ -77,8 +77,12 @@ int iwpm_init(u8 nl_client)
>> ret = -ENOMEM;
>> goto init_exit;
>> }
>> +
>> + refcount_set(&iwpm_admin.refcount, 1);
>> + } else {
>> + refcount_inc(&iwpm_admin.refcount);
>> }
>> - refcount_inc(&iwpm_admin.refcount);
>> +
>>
>> I wrote the comments because I thought someone might be confused by the above
>> changes :)
>
> Stuff like this needs to be split into a single patch for iwpm_admin
>
> Jason
>
Sure, I will split all of the changes into separate patches.
Weihang
next prev parent reply other threads:[~2021-05-18 3:30 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 [this message]
2021-05-17 23:03 ` Saleem, Shiraz
2021-05-18 3:34 ` liweihang
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=74a596dd3d204674a89818f4537d78db@huawei.com \
--to=liweihang@huawei.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linuxarm@huawei.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