[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ygnhpmsqbjn0.fsf@nvidia.com>
Date: Thu, 30 Sep 2021 10:35:47 +0300
From: Vlad Buslov <vladbu@...dia.com>
To: Cong Wang <xiyou.wangcong@...il.com>
CC: David Miller <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Jamal Hadi Salim <jhs@...atatu.com>,
Jiri Pirko <jiri@...nulli.us>,
"Linux Kernel Network Developers" <netdev@...r.kernel.org>
Subject: Re: [PATCH net] net: sched: flower: protect fl_walk() with rcu
On Thu 30 Sep 2021 at 08:12, Cong Wang <xiyou.wangcong@...il.com> wrote:
> On Wed, Sep 29, 2021 at 8:09 AM Vlad Buslov <vladbu@...dia.com> wrote:
>>
>> Patch that refactored fl_walk() to use idr_for_each_entry_continue_ul()
>> also removed rcu protection of individual filters which causes following
>> use-after-free when filter is deleted concurrently. Fix fl_walk() to obtain
>> rcu read lock while iterating and taking the filter reference and temporary
>> release the lock while calling arg->fn() callback that can sleep.
>>
> ...
>> Fixes: d39d714969cd ("idr: introduce idr_for_each_entry_continue_ul()")
>
> I don't dig the history, but I think this bug is introduced by your commit
> which makes cls_flower lockless. If we still had RTNL lock here, we
> would not have this bug, right?
Original commit that removed RTNL lock dependency from flower used
following helper function to safely iterate over filters in fl_walk():
static struct cls_fl_filter *fl_get_next_filter(struct tcf_proto *tp,
unsigned long *handle)
{
struct cls_fl_head *head = fl_head_dereference(tp);
struct cls_fl_filter *f;
rcu_read_lock();
while ((f = idr_get_next_ul(&head->handle_idr, handle))) {
/* don't return filters that are being deleted */
if (refcount_inc_not_zero(&f->refcnt))
break;
++(*handle);
}
rcu_read_unlock();
return f;
}
Then commit referenced in Fixes tag inlined the code from helper
function into fl_walk(), simultaneously introducing
idr_for_each_entry_continue_ul() for iteration over idr and removing rcu
read lock.
>
>> Signed-off-by: Vlad Buslov <vladbu@...dia.com>
>
> Other than the Fixes tag,
>
> Acked-by: Cong Wang <cong.wang@...edance.com>
>
> Thanks.
Powered by blists - more mailing lists