1. 02 3月, 2022 1 次提交
  2. 10 12月, 2021 1 次提交
  3. 26 10月, 2021 1 次提交
    • P
      net: batman-adv: fix error handling · 6f68cd63
      Pavel Skripkin 提交于
      Syzbot reported ODEBUG warning in batadv_nc_mesh_free(). The problem was
      in wrong error handling in batadv_mesh_init().
      
      Before this patch batadv_mesh_init() was calling batadv_mesh_free() in case
      of any batadv_*_init() calls failure. This approach may work well, when
      there is some kind of indicator, which can tell which parts of batadv are
      initialized; but there isn't any.
      
      All written above lead to cleaning up uninitialized fields. Even if we hide
      ODEBUG warning by initializing bat_priv->nc.work, syzbot was able to hit
      GPF in batadv_nc_purge_paths(), because hash pointer in still NULL. [1]
      
      To fix these bugs we can unwind batadv_*_init() calls one by one.
      It is good approach for 2 reasons: 1) It fixes bugs on error handling
      path 2) It improves the performance, since we won't call unneeded
      batadv_*_free() functions.
      
      So, this patch makes all batadv_*_init() clean up all allocated memory
      before returning with an error to no call correspoing batadv_*_free()
      and open-codes batadv_mesh_free() with proper order to avoid touching
      uninitialized fields.
      
      Link: https://lore.kernel.org/netdev/000000000000c87fbd05cef6bcb0@google.com/ [1]
      Reported-and-tested-by: syzbot+28b0702ada0bf7381f58@syzkaller.appspotmail.com
      Fixes: c6c8fea2 ("net: Add batman-adv meshing protocol")
      Signed-off-by: NPavel Skripkin <paskripkin@gmail.com>
      Acked-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      6f68cd63
  4. 20 8月, 2021 2 次提交
    • S
      batman-adv: Drop NULL check before dropping references · a2b7b148
      Sven Eckelmann 提交于
      The check if a batman-adv related object is NULL or not is now directly in
      the batadv_*_put functions. It is not needed anymore to perform this check
      outside these function:
      
      The changes were generated using a coccinelle semantic patch:
      
        @@
        expression E;
        @@
        - if (likely(E != NULL))
        (
        batadv_backbone_gw_put
        |
        batadv_claim_put
        |
        batadv_dat_entry_put
        |
        batadv_gw_node_put
        |
        batadv_hardif_neigh_put
        |
        batadv_hardif_put
        |
        batadv_nc_node_put
        |
        batadv_nc_path_put
        |
        batadv_neigh_ifinfo_put
        |
        batadv_neigh_node_put
        |
        batadv_orig_ifinfo_put
        |
        batadv_orig_node_put
        |
        batadv_orig_node_vlan_put
        |
        batadv_softif_vlan_put
        |
        batadv_tp_vars_put
        |
        batadv_tt_global_entry_put
        |
        batadv_tt_local_entry_put
        |
        batadv_tt_orig_list_entry_put
        |
        batadv_tt_req_node_put
        |
        batadv_tvlv_container_put
        |
        batadv_tvlv_handler_put
        )(E);
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      a2b7b148
    • S
      batman-adv: Check ptr for NULL before reducing its refcnt · e78783da
      Sven Eckelmann 提交于
      The commit b37a4668 ("netdevice: add the case if dev is NULL") changed
      the way how the NULL check for net_devices have to be handled when trying
      to reduce its reference counter. Before this commit, it was the
      responsibility of the caller to check whether the object is NULL or not.
      But it was changed to behave more like kfree. Now the callee has to handle
      the NULL-case.
      
      The batman-adv code was scanned via cocinelle for similar places. These
      were changed to use the paradigm
      
        @@
        identifier E, T, R, C;
        identifier put;
        @@
         void put(struct T *E)
         {
        +	if (!E)
        +		return;
        	kref_put(&E->C, R);
         }
      
      Functions which were used in other sources files were moved to the header
      to allow the compiler to inline the NULL check and the kref_put call.
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      e78783da
  5. 09 8月, 2021 2 次提交
    • S
      batman-adv: Drop NULL check before dropping references · 79a0bffb
      Sven Eckelmann 提交于
      The check if a batman-adv related object is NULL or not is now directly in
      the batadv_*_put functions. It is not needed anymore to perform this check
      outside these function:
      
      The changes were generated using a coccinelle semantic patch:
      
        @@
        expression E;
        @@
        - if (likely(E != NULL))
        (
        batadv_backbone_gw_put
        |
        batadv_claim_put
        |
        batadv_dat_entry_put
        |
        batadv_gw_node_put
        |
        batadv_hardif_neigh_put
        |
        batadv_hardif_put
        |
        batadv_nc_node_put
        |
        batadv_nc_path_put
        |
        batadv_neigh_ifinfo_put
        |
        batadv_neigh_node_put
        |
        batadv_orig_ifinfo_put
        |
        batadv_orig_node_put
        |
        batadv_orig_node_vlan_put
        |
        batadv_softif_vlan_put
        |
        batadv_tp_vars_put
        |
        batadv_tt_global_entry_put
        |
        batadv_tt_local_entry_put
        |
        batadv_tt_orig_list_entry_put
        |
        batadv_tt_req_node_put
        |
        batadv_tvlv_container_put
        |
        batadv_tvlv_handler_put
        )(E);
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      79a0bffb
    • S
      batman-adv: Check ptr for NULL before reducing its refcnt · 6340dcbd
      Sven Eckelmann 提交于
      The commit b37a4668 ("netdevice: add the case if dev is NULL") changed
      the way how the NULL check for net_devices have to be handled when trying
      to reduce its reference counter. Before this commit, it was the
      responsibility of the caller to check whether the object is NULL or not.
      But it was changed to behave more like kfree. Now the callee has to handle
      the NULL-case.
      
      The batman-adv code was scanned via cocinelle for similar places. These
      were changed to use the paradigm
      
        @@
        identifier E, T, R, C;
        identifier put;
        @@
         void put(struct T *E)
         {
        +	if (!E)
        +		return;
        	kref_put(&E->C, R);
         }
      
      Functions which were used in other sources files were moved to the header
      to allow the compiler to inline the NULL check and the kref_put call.
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      6340dcbd
  6. 06 2月, 2021 1 次提交
    • S
      batman-adv: Drop publication years from copyright info · cfa55c6d
      Sven Eckelmann 提交于
      The batman-adv source code was using the year of publication (to net-next)
      as "last" year for the copyright statement. The whole source code mentioned
      in the MAINTAINERS "BATMAN ADVANCED" section was handled as a single entity
      regarding the publishing year.
      
      This avoided having outdated (in sense of year information - not copyright
      holder) publishing information inside several files. But since the simple
      "update copyright year" commit (without other changes) in the file was not
      well received in the upstream kernel, the option to not have a copyright
      year (for initial and last publication) in the files are chosen instead.
      More detailed information about the years can still be retrieved from the
      SCM system.
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Acked-by: NMarek Lindner <mareklindner@neomailbox.ch>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      cfa55c6d
  7. 04 12月, 2020 1 次提交
  8. 19 8月, 2020 2 次提交
  9. 26 6月, 2020 1 次提交
  10. 21 4月, 2020 1 次提交
    • G
      batman-adv: fix batadv_nc_random_weight_tq · fd0c42c4
      George Spelvin 提交于
      and change to pseudorandom numbers, as this is a traffic dithering
      operation that doesn't need crypto-grade.
      
      The previous code operated in 4 steps:
      
      1. Generate a random byte 0 <= rand_tq <= 255
      2. Multiply it by BATADV_TQ_MAX_VALUE - tq
      3. Divide by 255 (= BATADV_TQ_MAX_VALUE)
      4. Return BATADV_TQ_MAX_VALUE - rand_tq
      
      This would apperar to scale (BATADV_TQ_MAX_VALUE - tq) by a random
      value between 0/255 and 255/255.
      
      But!  The intermediate value between steps 3 and 4 is stored in a u8
      variable.  So it's truncated, and most of the time, is less than 255, after
      which the division produces 0.  Specifically, if tq is odd, the product is
      always even, and can never be 255.  If tq is even, there's exactly one
      random byte value that will produce a product byte of 255.
      
      Thus, the return value is 255 (511/512 of the time) or 254 (1/512
      of the time).
      
      If we assume that the truncation is a bug, and the code is meant to scale
      the input, a simpler way of looking at it is that it's returning a random
      value between tq and BATADV_TQ_MAX_VALUE, inclusive.
      
      Well, we have an optimized function for doing just that.
      
      Fixes: 3c12de9a ("batman-adv: network coding - code and transmit packets if possible")
      Signed-off-by: NGeorge Spelvin <lkml@sdf.org>
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      fd0c42c4
  11. 01 1月, 2020 1 次提交
  12. 28 6月, 2019 1 次提交
  13. 25 3月, 2019 1 次提交
  14. 04 1月, 2019 1 次提交
  15. 06 9月, 2018 1 次提交
    • S
      batman-adv: Prevent duplicated nc_node entry · fa122fec
      Sven Eckelmann 提交于
      The function batadv_nc_get_nc_node is responsible for adding new nc_nodes
      to the in_coding_list and out_coding_list. It first checks whether the
      entry already is in the list or not. If it is, then the creation of a new
      entry is aborted.
      
      But the lock for the list is only held when the list is really modified.
      This could lead to duplicated entries because another context could create
      an entry with the same key between the check and the list manipulation.
      
      The check and the manipulation of the list must therefore be in the same
      locked code section.
      
      Fixes: d56b1705 ("batman-adv: network coding - detect coding nodes and remove these after timeout")
      Signed-off-by: NSven Eckelmann <sven@narfation.org>
      Acked-by: NMarek Lindner <mareklindner@neomailbox.ch>
      Signed-off-by: NSimon Wunderlich <sw@simonwunderlich.de>
      fa122fec
  16. 27 2月, 2018 1 次提交
  17. 22 12月, 2017 1 次提交
  18. 16 12月, 2017 4 次提交
  19. 23 5月, 2017 1 次提交
  20. 26 1月, 2017 1 次提交
  21. 09 11月, 2016 1 次提交
  22. 30 10月, 2016 1 次提交
  23. 19 10月, 2016 1 次提交
  24. 09 8月, 2016 4 次提交
  25. 30 6月, 2016 2 次提交
  26. 10 5月, 2016 3 次提交
  27. 04 5月, 2016 2 次提交