netfilter: xt_hashlimit: unregister proc file before releasing mutex
Subsystems (3)
PATCH 1/1 netfilter: xt_hashlimit: unregister proc file before releasing mutex
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel htable_create() could register the same file immediately after the mutex is released.
Move htable_remove_proc_entry() back to mutex protection to fix this. And, fold htable_destroy() into htable_put() to make the code slightly easier to understand.
--- net/netfilter/xt_hashlimit.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
net/netfilter/xt_hashlimit.c +6 -10
@@ -402,15 +402,6 @@ static void htable_remove_proc_entry(struct xt_hashlimit_htable *hinfo)remove_proc_entry (hinfo->name, parent); } -static void htable_destroy (struct xt_hashlimit_htable *hinfo) -{ -cancel_delayed_work_sync (&hinfo->gc_work); -htable_remove_proc_entry (hinfo); -htable_selective_cleanup (hinfo, true); -kfree (hinfo->name); -vfree (hinfo); -} -static struct xt_hashlimit_htable *htable_find_get (struct net *net,const char *name,u_int8_t family)
@@ -432,8 +423,13 @@ static void htable_put(struct xt_hashlimit_htable *hinfo) {if (refcount_dec_and_mutex_lock (&hinfo->use, &hashlimit_mutex)) {hlist_del (&hinfo->node); +htable_remove_proc_entry (hinfo);mutex_unlock (&hashlimit_mutex); -htable_destroy (hinfo); + +cancel_delayed_work_sync (&hinfo->gc_work); +htable_selective_cleanup (hinfo, true); +kfree (hinfo->name); +vfree (hinfo); } }
Signature · 1 line
2.21.1
Pablo Neira Ayuso
maintainerQuoted 9 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.
Probably revert previous one?
Quoted 8 lines · Pablo Neira Ayuso
Quoted 6 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.
Quoted 5 lines
Quoted 3 lines
Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.Probably revert previous one?
The hung task could appear again if we move the cleanup back under mutex.
Pablo Neira Ayuso
maintainerQuoted 9 lines · Cong Wang
Quoted 8 lines · Pablo Neira Ayuso
Quoted 6 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.Probably revert previous one?
The hung task could appear again if we move the cleanup back under mutex.
How could the hung task appear again by revertingc4a3922d2d20c710f827? Please elaborate.
Thanks.
Quoted 15 lines · Pablo Neira Ayuso
Quoted 13 lines · Cong Wang
Quoted 12 lines · Pablo Neira Ayuso
Quoted 9 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Probably revert previous one?
The hung task could appear again if we move the cleanup back under mutex.
How could the hung task appear again by reverting
c4a3922d2d20c710f827? Please elaborate.
Because the cfg.max could be as large as 8*HASHLIMIT_MAX_SIZE:
311 if (hinfo->cfg.max == 0)
312 hinfo->cfg.max = 8 * hinfo->cfg.size;
313 else if (hinfo->cfg.max < hinfo->cfg.size)
314 hinfo->cfg.max = hinfo->cfg.size;
Not sure whether we can finish cleaning up 8*HASHLIMIT_MAX_SIZE entries within the time a hung task tolerates. This largely depends on how much contention the spinlock has, at least I don't want to bet on it.
Thanks.
Pablo Neira Ayuso
maintainerQuoted 31 lines · Cong Wang
Quoted 15 lines · Pablo Neira Ayuso
Quoted 13 lines · Cong Wang
Quoted 12 lines · Pablo Neira Ayuso
Quoted 9 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Probably revert previous one?
The hung task could appear again if we move the cleanup back under mutex.
How could the hung task appear again by reverting
c4a3922d2d20c710f827? Please elaborate.Because the cfg.max could be as large as 8*HASHLIMIT_MAX_SIZE:
311 if (
hinfo->cfg.max== 0)
312hinfo->cfg.max= 8 *hinfo->cfg.size;
313 else if (hinfo->cfg.max<hinfo->cfg.size)
314hinfo->cfg.max=hinfo->cfg.size;
Quoted 4 lines
Not sure whether we can finish cleaning up 8*HASHLIMIT_MAX_SIZE entries within the time a hung task tolerates. This largely depends on how much contention the spinlock has, at least I don't want to bet on it.
Please, resend. Thanks.
Pablo Neira Ayuso
maintainerQuoted 32 lines · Pablo Neira Ayuso
Quoted 31 lines · Cong Wang
Quoted 15 lines · Pablo Neira Ayuso
Quoted 13 lines · Cong Wang
Quoted 12 lines · Pablo Neira Ayuso
Quoted 9 lines · Cong Wang
Before releasing the global mutex, we only unlink the hashtable from the hash list, its proc file is still not unregistered at this point. So syzbot could trigger a race condition where a parallel
htable_create()could register the same file immediately after the mutex is released.Move
htable_remove_proc_entry()back to mutex protection to fix this. And, foldhtable_destroy()intohtable_put()to make the code slightly easier to understand.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Probably revert previous one?
The hung task could appear again if we move the cleanup back under mutex.
How could the hung task appear again by reverting
c4a3922d2d20c710f827? Please elaborate.Because the cfg.max could be as large as 8*HASHLIMIT_MAX_SIZE:
311 if (
hinfo->cfg.max== 0)
312hinfo->cfg.max= 8 *hinfo->cfg.size;
313 else if (hinfo->cfg.max<hinfo->cfg.size)
314hinfo->cfg.max=hinfo->cfg.size;
Quoted 6 lines
Quoted 4 lines
Not sure whether we can finish cleaning up 8*HASHLIMIT_MAX_SIZE entries within the time a hung task tolerates. This largely depends on how much contention the spinlock has, at least I don't want to bet on it.
Please, resend. Thanks.
Sorry, I meant, applied, thanks.