netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]d80211: fix "iwconfig key [x]" behavior
@ 2006-08-28  8:36 Hong Liu
  2006-08-30 17:24 ` Jiri Benc
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Liu @ 2006-08-28  8:36 UTC (permalink / raw)
  To: jbenc; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

"iwconfig key [x]" behavior is not correctly handled in the stack, also
modify the giwencode method to show the key info.

Thanks,
Hong

[-- Attachment #2: d80211-fix-iwconfig-key.patch --]
[-- Type: text/x-patch, Size: 1861 bytes --]

[PATCH]d80211: fix "iwconfig key [x]" behavior

Signed-off-by: Hong Liu <hong.liu@intel.com>

diff --git a/net/d80211/ieee80211_ioctl.c b/net/d80211/ieee80211_ioctl.c
index dd52555..d3dc59c 100644
--- a/net/d80211/ieee80211_ioctl.c
+++ b/net/d80211/ieee80211_ioctl.c
@@ -2811,9 +2811,10 @@ static int ieee80211_ioctl_siwencode(str
 		if (sdata->default_key == NULL)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2824,16 +2825,22 @@ static int ieee80211_ioctl_siwencode(str
 		alg = ALG_NONE;
 	else if (erq->length == 0) {
 		/* No key data - just set the default TX key index */
-		sdata->default_key = sdata->keys[idx];
+		if (sdata->default_key != sdata->keys[idx]) {
+			if (sdata->default_key)
+				ieee80211_key_sysfs_remove_default(sdata);
+			sdata->default_key = sdata->keys[idx];
+			if (sdata->default_key)
+				ieee80211_key_sysfs_add_default(sdata);
+		}
+		return 0;
 	}
 
 	return ieee80211_set_encryption(
 		dev, bcaddr,
-		idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
+		idx, alg,
 		sdata->default_key == NULL,
 		NULL, keybuf, erq->length);
 
-	return 0;
 }
 
 
@@ -2852,9 +2859,10 @@ static int ieee80211_ioctl_giwencode(str
 		if (sdata->default_key == NULL)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2869,7 +2877,8 @@ static int ieee80211_ioctl_giwencode(str
 		return 0;
 	}
 
-	erq->length = 0;
+	erq->length = sdata->keys[idx]->keylen;
+	memcpy(key, sdata->keys[idx]->key, erq->length);
 	erq->flags |= IW_ENCODE_ENABLED;
 
 	return 0;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH]d80211: fix "iwconfig key [x]" behavior
  2006-08-28  8:36 [PATCH]d80211: fix "iwconfig key [x]" behavior Hong Liu
@ 2006-08-30 17:24 ` Jiri Benc
  2006-09-01  3:37   ` Hong Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Benc @ 2006-08-30 17:24 UTC (permalink / raw)
  To: Hong Liu; +Cc: netdev, John W. Linville

On Mon, 28 Aug 2006 16:36:39 +0800, Hong Liu wrote:
> "iwconfig key [x]" behavior is not correctly handled in the stack, also
> modify the giwencode method to show the key info.

Thanks for spotting and fixing these bugs!

> @@ -2869,7 +2877,8 @@ static int ieee80211_ioctl_giwencode(str
>  		return 0;
>  	}
>  
> -	erq->length = 0;
> +	erq->length = sdata->keys[idx]->keylen;
> +	memcpy(key, sdata->keys[idx]->key, erq->length);

Shouldn't there be a check for buffer size here?

Thanks,

 Jiri

-- 
Jiri Benc
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH]d80211: fix "iwconfig key [x]" behavior
  2006-08-30 17:24 ` Jiri Benc
@ 2006-09-01  3:37   ` Hong Liu
  2006-09-21 15:51     ` Jiri Benc
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Liu @ 2006-09-01  3:37 UTC (permalink / raw)
  To: Jiri Benc; +Cc: netdev, John W. Linville

On Thu, 2006-08-31 at 01:24, Jiri Benc wrote:
> On Mon, 28 Aug 2006 16:36:39 +0800, Hong Liu wrote:
> > "iwconfig key [x]" behavior is not correctly handled in the stack, also
> > modify the giwencode method to show the key info.
> 
> Thanks for spotting and fixing these bugs!
> 
> > @@ -2869,7 +2877,8 @@ static int ieee80211_ioctl_giwencode(str
> >               return 0;
> >       }
> > 
> > -     erq->length = 0;
> > +     erq->length = sdata->keys[idx]->keylen;
> > +     memcpy(key, sdata->keys[idx]->key, erq->length);
> 
> Shouldn't there be a check for buffer size here?
> 
> Thanks,
> 
>  Jiri
> 
> --
> Jiri Benc
> SUSE Labs
> 
> 

Signed-off-by: Hong Liu <hong.liu@intel.com>

diff --git a/net/d80211/ieee80211_ioctl.c b/net/d80211/ieee80211_ioctl.c
index 89a58e3..c9a3524 100644
--- a/net/d80211/ieee80211_ioctl.c
+++ b/net/d80211/ieee80211_ioctl.c
@@ -2867,9 +2867,10 @@ static int ieee80211_ioctl_siwencode(str
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2880,16 +2881,21 @@ static int ieee80211_ioctl_siwencode(str
 		alg = ALG_NONE;
 	else if (erq->length == 0) {
 		/* No key data - just set the default TX key index */
-		sdata->default_key = sdata->keys[idx];
+		if (sdata->default_key != sdata->keys[idx]) {
+			if (sdata->default_key)
+				ieee80211_key_sysfs_remove_default(sdata);
+			sdata->default_key = sdata->keys[idx];
+			if (sdata->default_key)
+				ieee80211_key_sysfs_add_default(sdata);
+		}
+		return 0;
 	}
 
 	return ieee80211_set_encryption(
 		dev, bcaddr,
-		idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
+		idx, alg,
 		!sdata->default_key,
 		NULL, keybuf, erq->length);
-
-	return 0;
 }
 
 
@@ -2908,9 +2914,10 @@ static int ieee80211_ioctl_giwencode(str
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2925,7 +2932,8 @@ static int ieee80211_ioctl_giwencode(str
 		return 0;
 	}
 
-	erq->length = 0;
+	erq->length = min((int)erq->length, sdata->keys[idx]->keylen);
+	memcpy(key, sdata->keys[idx]->key, erq->length);
 	erq->flags |= IW_ENCODE_ENABLED;
 
 	return 0;
@@ -3054,9 +3062,10 @@ static int ieee80211_ioctl_siwencodeext(
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH]d80211: fix "iwconfig key [x]" behavior
  2006-09-01  3:37   ` Hong Liu
@ 2006-09-21 15:51     ` Jiri Benc
  2006-09-22  7:56       ` Hong Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Jiri Benc @ 2006-09-21 15:51 UTC (permalink / raw)
  To: Hong Liu; +Cc: netdev, John W. Linville

Hi,

sorry for the delay.

On Fri, 01 Sep 2006 11:37:57 +0800, Hong Liu wrote:
> @@ -2925,7 +2932,8 @@ static int ieee80211_ioctl_giwencode(str
>  		return 0;
>  	}
>  
> -	erq->length = 0;
> +	erq->length = min((int)erq->length, sdata->keys[idx]->keylen);
> +	memcpy(key, sdata->keys[idx]->key, erq->length);
>  	erq->flags |= IW_ENCODE_ENABLED;
>  
>  	return 0;

This is still not correct, erq->length should be set to the actual key
length to allow WE to return -E2BIG in case of too small buffer.

	memcpy(key, sdata->keys[idx]->key,
	       min((int)erq->length, sdata->keys[idx]->keylen));
	erq->length = sdata->keys[idx]->keylen;

 Jiri

-- 
Jiri Benc
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH]d80211: fix "iwconfig key [x]" behavior
  2006-09-21 15:51     ` Jiri Benc
@ 2006-09-22  7:56       ` Hong Liu
  2006-09-22 12:00         ` Jiri Benc
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Liu @ 2006-09-22  7:56 UTC (permalink / raw)
  To: Jiri Benc; +Cc: netdev, John W. Linville

On Thu, 2006-09-21 at 23:51, Jiri Benc wrote:
> Hi,
> 
> sorry for the delay.
> 
> On Fri, 01 Sep 2006 11:37:57 +0800, Hong Liu wrote:
> > @@ -2925,7 +2932,8 @@ static int ieee80211_ioctl_giwencode(str
> >  		return 0;
> >  	}
> >  
> > -	erq->length = 0;
> > +	erq->length = min((int)erq->length, sdata->keys[idx]->keylen);
> > +	memcpy(key, sdata->keys[idx]->key, erq->length);
> >  	erq->flags |= IW_ENCODE_ENABLED;
> >  
> >  	return 0;
> 
> This is still not correct, erq->length should be set to the actual key
> length to allow WE to return -E2BIG in case of too small buffer.
> 
> 	memcpy(key, sdata->keys[idx]->key,
> 	       min((int)erq->length, sdata->keys[idx]->keylen));
> 	erq->length = sdata->keys[idx]->keylen;
> 
>  Jiri

Resend.

Thanks,
Hong


Signed-off-by: Hong Liu <hong.liu@intel.com>

diff --git a/net/d80211/ieee80211_ioctl.c b/net/d80211/ieee80211_ioctl.c
index 89a58e3..bde0c43 100644
--- a/net/d80211/ieee80211_ioctl.c
+++ b/net/d80211/ieee80211_ioctl.c
@@ -2867,9 +2867,10 @@ static int ieee80211_ioctl_siwencode(str
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2880,16 +2881,21 @@ static int ieee80211_ioctl_siwencode(str
 		alg = ALG_NONE;
 	else if (erq->length == 0) {
 		/* No key data - just set the default TX key index */
-		sdata->default_key = sdata->keys[idx];
+		if (sdata->default_key != sdata->keys[idx]) {
+			if (sdata->default_key)
+				ieee80211_key_sysfs_remove_default(sdata);
+			sdata->default_key = sdata->keys[idx];
+			if (sdata->default_key)
+				ieee80211_key_sysfs_add_default(sdata);
+		}
+		return 0;
 	}
 
 	return ieee80211_set_encryption(
 		dev, bcaddr,
-		idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
+		idx, alg,
 		!sdata->default_key,
 		NULL, keybuf, erq->length);
-
-	return 0;
 }
 
 
@@ -2908,9 +2914,10 @@ static int ieee80211_ioctl_giwencode(str
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;
@@ -2925,7 +2932,9 @@ static int ieee80211_ioctl_giwencode(str
 		return 0;
 	}
 
-	erq->length = 0;
+	memcpy(key, sdata->keys[idx]->key,
+	       min((int)erq->length, sdata->keys[idx]->keylen));
+	erq->length = sdata->keys[idx]->keylen;
 	erq->flags |= IW_ENCODE_ENABLED;
 
 	return 0;
@@ -3054,9 +3063,10 @@ static int ieee80211_ioctl_siwencodeext(
 		if (!sdata->default_key)
 			idx = 0;
 		else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
-			if (sdata->default_key == sdata->keys[i])
+			if (sdata->default_key == sdata->keys[i]) {
 				idx = i;
-			break;
+				break;
+			}
 		}
 		if (idx < 0)
 			return -EINVAL;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH]d80211: fix "iwconfig key [x]" behavior
  2006-09-22  7:56       ` Hong Liu
@ 2006-09-22 12:00         ` Jiri Benc
  0 siblings, 0 replies; 6+ messages in thread
From: Jiri Benc @ 2006-09-22 12:00 UTC (permalink / raw)
  To: Hong Liu; +Cc: netdev, John W. Linville

On Fri, 22 Sep 2006 15:56:26 +0800, Hong Liu wrote:
> Resend.

Applied to my tree, thanks for the patch!

 Jiri

-- 
Jiri Benc
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-09-22 12:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-28  8:36 [PATCH]d80211: fix "iwconfig key [x]" behavior Hong Liu
2006-08-30 17:24 ` Jiri Benc
2006-09-01  3:37   ` Hong Liu
2006-09-21 15:51     ` Jiri Benc
2006-09-22  7:56       ` Hong Liu
2006-09-22 12:00         ` Jiri Benc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).