]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
iwlwifi: dvm: don't call << operator with a negative value
authorEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Sat, 7 Jan 2017 17:57:46 +0000 (19:57 +0200)
committerLuca Coelho <luciano.coelho@intel.com>
Wed, 8 Feb 2017 15:54:20 +0000 (17:54 +0200)
In https://bugzilla.kernel.org/show_bug.cgi?id=177341 Bob
reported a UBSAN WARNING on rs.c.

Undefined behaviour in drivers/net/wireless/intel/iwlwifi/dvm/rs.c:746:18

This because
i = index - 1;
for (mask = (1 << i); i >= 0; i--, mask >>= 1)

is unsafe: i could be negative and hence we can call <<
on a negative value.
This bug doesn't have any real impact since the condition
of the for loop will prevent any usage of mask.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=177341
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/dvm/rs.c

index 710dbbefd551eb6cc12563d5e18d9e7ef2339bab..ff44ebc5829d664d10f52c1125f0205a958364e1 100644 (file)
@@ -740,7 +740,10 @@ static u16 rs_get_adjacent_rate(struct iwl_priv *priv, u8 index, u16 rate_mask,
 
                /* Find the previous rate that is in the rate mask */
                i = index - 1;
-               for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
+               if (i >= 0)
+                       mask = BIT(i);
+
+               for (; i >= 0; i--, mask >>= 1) {
                        if (rate_mask & mask) {
                                low = i;
                                break;