0008-net-fix-deadlock-while-clearing-neighbor-proxy-table.patch 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Wolfgang Bumiller <[email protected]>
  3. Date: Mon, 9 Apr 2018 14:56:29 +0200
  4. Subject: [PATCH] net: fix deadlock while clearing neighbor proxy table
  5. When coming from ndisc_netdev_event() in net/ipv6/ndisc.c,
  6. neigh_ifdown() is called with &nd_tbl, locking this while
  7. clearing the proxy neighbor entries when eg. deleting an
  8. interface. Calling the table's pndisc_destructor() with the
  9. lock still held, however, can cause a deadlock: When a
  10. multicast listener is available an IGMP packet of type
  11. ICMPV6_MGM_REDUCTION may be sent out. When reaching
  12. ip6_finish_output2(), if no neighbor entry for the target
  13. address is found, __neigh_create() is called with &nd_tbl,
  14. which it'll want to lock.
  15. Move the elements into their own list, then unlock the table
  16. and perform the destruction.
  17. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199289
  18. Fixes: 6fd6ce2056de ("ipv6: Do not depend on rt->n in ip6_finish_output2().")
  19. Signed-off-by: Wolfgang Bumiller <[email protected]>
  20. ---
  21. net/core/neighbour.c | 28 ++++++++++++++++++----------
  22. 1 file changed, 18 insertions(+), 10 deletions(-)
  23. diff --git a/net/core/neighbour.c b/net/core/neighbour.c
  24. index 7f831711b6e0..ff6c491d92ac 100644
  25. --- a/net/core/neighbour.c
  26. +++ b/net/core/neighbour.c
  27. @@ -55,7 +55,8 @@ static void neigh_timer_handler(struct timer_list *t);
  28. static void __neigh_notify(struct neighbour *n, int type, int flags,
  29. u32 pid);
  30. static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid);
  31. -static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
  32. +static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
  33. + struct net_device *dev);
  34. #ifdef CONFIG_PROC_FS
  35. static const struct file_operations neigh_stat_seq_fops;
  36. @@ -291,8 +292,7 @@ int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
  37. {
  38. write_lock_bh(&tbl->lock);
  39. neigh_flush_dev(tbl, dev);
  40. - pneigh_ifdown(tbl, dev);
  41. - write_unlock_bh(&tbl->lock);
  42. + pneigh_ifdown_and_unlock(tbl, dev);
  43. del_timer_sync(&tbl->proxy_timer);
  44. pneigh_queue_purge(&tbl->proxy_queue);
  45. @@ -681,9 +681,10 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
  46. return -ENOENT;
  47. }
  48. -static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
  49. +static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
  50. + struct net_device *dev)
  51. {
  52. - struct pneigh_entry *n, **np;
  53. + struct pneigh_entry *n, **np, *freelist = NULL;
  54. u32 h;
  55. for (h = 0; h <= PNEIGH_HASHMASK; h++) {
  56. @@ -691,16 +692,23 @@ static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
  57. while ((n = *np) != NULL) {
  58. if (!dev || n->dev == dev) {
  59. *np = n->next;
  60. - if (tbl->pdestructor)
  61. - tbl->pdestructor(n);
  62. - if (n->dev)
  63. - dev_put(n->dev);
  64. - kfree(n);
  65. + n->next = freelist;
  66. + freelist = n;
  67. continue;
  68. }
  69. np = &n->next;
  70. }
  71. }
  72. + write_unlock_bh(&tbl->lock);
  73. + while ((n = freelist)) {
  74. + freelist = n->next;
  75. + n->next = NULL;
  76. + if (tbl->pdestructor)
  77. + tbl->pdestructor(n);
  78. + if (n->dev)
  79. + dev_put(n->dev);
  80. + kfree(n);
  81. + }
  82. return -ENOENT;
  83. }
  84. --
  85. 2.14.2