Skip to contentSkip to conversation

airo: fix setting zero length WEP key

PATCH Superseded Stanislaw Gruszka 4 participants 38 messages Feb 2, 2010 – Mar 1, 2010 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 airo: fix setting zero length WEP key

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

---
 drivers/net/wireless/airo.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
drivers/net/wireless/airo.c +18 -16
index 4331d67..2a9f029 100644
@@ -5254,11 +5254,7 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	if (keylen == 0) {
-		airo_print_err(ai->dev->name, "%s: key length to set was zero",
-			       __func__);
-		return -1;
-	}
+	WARN_ON(keylen == 0);
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
@@ -6405,11 +6401,7 @@ static int airo_set_encode(struct net_device *dev,
 		if (dwrq->length > MIN_KEY_SIZE)
 			key.len = MAX_KEY_SIZE;
 		else
-			if (dwrq->length > 0)
-				key.len = MIN_KEY_SIZE;
-			else
-				/* Disable the key */
-				key.len = 0;
+			key.len = MIN_KEY_SIZE;
 		/* Check if the key is not marked as invalid */
 		if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
 			/* Cleanup */
@@ -6590,12 +6582,22 @@ static int airo_set_encodeext(struct net_device *dev,
 		default:
 			return -EINVAL;
 		}
-		/* Send the key to the card */
-		rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
-		if (rc < 0) {
-			airo_print_err(local->dev->name, "failed to set WEP key"
-			               " at index %d: %d.", idx, rc);
-			return rc;
+		if (key.len == 0) {
+			rc = set_wep_tx_idx(local, idx, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP transmit index to %d: %d.",
+					       idx, rc);
+				return rc;
+			}
+		} else {
+			rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP key at index %d: %d.",
+					       idx, rc);
+				return rc;
+			}
 		}
 	}
 
Signature · 1 line
1.6.2.5
Tested-by on v1 1/1
#1 lore raw
| Patch prevents call set_wep_key() with zero key length. That fix long
| standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a
| "airo: clean up WEP key operations". Additionally print call trace when
| someone will try to use improper parameters, and remove key.len = 0
| assignment, because it is in not possible code path.
| 
| Reported-and-bisected-by: Chris Siebenmann <[email protected]>
| Cc: Dan Williams <[email protected]>
| Cc: <[email protected]>
| Signed-off-by: Stanislaw Gruszka <[email protected]>

(Tested on a Thinkpad T42, using current git tip + this patch; HEAD is ab658321f32770b903a4426e2a6fae0392757755. This is the same machine I bisected the problem on.)

- cks

#2 lore raw
In reply to Stanislaw Gruszka
Quoted 5 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

What problem/regression does this actually fix? set_wep_key() should never be called with zero-length key, so we should actually be returning from that function instead of using WARN_ON() which would allow a zero-length key to be set (which isn't really valid).

To disable a WEP key, the WEXT caller should be setting IW_ENCODE_DISABLED in the flags, and *not* sending WEP keys. Or if they do for some reason send WEP keys, they need to use the key flag IW_ENCODE_NOKEY to ensure they key is marked as "invalid" and ignored by the driver.

Dan

#3 lore raw
| > Patch prevents call set_wep_key() with zero key
| > length. That fix long standing regression since commit
| > c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key
| > operations". [...]
|
| What problem/regression does this actually fix? [...]

That mentioned commit broke wireless on a Thinkpad T42 (running Fedora
11); from that commit onwards, the wireless system appeared to see no networks. The patch makes things work again.

More details are in the Fedora bugzilla:

	https://bugzilla.redhat.com/show_bug.cgi?id=522530

	- cks
#4 lore raw
Quoted 7 lines · Chris Siebenmann
| > Patch prevents call set_wep_key() with zero key
| > length. That fix long standing regression since commit
| > c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key
| > operations". [...]
|
| What problem/regression does this actually fix? [...]
Quoted 6 lines

That mentioned commit broke wireless on a Thinkpad T42 (running Fedora
11); from that commit onwards, the wireless system appeared to see no networks. The patch makes things work again.

More details are in the Fedora bugzilla:

	https://bugzilla.redhat.com/show_bug.cgi?id=522530

You mean with iwlist? That's quite odd because setting WEP keys doesn't have anything to do with the scanning stuff, even in the firmware. Note that Airo has always been somewhat tempermental for scans and you may or may not see any or all APs in any given scan.

Dan

#5 lore raw
| >  That mentioned commit broke wireless on a Thinkpad T42 (running Fedora
| > 11); from that commit onwards, the wireless system appeared to see no
| > networks. The patch makes things work again.
| > 
| >  More details are in the Fedora bugzilla:
| > 	https://bugzilla.redhat.com/show_bug.cgi?id=522530
| 
| You mean with iwlist?  That's quite odd because setting WEP keys
| doesn't have anything to do with the scanning stuff, even in the
| firmware.  Note that Airo has always been somewhat tempermental for
| scans and you may or may not see any or all APs in any given scan.

All I know is that the failure is total; in all situations I've
tried where a good kernel sees one or more networks and APs, a bad kernel sees none at all (and 'iwlist wifi0 scanning' reports 'No scan results'). A good kernel sometimes reports different numbers of networks and sometimes has quality problems, but a bad kernel never sees anything.

(Well, has never seen anything within a relatively modest amount of time. I have not let it sit for, say, an hour in order to see if something magically gets better; I have always rebooted into a kernel with working wireless.)

- cks

#6 lore raw
Quoted 19 lines · Chris Siebenmann
| >  That mentioned commit broke wireless on a Thinkpad T42 (running Fedora
| > 11); from that commit onwards, the wireless system appeared to see no
| > networks. The patch makes things work again.
| > 
| >  More details are in the Fedora bugzilla:
| > 	https://bugzilla.redhat.com/show_bug.cgi?id=522530
| 
| You mean with iwlist?  That's quite odd because setting WEP keys
| doesn't have anything to do with the scanning stuff, even in the
| firmware.  Note that Airo has always been somewhat tempermental for
| scans and you may or may not see any or all APs in any given scan.

All I know is that the failure is total; in all situations I've
tried where a good kernel sees one or more networks and APs, a bad kernel sees none at all (and 'iwlist wifi0 scanning' reports 'No scan results'). A good kernel sometimes reports different numbers of networks and sometimes has quality problems, but a bad kernel never sees anything.

Quoted 4 lines

(Well, has never seen anything within a relatively modest amount of time. I have not let it sit for, say, an hour in order to see if something magically gets better; I have always rebooted into a kernel with working wireless.)

When are you attempting to scan? Is anything like wpa_supplicant or NetworkManager running in the background when you do this?

Dan

#7 lore raw

| When are you attempting to scan? Is anything like wpa_supplicant or | NetworkManager running in the background when you do this?

My primary results are from Fedora 11's GNOME GUI (boot machine, log
in, attempt to connect to one of our wireless networks in various places); I believe that this uses NetworkManager. I tried with iwlist now and got the same results, but it looks like wpa_supplicant and NetworkManager were both running at the time based on pstree output.

- cks

#8 lore raw
Quoted 8 lines · Chris Siebenmann

| When are you attempting to scan? Is anything like wpa_supplicant or | NetworkManager running in the background when you do this?

My primary results are from Fedora 11's GNOME GUI (boot machine, log
in, attempt to connect to one of our wireless networks in various places); I believe that this uses NetworkManager. I tried with iwlist now and got the same results, but it looks like wpa_supplicant and NetworkManager were both running at the time based on pstree output.

Ok, that should be fine since wpa_supplicant is the only thing hitting the airo up for scans and whatnot. I'm grabbing a kernel now to do some testing with my 350 (PCMCIA). I assume you have an internal minicard?

Dan

#9 lore raw
| > | When are you attempting to scan?  Is anything like wpa_supplicant
| > | or NetworkManager running in the background when you do this?
| >
| >  My primary results are from Fedora 11's GNOME GUI (boot machine,
| > log in, attempt to connect to one of our wireless networks in
| > various places); I believe that this uses NetworkManager. I tried
| > with iwlist now and got the same results, but it looks like
| > wpa_supplicant and NetworkManager were both running at the time
| > based on pstree output.
|
| Ok, that should be fine since wpa_supplicant is the only thing hitting
| the airo up for scans and whatnot.  I'm grabbing a kernel now to do
| some testing with my 350 (PCMCIA).  I assume you have an internal
| minicard?

I'm not sure what the machine's exact configuration is because I
inherited it (the usual long cycle of passing older and older hardware around at work), but I believe it must; I certainly don't have anything plugged into any external slots or sockets.

- cks

#10 lore raw
Quoted 15 lines · Chris Siebenmann
| > | When are you attempting to scan?  Is anything like wpa_supplicant
| > | or NetworkManager running in the background when you do this?
| >
| >  My primary results are from Fedora 11's GNOME GUI (boot machine,
| > log in, attempt to connect to one of our wireless networks in
| > various places); I believe that this uses NetworkManager. I tried
| > with iwlist now and got the same results, but it looks like
| > wpa_supplicant and NetworkManager were both running at the time
| > based on pstree output.
|
| Ok, that should be fine since wpa_supplicant is the only thing hitting
| the airo up for scans and whatnot.  I'm grabbing a kernel now to do
| some testing with my 350 (PCMCIA).  I assume you have an internal
| minicard?
Quoted 4 lines

I'm not sure what the machine's exact configuration is because I
inherited it (the usual long cycle of passing older and older hardware around at work), but I believe it must; I certainly don't have anything plugged into any external slots or sockets.

And just to confirm, what are the exact symptoms that you have with "broken" kernels? Just that connections can't be made, the card can't find access points, etc? or?

Dan

#11 lore raw
| >  I'm not sure what the machine's exact configuration is because
| > I inherited it (the usual long cycle of passing older and older
| > hardware around at work), but I believe it must; I certainly don't
| > have anything plugged into any external slots or sockets.
|
| And just to confirm, what are the exact symptoms that you have with
| "broken" kernels?  Just that connections can't be made, the card can't
| find access points, etc? or?

In the GUI, no wireless networks show up/are listed in the usual
dropdown menu; this means that I can't go as far as even trying to connect to anything. From the command line, 'iwlist wifi0 scanning' lists nothing.

- cks

#12 lore raw
Quoted 9 lines · Chris Siebenmann
| >  I'm not sure what the machine's exact configuration is because
| > I inherited it (the usual long cycle of passing older and older
| > hardware around at work), but I believe it must; I certainly don't
| > have anything plugged into any external slots or sockets.
|
| And just to confirm, what are the exact symptoms that you have with
| "broken" kernels?  Just that connections can't be made, the card can't
| find access points, etc? or?
Quoted 4 lines

In the GUI, no wireless networks show up/are listed in the usual
dropdown menu; this means that I can't go as far as even trying to connect to anything. From the command line, 'iwlist wifi0 scanning' lists nothing.

Wait, wifi0? You need to be using 'eth0' or 'eth1', whichever eth device that 'iwconfig' reports. wifi0 is a historical airo anomaly that's only used for packet capture and sniffing of the 802.11 frames. It should not be used for anything other than Wireshark basically.

Do you get the same behavior if you use the normal ethX interface of the airo device?

Dan

#13 lore raw
Quoted 15 lines · Dan Williams
Quoted 9 lines · Chris Siebenmann
| >  I'm not sure what the machine's exact configuration is because
| > I inherited it (the usual long cycle of passing older and older
| > hardware around at work), but I believe it must; I certainly don't
| > have anything plugged into any external slots or sockets.
|
| And just to confirm, what are the exact symptoms that you have with
| "broken" kernels?  Just that connections can't be made, the card can't
| find access points, etc? or?
Quoted 4 lines

In the GUI, no wireless networks show up/are listed in the usual
dropdown menu; this means that I can't go as far as even trying to connect to anything. From the command line, 'iwlist wifi0 scanning' lists nothing.

Quoted 7 lines

Wait, wifi0? You need to be using 'eth0' or 'eth1', whichever eth device that 'iwconfig' reports. wifi0 is a historical airo anomaly that's only used for packet capture and sniffing of the 802.11 frames. It should not be used for anything other than Wireshark basically.

Do you get the same behavior if you use the normal ethX interface of the airo device?

Note that just because wifi0 may return scan results doesn't mean it should be used with iwconfig...

But also, you're doing the iwlist scan as root, correct?

Dan

#14 lore raw
In reply to Dan Williams
| >  In the GUI, no wireless networks show up/are listed in the usual
| > dropdown menu; this means that I can't go as far as even trying to
| > connect to anything.  From the command line, 'iwlist wifi0 scanning'
| > lists nothing.
|
| Wait, wifi0?  You need to be using 'eth0' or 'eth1', whichever eth
| device that 'iwconfig' reports. wifi0 is a historical airo anomaly
| that's only used for packet capture and sniffing of the 802.11 frames.
| It should not be used for anything other than Wireshark basically.
|
| Do you get the same behavior if you use the normal ethX interface of
| the airo device?

Yes; on a 'bad' kernel, 'iwlist eth1 scanning' lists nothing, and on a
good kernel it lists the networks that I expect (with some variability; where I have the machine at the moment is on the edge of visibility for some networks, and they appear and disappear periodically).

| Note that just because wifi0 may return scan results doesn't mean it
| should be used with iwconfig...
|
| But also, you're doing the iwlist scan as root, correct?

Yes (on both the good and the bad kernels).

I haven't been trying to use iwconfig for anything; all of my actual
use of the wireless networks has been done through the Fedora 11 GUI.

- cks

#15 lore raw
Quoted 23 lines · Chris Siebenmann
| >  In the GUI, no wireless networks show up/are listed in the usual
| > dropdown menu; this means that I can't go as far as even trying to
| > connect to anything.  From the command line, 'iwlist wifi0 scanning'
| > lists nothing.
|
| Wait, wifi0?  You need to be using 'eth0' or 'eth1', whichever eth
| device that 'iwconfig' reports. wifi0 is a historical airo anomaly
| that's only used for packet capture and sniffing of the 802.11 frames.
| It should not be used for anything other than Wireshark basically.
|
| Do you get the same behavior if you use the normal ethX interface of
| the airo device?

Yes; on a 'bad' kernel, 'iwlist eth1 scanning' lists nothing, and on a
good kernel it lists the networks that I expect (with some variability; where I have the machine at the moment is on the edge of visibility for some networks, and they appear and disappear periodically).

| Note that just because wifi0 may return scan results doesn't mean it
| should be used with iwconfig...
|
| But also, you're doing the iwlist scan as root, correct?
Quoted 4 lines

Yes (on both the good and the bad kernels).

I haven't been trying to use iwconfig for anything; all of my actual
use of the wireless networks has been done through the Fedora 11 GUI.

I've been able to reproduce the issue with my 350. Note that even with the original patch, the 350 will never return a scan result *other* than the associated AP. If you turn off the AP, the airo will not return any scan results even though before it connected to the AP it would return a bunch.

Airo firmware is, well, old and crappy, and nobody ever got enough documentation out of Cisco to get the driver working extremely well.

But oddly enough, the patch does fix the issue, though I have a slightly modified version that I'd rather be applied (see other mails).

Dan

#16 lore raw
In reply to Dan Williams
Quoted 9 lines · Dan Williams
Quoted 5 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

What problem/regression does this actually fix? set_wep_key() should never be called with zero-length key,

There was one case where set_wep_key() was called instead of set_wep_tx_idx().

Quoted 3 lines

so we should actually be returning
from that function instead of using WARN_ON() which would allow a zero-length key to be set (which isn't really valid).

Ok, changing that in v2 patch.

Cheers
Stanislaw

#17 lore raw

PATCH v2 1/1 airo: fix setting zero length WEP key

In reply to Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

v1->v2
Return instantly from set_wep_key() when keylen == 0.

---
 drivers/net/wireless/airo.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)
drivers/net/wireless/airo.c +18 -15
index 4331d67..01bffc2 100644
@@ -5254,11 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	if (keylen == 0) {
-		airo_print_err(ai->dev->name, "%s: key length to set was zero",
-			       __func__);
+	if (WARN_ON(keylen == 0))
 		return -1;
-	}
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
@@ -6405,11 +6402,7 @@ static int airo_set_encode(struct net_device *dev,
 		if (dwrq->length > MIN_KEY_SIZE)
 			key.len = MAX_KEY_SIZE;
 		else
-			if (dwrq->length > 0)
-				key.len = MIN_KEY_SIZE;
-			else
-				/* Disable the key */
-				key.len = 0;
+			key.len = MIN_KEY_SIZE;
 		/* Check if the key is not marked as invalid */
 		if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
 			/* Cleanup */
@@ -6590,12 +6583,22 @@ static int airo_set_encodeext(struct net_device *dev,
 		default:
 			return -EINVAL;
 		}
-		/* Send the key to the card */
-		rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
-		if (rc < 0) {
-			airo_print_err(local->dev->name, "failed to set WEP key"
-			               " at index %d: %d.", idx, rc);
-			return rc;
+		if (key.len == 0) {
+			rc = set_wep_tx_idx(local, idx, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP transmit index to %d: %d.",
+					       idx, rc);
+				return rc;
+			}
+		} else {
+			rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP key at index %d: %d.",
+					       idx, rc);
+				return rc;
+			}
 		}
 	}
 
Signature · 1 line
1.6.2.5
Tested-by on v2 1/1
#18 lore raw
| Patch prevents call set_wep_key() with zero key length. That fix long
| standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a
| "airo: clean up WEP key operations". Additionally print call trace when
| someone will try to use improper parameters, and remove key.len = 0
| assignment, because it is in not possible code path.
| 
| v1->v2
| Return instantly from set_wep_key() when keylen == 0.
| 
| Reported-and-bisected-by: Chris Siebenmann <[email protected]>
| Cc: Dan Williams <[email protected]>
| Cc: <[email protected]>
| Signed-off-by: Stanislaw Gruszka <[email protected]>

(Tested on a Thinkpad T42, using current git tip + this patch; HEAD is ab658321f32770b903a4426e2a6fae0392757755. This is the same machine I bisected the problem on.)

- cks

#19 lore raw
In reply to Stanislaw Gruszka
Quoted 5 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

Could you send the hunk that touches airo_set_encode() separately please? That's obviously correct and an easy ack, but isn't really related to the other hunks here.

Thanks,
Dan

Quoted 70 lines

v1->v2
Return instantly from set_wep_key() when keylen == 0.

---
 drivers/net/wireless/airo.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)
drivers/net/wireless/airo.c +18 -15
index 4331d67..01bffc2 100644
@@ -5254,11 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	if (keylen == 0) {
-		airo_print_err(ai->dev->name, "%s: key length to set was zero",
-			       __func__);
+	if (WARN_ON(keylen == 0))
 		return -1;
-	}
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
@@ -6405,11 +6402,7 @@ static int airo_set_encode(struct net_device *dev,
 		if (dwrq->length > MIN_KEY_SIZE)
 			key.len = MAX_KEY_SIZE;
 		else
-			if (dwrq->length > 0)
-				key.len = MIN_KEY_SIZE;
-			else
-				/* Disable the key */
-				key.len = 0;
+			key.len = MIN_KEY_SIZE;
 		/* Check if the key is not marked as invalid */
 		if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
 			/* Cleanup */
@@ -6590,12 +6583,22 @@ static int airo_set_encodeext(struct net_device *dev,
 		default:
 			return -EINVAL;
 		}
-		/* Send the key to the card */
-		rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
-		if (rc < 0) {
-			airo_print_err(local->dev->name, "failed to set WEP key"
-			               " at index %d: %d.", idx, rc);
-			return rc;
+		if (key.len == 0) {
+			rc = set_wep_tx_idx(local, idx, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP transmit index to %d: %d.",
+					       idx, rc);
+				return rc;
+			}
+		} else {
+			rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP key at index %d: %d.",
+					       idx, rc);
+				return rc;
+			}
 		}
 	}
 
#20 lore raw
Quoted 10 lines · Dan Williams
Quoted 5 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

Could you send the hunk that touches airo_set_encode() separately please? That's obviously correct and an easy ack, but isn't really related to the other hunks here.

I'm confused by your further patch, I'm deferring fixing this to you :)

Stanislaw

#21 lore raw
In reply to Stanislaw Gruszka

John, can we revert the patch you applied, and apply the following patch instead (in the next mail)? I'd rather use the one I'm about to send because it makes it clearer *why* setting the TX key index is required, and it limits that case to only the time when it's necessary. Pending the testing by Chris, I'd rather have the revised version committed instead.

Thanks,
Dan

#22 lore raw

PATCH 1/1 airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

The firmware apparently needs the WEP key RID touched when turning WEP off, otherwise it gets angry and refuses to return scan results. The firmware doesn't handle zero-length WEP keys so quite the warning message that was inadvertently printed when disabling WEP, which wpa_supplicant could trigger repeatedly.

---

drivers/net/wireless/airo.c +14 -10
index 4331d67..38902c7 100644
@@ -5254,11 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	if (keylen == 0) {
-		airo_print_err(ai->dev->name, "%s: key length to set was zero",
-			       __func__);
+	if (WARN_ON (keylen == 0))
 		return -1;
-	}
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
@@ -6532,7 +6529,7 @@ static int airo_set_encodeext(struct net_device *dev,
 	struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
 	int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
 	__le16 currentAuthType = local->config.authType;
-	int idx, key_len, alg = ext->alg, set_key = 1, rc;
+	int idx, key_len, alg = ext->alg, rc;
 	wep_key_t key;
 
 	if (!local->wep_capable)
@@ -6566,10 +6563,9 @@ static int airo_set_encodeext(struct net_device *dev,
 			               idx, rc);
 			return rc;
 		}
-		set_key = ext->key_len > 0 ? 1 : 0;
 	}
 
-	if (set_key) {
+	if (ext->key_len > 0) {
 		/* Set the requested key first */
 		memset(key.key, 0, MAX_KEY_SIZE);
 		switch (alg) {
@@ -6600,12 +6596,20 @@ static int airo_set_encodeext(struct net_device *dev,
 	}
 
 	/* Read the flags */
-	if(encoding->flags & IW_ENCODE_DISABLED)
+	if (encoding->flags & IW_ENCODE_DISABLED) {
+		/* The firmware seems to need the WEP key RID touched when
+		 * setting WEP disabled; resetting the transmit key index to 0
+		 * is good enough.  Otherwise it gets confused and stops
+		 * delivering scan results (!).
+		 */
+		if (!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
+			set_wep_tx_idx(local, 0, 0, 1);
 		local->config.authType = AUTH_OPEN;	// disable encryption
-	if(encoding->flags & IW_ENCODE_RESTRICTED)
+	} else if (encoding->flags & IW_ENCODE_RESTRICTED)
 		local->config.authType = AUTH_SHAREDKEY;	// Only Both
-	if(encoding->flags & IW_ENCODE_OPEN)
+	else if (encoding->flags & IW_ENCODE_OPEN)
 		local->config.authType = AUTH_ENCRYPT;	// Only Wep
+
 	/* Commit the changes to flags if needed */
 	if (local->config.authType != currentAuthType)
 		set_bit (FLAG_COMMIT, &local->flags);
#23 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

| The firmware apparently needs the WEP key RID touched when turning
| WEP off, otherwise it gets angry and refuses to return scan results.
| The firmware doesn't handle zero-length WEP keys so quite the warning
| message that was inadvertently printed when disabling WEP, which
| wpa_supplicant could trigger repeatedly.
|
| Signed-off-by: Dan Williams <[email protected]>

This patch does *not* work for me; with it applied to the 2.6.33-rc6
from-git that I have been using as the testing basis, the resulting kernel does not see any wireless networks. dmesg has multiple reports of:

	airo(eth1): cmd:103 status:7f03 rsp0:0 rsp1:ff10 rsp2:c0f0
	airo(eth1): cmd:103 status:7f03 rsp0:0 rsp1:ff10 rsp2:c0f0

	- cks
#24 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

Quoted 11 lines · Chris Siebenmann
| The firmware apparently needs the WEP key RID touched when turning
| WEP off, otherwise it gets angry and refuses to return scan results.
| The firmware doesn't handle zero-length WEP keys so quite the warning
| message that was inadvertently printed when disabling WEP, which
| wpa_supplicant could trigger repeatedly.
|
| Signed-off-by: Dan Williams <[email protected]>

This patch does *not* work for me; with it applied to the 2.6.33-rc6
from-git that I have been using as the testing basis, the resulting kernel does not see any wireless networks. dmesg has multiple reports

Yes, I know it may have worked in earlier kernels. And we should find out why that is, and hopefully fix the regression if any. But understand that airo has always been problematic and has never worked as well as other fullmac cards like orinoco.

I booted up RHEL5 today, which uses a 2.6.18 kernel and of course does not have the patch-in-question. That behavior is:

1) stop NetworkManager and wpa_supplicant
2) insert airo card
3) iwlist scan returns many results
4) connect to WEP-enabled AP
5) iwlist scan returns *only* the connected ap
6) iwconfig eth1 essid any key off
7) iwlist scan returns no results

remember, that's without any of the patches we're talking about, using a kernel from 2007. Which is about the same behavior you get, correct?

Quoted 4 lines

of:

	airo(eth1): cmd:103 status:7f03 rsp0:0 rsp1:ff10 rsp2:c0f0
	airo(eth1): cmd:103 status:7f03 rsp0:0 rsp1:ff10 rsp2:c0f0

CMD 0x0103 is the LISTBSS command, which is sent to trigger a scan. What firmware version do you have? It should get printed out in 'dmesg' when loading the driver.

Dan

#25 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

| Yes, I know it may have worked in earlier kernels.  And we should find
| out why that is, and hopefully fix the regression if any.  But
| understand that airo has always been problematic and has never worked as
| well as other fullmac cards like orinoco.
| 
| I booted up RHEL5 today, which uses a 2.6.18 kernel and of course does
| not have the patch-in-question.  That behavior is:
| 
| 1) stop NetworkManager and wpa_supplicant
| 2) insert airo card
| 3) iwlist scan returns many results
| 4) connect to WEP-enabled AP
| 5) iwlist scan returns *only* the connected ap
| 6) iwconfig eth1 essid any key off
| 7) iwlist scan returns no results
| 
| remember, that's without any of the patches we're talking about, using a
| kernel from 2007.  Which is about the same behavior you get, correct?

I don't get quite this behavior, although I'm not doing exactly these
steps; instead, I do:
- boot machine
- use 'iwlist scan' and see multiple APs
- use NetworkManager to connect to our WEP-enabled AP
- 'iwlist scan' returns only the single AP
- turn things off with:
iwconfig eth1 essid ANY key off
- 'iwconfig eth1' and NetworkManager both show no connected AP
- 'iwlist scan' returns only the ex-connected AP

(I do not know the right commands to connect to our WEP-enabled AP and verify that everything is working right without using NetworkManager, so I used it for the connection phase.)

- cks

#26 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

Quoted 19 lines · Chris Siebenmann
| Yes, I know it may have worked in earlier kernels.  And we should find
| out why that is, and hopefully fix the regression if any.  But
| understand that airo has always been problematic and has never worked as
| well as other fullmac cards like orinoco.
| 
| I booted up RHEL5 today, which uses a 2.6.18 kernel and of course does
| not have the patch-in-question.  That behavior is:
| 
| 1) stop NetworkManager and wpa_supplicant
| 2) insert airo card
| 3) iwlist scan returns many results
| 4) connect to WEP-enabled AP
| 5) iwlist scan returns *only* the connected ap
| 6) iwconfig eth1 essid any key off
| 7) iwlist scan returns no results
| 
| remember, that's without any of the patches we're talking about, using a
| kernel from 2007.  Which is about the same behavior you get, correct?
Quoted 10 lines

I don't get quite this behavior, although I'm not doing exactly these
steps; instead, I do:
- boot machine
- use 'iwlist scan' and see multiple APs
- use NetworkManager to connect to our WEP-enabled AP
- 'iwlist scan' returns only the single AP
- turn things off with:
iwconfig eth1 essid ANY key off
- 'iwconfig eth1' and NetworkManager both show no connected AP
- 'iwlist scan' returns only the ex-connected AP

These are the results you get on the older kernel without the commit we're all talking about here?

Quoted 3 lines

(I do not know the right commands to connect to our WEP-enabled AP and verify that everything is working right without using NetworkManager, so I used it for the connection phase.)

iwconfig ethX essid 'foobar' key <your hex wep key>

Then run 'iwconfig ethX' over and over until you see a valid AP BSSID listed in the result, and then you can run 'dhclient -1 -v -d ethX' to try and DHCP.

Also, what firmware version do you have?

Dan

#27 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

So that I don't forget this again:
| Also, what firmware version do you have?

The driver reports:
airo(): Probing for PCI adapters
airo 0000:02:02.0: PCI INT A -> Link[LNKC] -> GSI 11 (level, low) -> IRQ 11 airo(): Found an MPI350 card
airo(eth1): Firmware version 5.41.00
airo(eth1): WPA supported.
airo(eth1): MAC enabled 00:0e:9b:90:af:29

- cks

#28 lore raw

Re: [PATCH] airo: fix WEP key clearing after c0380693520b1a1e4f756799a0edc379378b462a

In reply to Dan Williams
| >  I don't get quite this behavior, although I'm not doing exactly these
| > steps; instead, I do:
| > 	- boot machine
| > 	- use 'iwlist scan' and see multiple APs
| > 	- use NetworkManager to connect to our WEP-enabled AP
| > 	- 'iwlist scan' returns only the single AP
| > 	- turn things off with:
| > 		iwconfig eth1 essid ANY key off
| > 	- 'iwconfig eth1' and NetworkManager both show no connected AP
| > 	- 'iwlist scan' returns only the ex-connected AP
| 
| These are the results you get on the older kernel without the commit
| we're all talking about here?

I have been testing on the kernel with working wireless,
specifically Fedora 11's 2.6.29.6-217.2.8.fc11 kernel.

I have to amend my testing results, however. I have now managed to get
the network live with iwconfig, not NetworkManager, and when I do this and do 'iwconfig eth1 essid ANY key off', I actually see *multiple* APs with 'iwlist scan' if I catch it at the right time. (In fact, I sometimes associate with an unprotected network in range.)

(There is only one good network in range, which is ours, but I'm on the edge of a number that sometimes show up in normal scan output and sometimes don't.)

So this doesn't match the behavior you were seeing with your old kernel
and machine.

- cks

#29 lore raw
In reply to Dan Williams
Quoted 6 lines · Dan Williams

John, can we revert the patch you applied, and apply the following patch instead (in the next mail)? I'd rather use the one I'm about to send because it makes it clearer *why* setting the TX key index is required, and it limits that case to only the time when it's necessary. Pending the testing by Chris, I'd rather have the revised version committed instead.

Do you still want this don, even after Chris's testing says your patch doesn't work? I wasn't sure from your response.

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#30 lore raw
Quoted 10 lines · John W. Linville
Quoted 6 lines · Dan Williams

John, can we revert the patch you applied, and apply the following patch instead (in the next mail)? I'd rather use the one I'm about to send because it makes it clearer *why* setting the TX key index is required, and it limits that case to only the time when it's necessary. Pending the testing by Chris, I'd rather have the revised version committed instead.

Do you still want this don, even after Chris's testing says your patch doesn't work? I wasn't sure from your response.

Not yet, no. I'd like to work out the issue first, if we can.

Thanks,
Dan

#31 lore raw
In reply to Stanislaw Gruszka
Quoted 6 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

Quoted 7 lines

v1->v2
Return instantly from set_wep_key() when keylen == 0.

Stanislaw, your original patch was already committed in wireless-next-2.6. Could you send a second patch with just your v1->v2 change?

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#32 lore raw

PATCH 1/1 airo: return from set_wep_key() when key length is zero

Even if keylen == 0 is a bug and should not really happen, better avoid possibility of passing bad value to firmware.

---
 drivers/net/wireless/airo.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/wireless/airo.c +2 -1
index 2a9f029..01bffc2 100644
@@ -5254,7 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	WARN_ON(keylen == 0);
+	if (WARN_ON(keylen == 0))
+		return -1;
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
Signature · 1 line
1.6.2.5
#33 lore raw

PATCH RESEND 1/1 airo: return from set_wep_key() when key length is zero

In reply to John W. Linville

Even if keylen == 0 is a bug and should not really happen, better avoid possibility of passing bad value to firmware.

---
 drivers/net/wireless/airo.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/wireless/airo.c +2 -1
index 2a9f029..01bffc2 100644
@@ -5254,7 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	WARN_ON(keylen == 0);
+	if (WARN_ON(keylen == 0))
+		return -1;
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
Signature · 1 line
1.6.2.5
#34 lore raw

Re: [PATCH resend] airo: return from set_wep_key() when key length is zero

Quoted 4 lines · Stanislaw Gruszka

Even if keylen == 0 is a bug and should not really happen, better avoid possibility of passing bad value to firmware.

I actually told John to just apply your first patch via IRC, but perhaps he hasn't done that yet. I cannot reproduce the issue that Chris encountered with my PCMCIA 350 using 5.60 firmware, and I bricked my card loading 5.40 firmware (same as Chris) onto it.

I couldn't find any failures your original patch on my 5.60 device, my objections were simply code flow and semantics. So I'll ack the original patch.

Dan

Quoted 18 lines
---
 drivers/net/wireless/airo.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/wireless/airo.c +2 -1
index 2a9f029..01bffc2 100644
@@ -5254,7 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	WARN_ON(keylen == 0);
+	if (WARN_ON(keylen == 0))
+		return -1;
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
Tested-by Chris Siebenmann
#35 lore raw

Re: [PATCH resend] airo: return from set_wep_key() when key length is zero

Quoted 6 lines · Dan Williams
Quoted 4 lines · Stanislaw Gruszka

Even if keylen == 0 is a bug and should not really happen, better avoid possibility of passing bad value to firmware.

Quoted 8 lines

I actually told John to just apply your first patch via IRC, but perhaps he hasn't done that yet. I cannot reproduce the issue that Chris encountered with my PCMCIA 350 using 5.60 firmware, and I bricked my card loading 5.40 firmware (same as Chris) onto it.

I couldn't find any failures your original patch on my 5.60 device, my objections were simply code flow and semantics. So I'll ack the original patch.

commit f09c256375c7cf1e112b8ef6306cdd313490d7c0

Author: Stanislaw Gruszka <[email protected]>
Date:   Tue Feb 2 15:34:50 2010 +0100

airo: fix setting zero length WEP key

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

Hth...

John

Signature · 2 lines
John W. Linville                Someday the world will need a hero, and you
[email protected]                  might be all we have.  Be ready.
#36 lore raw

Re: [PATCH resend] airo: return from set_wep_key() when key length is zero

Quoted 6 lines · John W. Linville
Quoted 5 lines · Dan Williams
Quoted 4 lines · Stanislaw Gruszka

Even if keylen == 0 is a bug and should not really happen, better avoid possibility of passing bad value to firmware.

This is small v1->v2 patch on top of below commit. You asked for it :)

Quoted 5 lines

commit f09c256375c7cf1e112b8ef6306cdd313490d7c0

Author: Stanislaw Gruszka <[email protected]>
Date:   Tue Feb 2 15:34:50 2010 +0100

airo: fix setting zero length WEP key

Stanislaw

Acked-by on v2 1/1
#37 lore raw
In reply to Stanislaw Gruszka
Quoted 6 lines · Stanislaw Gruszka

Patch prevents call set_wep_key() with zero key length. That fix long standing regression since commit c0380693520b1a1e4f756799a0edc379378b462a "airo: clean up WEP key operations". Additionally print call trace when someone will try to use improper parameters, and remove key.len = 0 assignment, because it is in not possible code path.

Quoted 7 lines

v1->v2
Return instantly from set_wep_key() when keylen == 0.

Quoted 63 lines
---
 drivers/net/wireless/airo.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)
drivers/net/wireless/airo.c +18 -15
index 4331d67..01bffc2 100644
@@ -5254,11 +5254,8 @@ static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
 	WepKeyRid wkr;
 	int rc;
 
-	if (keylen == 0) {
-		airo_print_err(ai->dev->name, "%s: key length to set was zero",
-			       __func__);
+	if (WARN_ON(keylen == 0))
 		return -1;
-	}
 
 	memset(&wkr, 0, sizeof(wkr));
 	wkr.len = cpu_to_le16(sizeof(wkr));
@@ -6405,11 +6402,7 @@ static int airo_set_encode(struct net_device *dev,
 		if (dwrq->length > MIN_KEY_SIZE)
 			key.len = MAX_KEY_SIZE;
 		else
-			if (dwrq->length > 0)
-				key.len = MIN_KEY_SIZE;
-			else
-				/* Disable the key */
-				key.len = 0;
+			key.len = MIN_KEY_SIZE;
 		/* Check if the key is not marked as invalid */
 		if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
 			/* Cleanup */
@@ -6590,12 +6583,22 @@ static int airo_set_encodeext(struct net_device *dev,
 		default:
 			return -EINVAL;
 		}
-		/* Send the key to the card */
-		rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
-		if (rc < 0) {
-			airo_print_err(local->dev->name, "failed to set WEP key"
-			               " at index %d: %d.", idx, rc);
-			return rc;
+		if (key.len == 0) {
+			rc = set_wep_tx_idx(local, idx, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP transmit index to %d: %d.",
+					       idx, rc);
+				return rc;
+			}
+		} else {
+			rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
+			if (rc < 0) {
+				airo_print_err(local->dev->name,
+					       "failed to set WEP key at index %d: %d.",
+					       idx, rc);
+				return rc;
+			}
 		}
 	}