All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Coelho <luca@coelho.fi>
To: linux-wireless@vger.kernel.org
Cc: kvalo@codeaurora.org,
	Emmanuel Grumbach <emmanuel.grumbach@intel.com>,
	Luca Coelho <luciano.coelho@intel.com>
Subject: [PATCH 11/17] iwlwifi: dvm: don't call << operator with a negative value
Date: Wed,  8 Feb 2017 17:51:43 +0200	[thread overview]
Message-ID: <20170208155149.1704-3-luca@coelho.fi> (raw)
In-Reply-To: <20170208155149.1704-1-luca@coelho.fi>

From: Emmanuel Grumbach <emmanuel.grumbach@intel.com>

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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rs.c b/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
index 710dbbefd551..ff44ebc5829d 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
@@ -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;
-- 
2.11.0

  parent reply	other threads:[~2017-02-08 15:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-08 11:23 [PATCH 00/17] iwlwifi: updates intended for v4.11 2017-02-08 Luca Coelho
2017-02-08 11:23 ` [PATCH 01/17] iwlwifi: pcie: move msix conf functions above other functions Luca Coelho
2017-02-08 11:23 ` [PATCH 02/17] iwlwifi: pcie: separate between SW and HW MSIX configuration Luca Coelho
2017-02-08 11:23 ` [PATCH 03/17] iwlwifi: pcie: re-configure IVAR table after suspend-resume Luca Coelho
2017-02-08 11:23 ` [PATCH 04/17] iwlwifi: pcie: Re-configure IVAR table after stop device Luca Coelho
2017-02-08 11:23 ` [PATCH 05/17] iwlwifi: mvm: fix a print of NSS for HT rate Luca Coelho
2017-02-08 11:23 ` [PATCH 06/17] iwlwifi: mvm: fix references to first_agg_queue in DQA mode Luca Coelho
2017-02-08 11:23 ` [PATCH 07/17] iwlwifi: mvm: fix reorder timer re-arming Luca Coelho
2017-02-08 11:23 ` [PATCH 08/17] iwlwifi: mvm: use the PROBE_RESP_QUEUE to send deauth to unknown station Luca Coelho
2017-02-08 14:29 ` [PATCH 00/17] iwlwifi: updates intended for v4.11 2017-02-08 Kalle Valo
2017-02-08 14:31   ` Coelho, Luciano
2017-02-08 15:51 ` [PATCH 09/17] iwlwifi: pcie: don't increment / decrement a bool Luca Coelho
2017-02-08 15:51   ` [PATCH 10/17] iwlwifi: make RTPM depend on EXPERT Luca Coelho
2017-02-08 15:51   ` Luca Coelho [this message]
2017-02-08 15:51   ` [PATCH 12/17] iwlwifi: mvm: don't call << operator with a negative value Luca Coelho
2017-02-08 15:51   ` [PATCH 13/17] iwlwifi: pcie: set STATUS_RFKILL immediately after interrupt Luca Coelho
2017-02-08 15:51   ` [PATCH 14/17] iwlwifi: mvm: Fix CSA received immediately after association Luca Coelho
2017-02-08 15:51   ` [PATCH 15/17] iwlwifi: mvm: avoid race condition in ADD_STA Luca Coelho
2017-02-08 15:51   ` [PATCH 16/17] iwlwifi: mvm: Fix removal of IGTK Luca Coelho
2017-02-08 15:51   ` [PATCH 17/17] iwlwifi: mvm: avoid exceeding the allowed print length Luca Coelho

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170208155149.1704-3-luca@coelho.fi \
    --to=luca@coelho.fi \
    --cc=emmanuel.grumbach@intel.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.