0004-batman-adv-add-two-more-patches-from-the-upstream-maint-branch.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Mon, 15 Dec 2014 01:44:23 +0100
  3. Subject: batman-adv: add two more patches from the upstream 'maint' branch
  4. diff --git a/batman-adv/patches/0002-batman-adv-Fix-double-fetch-in-RCU-version-of-hlist_.patch b/batman-adv/patches/0002-batman-adv-Fix-double-fetch-in-RCU-version-of-hlist_.patch
  5. new file mode 100644
  6. index 0000000..6fb2e63
  7. --- /dev/null
  8. +++ b/batman-adv/patches/0002-batman-adv-Fix-double-fetch-in-RCU-version-of-hlist_.patch
  9. @@ -0,0 +1,54 @@
  10. +From 2cbadf647c3836ad1cf62ec5554fbeee7b3d6ecd Mon Sep 17 00:00:00 2001
  11. +Message-Id: <2cbadf647c3836ad1cf62ec5554fbeee7b3d6ecd.1418604208.git.mschiffer@universe-factory.net>
  12. +In-Reply-To: <0c8001036a191efd3aa30493ba7e31f9eceb21e1.1418604208.git.mschiffer@universe-factory.net>
  13. +References: <0c8001036a191efd3aa30493ba7e31f9eceb21e1.1418604208.git.mschiffer@universe-factory.net>
  14. +From: Sven Eckelmann <sven@narfation.org>
  15. +Date: Mon, 3 Nov 2014 23:16:19 +0100
  16. +Subject: [PATCH] batman-adv: Fix double fetch in RCU version of hlist_*entry*
  17. +
  18. +The backported (<3.9) version of hlist_for_each_entry_rcu and
  19. +hlist_for_each_entry_safe uses the new macro hlist_entry_safe. It is called
  20. +with an ACCESS_ONCE parameter for the first parameter ptr. This disallows
  21. +merging of the two loads which the current version of the macro uses.
  22. +
  23. +This is problematic because this macro must only generate one load. Otherwise
  24. +with two contexts (or CPUs) following could happen:
  25. +
  26. +1. context 1 fetches the ptr to the last entry in hlist_entry_safe() and
  27. + accepts this non-NULL ptr
  28. +
  29. +2. context 2 deletes the last entry and terminates the list with NULL
  30. +
  31. +3. context 1 re-fetches the pointer, doesn't check for zero, calculates the
  32. + entry based on a NULL pointer
  33. +
  34. +4. context 1 crashes because it tries to load/write data from/to the invalid
  35. + address
  36. +
  37. +Instead use a single load to a temporary variable and do the NULL-check and
  38. +calculation based on that one.
  39. +
  40. +Signed-off-by: Sven Eckelmann <sven@narfation.org>
  41. +Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
  42. +---
  43. + compat.h | 4 +++-
  44. + 1 file changed, 3 insertions(+), 1 deletion(-)
  45. +
  46. +diff --git a/compat.h b/compat.h
  47. +index 5eb5fe6..79ba39b 100644
  48. +--- a/compat.h
  49. ++++ b/compat.h
  50. +@@ -345,7 +345,9 @@ static int __batadv_interface_tx(struct sk_buff *skb, \
  51. + dev->master;\
  52. + })
  53. + #define hlist_entry_safe(ptr, type, member) \
  54. +- (ptr) ? hlist_entry(ptr, type, member) : NULL
  55. ++ ({ typeof(ptr) ____ptr = (ptr); \
  56. ++ ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
  57. ++ })
  58. +
  59. + #undef hlist_for_each_entry
  60. + #define hlist_for_each_entry(pos, head, member) \
  61. +--
  62. +2.1.3
  63. +
  64. diff --git a/batman-adv/patches/0003-batman-adv-fix-delayed-foreign-originator-recognitio.patch b/batman-adv/patches/0003-batman-adv-fix-delayed-foreign-originator-recognitio.patch
  65. new file mode 100644
  66. index 0000000..2748f76
  67. --- /dev/null
  68. +++ b/batman-adv/patches/0003-batman-adv-fix-delayed-foreign-originator-recognitio.patch
  69. @@ -0,0 +1,56 @@
  70. +From 207d13673fd25e5ae1bc8bb42d1efd4ec4c2dc4d Mon Sep 17 00:00:00 2001
  71. +Message-Id: <207d13673fd25e5ae1bc8bb42d1efd4ec4c2dc4d.1418604208.git.mschiffer@universe-factory.net>
  72. +In-Reply-To: <0c8001036a191efd3aa30493ba7e31f9eceb21e1.1418604208.git.mschiffer@universe-factory.net>
  73. +References: <0c8001036a191efd3aa30493ba7e31f9eceb21e1.1418604208.git.mschiffer@universe-factory.net>
  74. +From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@c0d3.blue>
  75. +Date: Thu, 30 Oct 2014 06:23:40 +0100
  76. +Subject: [PATCH] batman-adv: fix delayed foreign originator recognition
  77. +MIME-Version: 1.0
  78. +Content-Type: text/plain; charset=UTF-8
  79. +Content-Transfer-Encoding: 8bit
  80. +
  81. +Currently it can happen that the reception of an OGM from a new
  82. +originator is not being accepted. More precisely it can happen that
  83. +an originator struct gets allocated and initialized
  84. +(batadv_orig_node_new()), even the TQ gets calculated and set correctly
  85. +(batadv_iv_ogm_calc_tq()) but still the periodic orig_node purging
  86. +thread will decide to delete it if it has a chance to jump between
  87. +these two function calls.
  88. +
  89. +This is because batadv_orig_node_new() initializes the last_seen value
  90. +to zero and its caller (batadv_iv_ogm_orig_get()) makes it visible to
  91. +other threads by adding it to the hash table already.
  92. +batadv_iv_ogm_calc_tq() will set the last_seen variable to the correct,
  93. +current time a few lines later but if the purging thread jumps in between
  94. +that it will think that the orig_node timed out and will wrongly
  95. +schedule it for deletion already.
  96. +
  97. +If the purging interval is the same as the originator interval (which is
  98. +the default: 1 second), then this game can continue for several rounds
  99. +until the random OGM jitter added enough difference between these
  100. +two (in tests, two to about four rounds seemed common).
  101. +
  102. +Fixing this by initializing the last_seen variable of an orig_node
  103. +to the current time before adding it to the hash table.
  104. +
  105. +Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
  106. +Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
  107. +---
  108. + originator.c | 1 +
  109. + 1 file changed, 1 insertion(+)
  110. +
  111. +diff --git a/originator.c b/originator.c
  112. +index 6a48451..648bdba 100644
  113. +--- a/originator.c
  114. ++++ b/originator.c
  115. +@@ -678,6 +678,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
  116. + atomic_set(&orig_node->last_ttvn, 0);
  117. + orig_node->tt_buff = NULL;
  118. + orig_node->tt_buff_len = 0;
  119. ++ orig_node->last_seen = jiffies;
  120. + reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
  121. + orig_node->bcast_seqno_reset = reset_time;
  122. + #ifdef CONFIG_BATMAN_ADV_MCAST
  123. +--
  124. +2.1.3
  125. +