2022-04-15 09:49:00

by baihaowen

[permalink] [raw]
Subject: [PATCH V3] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

The rtllib_rx_assoc_resp() function has a signedness bug because it's
a declared as a u16 but it return -ENOMEM. When you look at it more
closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.

Clean it up to just return standard kernel error codes. We can print
out the a->status before returning a regular error code. The printks
in the caller need to be adjusted as well.

Signed-off-by: Haowen Bai <[email protected]>
---
V1->V2: reduce return random value; print its own error message.
V2->V3: change commit message; change s16 -> int.

drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 82bf05eb1cbf..4a1b9a94930f 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1764,7 +1764,7 @@ static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
spin_unlock_irqrestore(&ieee->lock, flags);
}

-static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
+static inline int auth_parse(struct net_device *dev, struct sk_buff *skb,
u8 **challenge, int *chlen)
{
struct rtllib_authentication *a;
@@ -1773,7 +1773,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
if (skb->len < (sizeof(struct rtllib_authentication) -
sizeof(struct rtllib_info_element))) {
netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
- return 0xcafe;
+ return -EINVAL;
}
*challenge = NULL;
a = (struct rtllib_authentication *) skb->data;
@@ -1787,7 +1787,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
return -ENOMEM;
}
}
- return le16_to_cpu(a->status);
+ return a->status;
}

static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
@@ -2282,7 +2282,7 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,

static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
{
- u16 errcode;
+ int errcode;
u8 *challenge;
int chlen = 0;
bool bSupportNmode = true, bHalfSupportNmode = false;
@@ -2292,8 +2292,8 @@ static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
if (errcode) {
ieee->softmac_stats.rx_auth_rs_err++;
netdev_info(ieee->dev,
- "Authentication response status code 0x%x",
- errcode);
+ "Authentication response status code %d",
+ le16_to_cpu(errcode));
rtllib_associate_abort(ieee);
return;
}
--
2.7.4


2022-04-15 22:04:05

by Fabio M. De Francesco

[permalink] [raw]
Subject: Re: [PATCH V3] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

On venerd? 15 aprile 2022 08:06:17 CEST Fabio M. De Francesco wrote:
> On venerd? 15 aprile 2022 07:50:36 CEST Haowen Bai wrote:
> > The rtllib_rx_assoc_resp() function has a signedness bug because it's
> > a declared as a u16 but it return -ENOMEM. When you look at it more
> > closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
> > a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.
> >
> > Clean it up to just return standard kernel error codes. We can print
> > out the a->status before returning a regular error code. The printks
> > in the caller need to be adjusted as well.
>
> This commit message suggested by Dan Carpenter is much better. The
previous
> one made me think that you were doing several different logical changes.
>
> >
> > [snip]
> >
> > static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct
> sk_buff *skb)
> > {
> > - u16 errcode;
> > + int errcode;
> > u8 *challenge;
> > int chlen = 0;
> > bool bSupportNmode = true, bHalfSupportNmode = false;
> > @@ -2292,8 +2292,8 @@ static void rtllib_rx_auth_resp(struct
> rtllib_device *ieee, struct sk_buff *skb)
> > if (errcode) {
> > ieee->softmac_stats.rx_auth_rs_err++;
> > netdev_info(ieee->dev,
> > - "Authentication response status code
> 0x%x",
> > - errcode);
> > + "Authentication response status code %d",
> > + le16_to_cpu(errcode));
>
> This is something that I'm still missing. Why do we need that call to
> le16_to_cpu on "errcode"?
>
> "errcode" is returned by auth_parse()? I see that this function already
> changes the endianness of the returned value.

Sorry, I missed that you also changed auth_code().

Fabio

>
> Thanks,
>
> Fabio
>
>
> > rtllib_associate_abort(ieee);
> > return;
> > }
> > --
> > 2.7.4
> >
> >
> >
>
>
>
>
>




2022-04-16 00:14:45

by baihaowen

[permalink] [raw]
Subject: [PATCH V4] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

This commit message suggested by Dan Carpenter as below:

The rtllib_rx_assoc_resp() function has a signedness bug because it's
a declared as a u16 but it return -ENOMEM. When you look at it more
closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.

Clean it up to just return standard kernel error codes. We can print
out the a->status before returning a regular error code. The printks
in the caller need to be adjusted as well.

Signed-off-by: Haowen Bai <[email protected]>
---
V1->V2: reduce return random value; print its own error message.
V2->V3: change commit message; change s16 -> int.
V3->V4: add message suggested by in title.

drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 82bf05eb1cbf..4a1b9a94930f 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1764,7 +1764,7 @@ static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
spin_unlock_irqrestore(&ieee->lock, flags);
}

-static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
+static inline int auth_parse(struct net_device *dev, struct sk_buff *skb,
u8 **challenge, int *chlen)
{
struct rtllib_authentication *a;
@@ -1773,7 +1773,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
if (skb->len < (sizeof(struct rtllib_authentication) -
sizeof(struct rtllib_info_element))) {
netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
- return 0xcafe;
+ return -EINVAL;
}
*challenge = NULL;
a = (struct rtllib_authentication *) skb->data;
@@ -1787,7 +1787,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
return -ENOMEM;
}
}
- return le16_to_cpu(a->status);
+ return a->status;
}

static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest)
@@ -2282,7 +2282,7 @@ rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,

static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
{
- u16 errcode;
+ int errcode;
u8 *challenge;
int chlen = 0;
bool bSupportNmode = true, bHalfSupportNmode = false;
@@ -2292,8 +2292,8 @@ static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb)
if (errcode) {
ieee->softmac_stats.rx_auth_rs_err++;
netdev_info(ieee->dev,
- "Authentication response status code 0x%x",
- errcode);
+ "Authentication response status code %d",
+ le16_to_cpu(errcode));
rtllib_associate_abort(ieee);
return;
}
--
2.7.4

2022-04-16 01:25:36

by Fabio M. De Francesco

[permalink] [raw]
Subject: Re: [PATCH V3] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

On venerd? 15 aprile 2022 07:50:36 CEST Haowen Bai wrote:
> The rtllib_rx_assoc_resp() function has a signedness bug because it's
> a declared as a u16 but it return -ENOMEM. When you look at it more
> closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
> a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.
>
> Clean it up to just return standard kernel error codes. We can print
> out the a->status before returning a regular error code. The printks
> in the caller need to be adjusted as well.

This commit message suggested by Dan Carpenter is much better. The previous
one made me think that you were doing several different logical changes.

>
> [snip]
>
> static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct
sk_buff *skb)
> {
> - u16 errcode;
> + int errcode;
> u8 *challenge;
> int chlen = 0;
> bool bSupportNmode = true, bHalfSupportNmode = false;
> @@ -2292,8 +2292,8 @@ static void rtllib_rx_auth_resp(struct
rtllib_device *ieee, struct sk_buff *skb)
> if (errcode) {
> ieee->softmac_stats.rx_auth_rs_err++;
> netdev_info(ieee->dev,
> - "Authentication response status code
0x%x",
> - errcode);
> + "Authentication response status code %d",
> + le16_to_cpu(errcode));

This is something that I'm still missing. Why do we need that call to
le16_to_cpu on "errcode"?

"errcode" is returned by auth_parse()? I see that this function already
changes the endianness of the returned value.

Thanks,

Fabio


> rtllib_associate_abort(ieee);
> return;
> }
> --
> 2.7.4
>
>
>




2022-04-16 02:10:52

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH V4] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

On Fri, Apr 15, 2022 at 02:15:25PM +0800, Haowen Bai wrote:
> This commit message suggested by Dan Carpenter as below:
>
> The rtllib_rx_assoc_resp() function has a signedness bug because it's
> a declared as a u16 but it return -ENOMEM. When you look at it more
> closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
> a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.
>
> Clean it up to just return standard kernel error codes. We can print
> out the a->status before returning a regular error code. The printks
> in the caller need to be adjusted as well.
>
> Signed-off-by: Haowen Bai <[email protected]>
> ---
> V1->V2: reduce return random value; print its own error message.
> V2->V3: change commit message; change s16 -> int.
> V3->V4: add message suggested by in title.
>
> drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
> index 82bf05eb1cbf..4a1b9a94930f 100644
> --- a/drivers/staging/rtl8192e/rtllib_softmac.c
> +++ b/drivers/staging/rtl8192e/rtllib_softmac.c
> @@ -1764,7 +1764,7 @@ static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
> spin_unlock_irqrestore(&ieee->lock, flags);
> }
>
> -static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> +static inline int auth_parse(struct net_device *dev, struct sk_buff *skb,
> u8 **challenge, int *chlen)
> {
> struct rtllib_authentication *a;
> @@ -1773,7 +1773,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> if (skb->len < (sizeof(struct rtllib_authentication) -
> sizeof(struct rtllib_info_element))) {
> netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
> - return 0xcafe;
> + return -EINVAL;
> }
> *challenge = NULL;
> a = (struct rtllib_authentication *) skb->data;
> @@ -1787,7 +1787,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> return -ENOMEM;
> }
> }
> - return le16_to_cpu(a->status);
> + return a->status;

See previous responses.

regards,
dan carpenter

2022-04-16 02:38:16

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH V3] staging: rtl8192e: Fix signedness bug in rtllib_rx_assoc_resp()

On Fri, Apr 15, 2022 at 01:50:36PM +0800, Haowen Bai wrote:
> The rtllib_rx_assoc_resp() function has a signedness bug because it's
> a declared as a u16 but it return -ENOMEM. When you look at it more
> closely it returns a mix of error codes including 0xcafe, -ENOMEM, and
> a->status which is WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG. This is a mess.
>
> Clean it up to just return standard kernel error codes. We can print
> out the a->status before returning a regular error code. The printks
> in the caller need to be adjusted as well.
>
> Signed-off-by: Haowen Bai <[email protected]>
> ---
> V1->V2: reduce return random value; print its own error message.
> V2->V3: change commit message; change s16 -> int.
>
> drivers/staging/rtl8192e/rtllib_softmac.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
> index 82bf05eb1cbf..4a1b9a94930f 100644
> --- a/drivers/staging/rtl8192e/rtllib_softmac.c
> +++ b/drivers/staging/rtl8192e/rtllib_softmac.c
> @@ -1764,7 +1764,7 @@ static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee)
> spin_unlock_irqrestore(&ieee->lock, flags);
> }
>
> -static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> +static inline int auth_parse(struct net_device *dev, struct sk_buff *skb,
> u8 **challenge, int *chlen)
> {
> struct rtllib_authentication *a;
> @@ -1773,7 +1773,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> if (skb->len < (sizeof(struct rtllib_authentication) -
> sizeof(struct rtllib_info_element))) {
> netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len);
> - return 0xcafe;
> + return -EINVAL;
> }
> *challenge = NULL;
> a = (struct rtllib_authentication *) skb->data;
> @@ -1787,7 +1787,7 @@ static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb,
> return -ENOMEM;
> }
> }
> - return le16_to_cpu(a->status);
> + return a->status;

Please do not return a->status. See my previous email. You're sending
new versions too quickly. Wait a day between new versions.

regards,
dan carpenter