linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] wireless/nl80211.c: fix uninitialized variable
@ 2021-03-30 17:22 Alaa Emad
  2021-03-30 19:26 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Alaa Emad @ 2021-03-30 17:22 UTC (permalink / raw)
  To: johannes, davem, kuba
  Cc: gregkh, linux-wireless, netdev, linux-kernel, syzkaller,
	Alaa Emad, syzbot+72b99dcf4607e8c770f3

This change fix  KMSAN uninit-value in net/wireless/nl80211.c:225 , That
because of `fixedlen` variable uninitialized,So I initialized it by zero.

Reported-by: syzbot+72b99dcf4607e8c770f3@syzkaller.appspotmail.com
Signed-off-by: Alaa Emad <alaaemadhossney.ae@gmail.com>
---
Changes in v2:
  - Make the commit message more clearer.
---
 net/wireless/nl80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 775d0c4d86c3..b87ab67ad33d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
 	const struct element *elem;
 	const struct ieee80211_mgmt *mgmt = (void *)data;
 	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
-	unsigned int fixedlen, hdrlen;
+	unsigned int fixedlen = 0, hdrlen;
 
 	if (s1g_bcn) {
 		fixedlen = offsetof(struct ieee80211_ext,
-- 
2.25.1


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

* Re: [PATCH v2] wireless/nl80211.c: fix uninitialized variable
  2021-03-30 17:22 [PATCH v2] wireless/nl80211.c: fix uninitialized variable Alaa Emad
@ 2021-03-30 19:26 ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-03-30 19:26 UTC (permalink / raw)
  To: Alaa Emad, johannes, davem, kuba
  Cc: gregkh, linux-wireless, netdev, linux-kernel, syzkaller,
	syzbot+72b99dcf4607e8c770f3



On 3/30/21 7:22 PM, Alaa Emad wrote:
> This change fix  KMSAN uninit-value in net/wireless/nl80211.c:225 , That
> because of `fixedlen` variable uninitialized,So I initialized it by zero.
> 
> Reported-by: syzbot+72b99dcf4607e8c770f3@syzkaller.appspotmail.com
> Signed-off-by: Alaa Emad <alaaemadhossney.ae@gmail.com>
> ---
> Changes in v2:
>   - Make the commit message more clearer.
> ---
>  net/wireless/nl80211.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 775d0c4d86c3..b87ab67ad33d 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
>  	const struct element *elem;
>  	const struct ieee80211_mgmt *mgmt = (void *)data;
>  	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
> -	unsigned int fixedlen, hdrlen;
> +	unsigned int fixedlen = 0, hdrlen;
>  
>  	if (s1g_bcn) {
>  		fixedlen = offsetof(struct ieee80211_ext,
> 

What was the report exactly ?

Current code does :

unsigned int fixedlen;

if (s1g_bcn) {
    fixedlen = something1;
    ...
else {
    fixedlen = something2;
    ...
}

So your patch does nothing.

Initial value of @fixedlen is not relevant.

Reading this code (without access to KMSAN report) I suspect the issue
is more like the following :

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 775d0c4d86c3..d815261917ff 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -209,9 +209,12 @@ static int validate_beacon_head(const struct nlattr *attr,
        unsigned int len = nla_len(attr);
        const struct element *elem;
        const struct ieee80211_mgmt *mgmt = (void *)data;
-       bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
        unsigned int fixedlen, hdrlen;
+       bool s1g_bcn;
 
+       if (len < offsetofend(typeof(*mgmt), frame_control))
+               goto err;
+       s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
        if (s1g_bcn) {
                fixedlen = offsetof(struct ieee80211_ext,
                                    u.s1g_beacon.variable);


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

* Re: [PATCH v2] wireless/nl80211.c: fix uninitialized variable
  2021-03-30 16:37 Alaa Emad
@ 2021-03-30 17:14 ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-03-30 17:14 UTC (permalink / raw)
  To: Alaa Emad
  Cc: johannes, davem, kuba, linux-wireless, netdev, linux-kernel,
	syzkaller, syzbot+72b99dcf4607e8c770f3

On Tue, Mar 30, 2021 at 06:37:05PM +0200, Alaa Emad wrote:
> This change fix  KMSAN uninit-value in net/wireless/nl80211.c:225 , That
> because of `fixedlen` variable uninitialized,So I initialized it by zero.
> 
> Reported-by: syzbot+72b99dcf4607e8c770f3@syzkaller.appspotmail.com
> Signed-off-by: Alaa Emad <alaaemadhossney.ae@gmail.com>
> ---
> Changes in v2:
>   - Make the commit message more clearer.
> ---
>  net/wireless/nl80211.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 775d0c4d86c3..b87ab67ad33d 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
>  	const struct element *elem;
>  	const struct ieee80211_mgmt *mgmt = (void *)data;
>  	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
> -	unsigned int fixedlen, hdrlen;
> +	unsigned int fixedlen = 0 , hdrlen;

Please always use scripts/checkpatch.pl before sending out patches.  It
would have pointed out that this line is incorrect and needs to be fixed
up  :(

thanks,

greg k-h

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

* [PATCH v2] wireless/nl80211.c: fix uninitialized variable
@ 2021-03-30 16:37 Alaa Emad
  2021-03-30 17:14 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Alaa Emad @ 2021-03-30 16:37 UTC (permalink / raw)
  To: johannes, davem, kuba
  Cc: gregkh, linux-wireless, netdev, linux-kernel, syzkaller,
	Alaa Emad, syzbot+72b99dcf4607e8c770f3

This change fix  KMSAN uninit-value in net/wireless/nl80211.c:225 , That
because of `fixedlen` variable uninitialized,So I initialized it by zero.

Reported-by: syzbot+72b99dcf4607e8c770f3@syzkaller.appspotmail.com
Signed-off-by: Alaa Emad <alaaemadhossney.ae@gmail.com>
---
Changes in v2:
  - Make the commit message more clearer.
---
 net/wireless/nl80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 775d0c4d86c3..b87ab67ad33d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
 	const struct element *elem;
 	const struct ieee80211_mgmt *mgmt = (void *)data;
 	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
-	unsigned int fixedlen, hdrlen;
+	unsigned int fixedlen = 0 , hdrlen;
 
 	if (s1g_bcn) {
 		fixedlen = offsetof(struct ieee80211_ext,
-- 
2.25.1


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

end of thread, other threads:[~2021-03-30 19:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 17:22 [PATCH v2] wireless/nl80211.c: fix uninitialized variable Alaa Emad
2021-03-30 19:26 ` Eric Dumazet
  -- strict thread matches above, loose matches on Subject: below --
2021-03-30 16:37 Alaa Emad
2021-03-30 17:14 ` Greg KH

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).