]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
batman-adv: Fix integer overflow in batadv_iv_ogm_calc_tq
authorSven Eckelmann <sven.eckelmann@open-mesh.com>
Tue, 16 Feb 2016 09:47:07 +0000 (10:47 +0100)
committerAntonio Quartulli <a@unstable.cc>
Wed, 18 May 2016 03:49:42 +0000 (11:49 +0800)
The undefined behavior sanatizer detected an signed integer overflow in a
setup with near perfect link quality

    UBSAN: Undefined behaviour in net/batman-adv/bat_iv_ogm.c:1246:25
    signed integer overflow:
    8713350 * 255 cannot be represented in type 'int'

The problems happens because the calculation of mixed unsigned and signed
integers resulted in an integer multiplication.

      batadv_ogm_packet::tq (u8 255)
    * tq_own (u8 255)
    * tq_asym_penalty (int 134; max 255)
    * tq_iface_penalty (int 255; max 255)

The tq_iface_penalty, tq_asym_penalty and inv_asym_penalty can just be
changed to unsigned int because they are not expected to become negative.

Fixes: c039876892e3 ("batman-adv: add WiFi penalty")
Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
net/batman-adv/bat_iv_ogm.c

index 1b5bbafc0fa3f288dee1040641214b022f3718d0..ce2f203048d35a606487e9cd3a9acec3d72d85f6 100644 (file)
@@ -1180,9 +1180,10 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
        u8 total_count;
        u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
        unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
-       int tq_asym_penalty, inv_asym_penalty, if_num;
+       int if_num;
+       unsigned int tq_asym_penalty, inv_asym_penalty;
        unsigned int combined_tq;
-       int tq_iface_penalty;
+       unsigned int tq_iface_penalty;
        bool ret = false;
 
        /* find corresponding one hop neighbor */