Message ID | 20220729103559.215140-2-alexander.mikhalitsyn@virtuozzo.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | neighbour: fix possible DoS due to net iface start/stop loop | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Guessing tree name failed - patch did not apply |
On 7/29/22 4:35 AM, Alexander Mikhalitsyn wrote: > The patch proposed doing very simple thing. It drops only packets from it does 2 things - adds a namespace check and a performance based change with the way the list is walked. > the same namespace in the pneigh_queue_purge() where network interface > state change is detected. This is enough to prevent the problem for the > whole node preserving original semantics of the code. > > diff --git a/net/core/neighbour.c b/net/core/neighbour.c > index 54625287ee5b..213ec0be800b 100644 > --- a/net/core/neighbour.c > +++ b/net/core/neighbour.c > @@ -386,8 +396,7 @@ static int __neigh_ifdown(struct neigh_table *tbl, struct net_device *dev, > neigh_flush_dev(tbl, dev, skip_perm); > pneigh_ifdown_and_unlock(tbl, dev); > > - del_timer_sync(&tbl->proxy_timer); why are you removing this line too? > - pneigh_queue_purge(&tbl->proxy_queue); > + pneigh_queue_purge(&tbl->proxy_queue, dev_net(dev)); > return 0; > } >
On 01.08.2022 17:08, David Ahern wrote: > On 7/29/22 4:35 AM, Alexander Mikhalitsyn wrote: >> The patch proposed doing very simple thing. It drops only packets from > it does 2 things - adds a namespace check and a performance based change > with the way the list is walked. I believe no. All items are removed before the patch and all items are walked after the patch, similar O(n) operation. >> the same namespace in the pneigh_queue_purge() where network interface >> state change is detected. This is enough to prevent the problem for the >> whole node preserving original semantics of the code. >> > >> diff --git a/net/core/neighbour.c b/net/core/neighbour.c >> index 54625287ee5b..213ec0be800b 100644 >> --- a/net/core/neighbour.c >> +++ b/net/core/neighbour.c >> @@ -386,8 +396,7 @@ static int __neigh_ifdown(struct neigh_table *tbl, struct net_device *dev, >> neigh_flush_dev(tbl, dev, skip_perm); >> pneigh_ifdown_and_unlock(tbl, dev); >> >> - del_timer_sync(&tbl->proxy_timer); > why are you removing this line too? Because we have packets in the queue after the purge and they have to be processed. May be we should better do if (skb_queue_empty(&tbl->proxy_queue)) del_timer_sync(&tbl->proxy_timer); after the purge. That could be more correct. >> - pneigh_queue_purge(&tbl->proxy_queue); >> + pneigh_queue_purge(&tbl->proxy_queue, dev_net(dev)); >> return 0; >> } >>
diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 54625287ee5b..213ec0be800b 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -307,14 +307,24 @@ static int neigh_del_timer(struct neighbour *n) return 0; } -static void pneigh_queue_purge(struct sk_buff_head *list) +static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net) { + unsigned long flags; struct sk_buff *skb; - while ((skb = skb_dequeue(list)) != NULL) { - dev_put(skb->dev); - kfree_skb(skb); + spin_lock_irqsave(&list->lock, flags); + skb = skb_peek(list); + while (skb) { + struct sk_buff *skb_next = skb_peek_next(skb, list); + + if (!net || net_eq(dev_net(skb->dev), net)) { + __skb_unlink(skb, list); + dev_put(skb->dev); + kfree_skb(skb); + } + skb = skb_next; } + spin_unlock_irqrestore(&list->lock, flags); } static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev, @@ -386,8 +396,7 @@ static int __neigh_ifdown(struct neigh_table *tbl, struct net_device *dev, neigh_flush_dev(tbl, dev, skip_perm); pneigh_ifdown_and_unlock(tbl, dev); - del_timer_sync(&tbl->proxy_timer); - pneigh_queue_purge(&tbl->proxy_queue); + pneigh_queue_purge(&tbl->proxy_queue, dev_net(dev)); return 0; } @@ -1787,7 +1796,7 @@ int neigh_table_clear(int index, struct neigh_table *tbl) cancel_delayed_work_sync(&tbl->managed_work); cancel_delayed_work_sync(&tbl->gc_work); del_timer_sync(&tbl->proxy_timer); - pneigh_queue_purge(&tbl->proxy_queue); + pneigh_queue_purge(&tbl->proxy_queue, NULL); neigh_ifdown(tbl, NULL); if (atomic_read(&tbl->entries)) pr_crit("neighbour leakage\n");