All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
@ 2021-11-30  8:43 ` Zhou Qingyang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhou Qingyang @ 2021-11-30  8:43 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Manikanta Pubbisetty, Shashidhar Lakkavalli,
	Govindaraj Saminathan, Vasanthakumar Thiagarajan,
	Pradeep Kumar Chitrapu, ath11k, linux-wireless, netdev,
	linux-kernel

In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
used in memcpy(), which may lead to a NULL pointer dereference on
failure of kzalloc().

Fix this bug by adding a check of arg.extraie.ptr.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_ATH11K=m show no new warnings, and our static
analyzer no longer warns about this code.

Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/wireless/ath/ath11k/mac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1cc55602787b..095f1f9b7611 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -3237,8 +3237,13 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
 	arg.scan_id = ATH11K_SCAN_ID;
 
 	if (req->ie_len) {
-		arg.extraie.len = req->ie_len;
 		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
+		if (!arg.extraie.ptr) {
+			ret = -ENOMEM;
+			goto exit;
+		}
+
+		arg.extraie.len = req->ie_len;
 		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
 	}
 
-- 
2.25.1


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

* [PATCH] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
@ 2021-11-30  8:43 ` Zhou Qingyang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhou Qingyang @ 2021-11-30  8:43 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Manikanta Pubbisetty, Shashidhar Lakkavalli,
	Govindaraj Saminathan, Vasanthakumar Thiagarajan,
	Pradeep Kumar Chitrapu, ath11k, linux-wireless, netdev,
	linux-kernel

In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
used in memcpy(), which may lead to a NULL pointer dereference on
failure of kzalloc().

Fix this bug by adding a check of arg.extraie.ptr.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_ATH11K=m show no new warnings, and our static
analyzer no longer warns about this code.

Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/net/wireless/ath/ath11k/mac.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1cc55602787b..095f1f9b7611 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -3237,8 +3237,13 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
 	arg.scan_id = ATH11K_SCAN_ID;
 
 	if (req->ie_len) {
-		arg.extraie.len = req->ie_len;
 		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
+		if (!arg.extraie.ptr) {
+			ret = -ENOMEM;
+			goto exit;
+		}
+
+		arg.extraie.len = req->ie_len;
 		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
 	}
 
-- 
2.25.1


-- 
ath11k mailing list
ath11k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath11k

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

* Re: [PATCH] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
  2021-11-30  8:43 ` Zhou Qingyang
@ 2021-12-01 17:22   ` Jeff Johnson
  -1 siblings, 0 replies; 8+ messages in thread
From: Jeff Johnson @ 2021-12-01 17:22 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Manikanta Pubbisetty, Shashidhar Lakkavalli,
	Govindaraj Saminathan, Vasanthakumar Thiagarajan,
	Pradeep Kumar Chitrapu, ath11k, linux-wireless, netdev,
	linux-kernel

On 11/30/2021 12:43 AM, Zhou Qingyang wrote:
> In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
> used in memcpy(), which may lead to a NULL pointer dereference on
> failure of kzalloc().
> 
> Fix this bug by adding a check of arg.extraie.ptr.
> 
> This bug was found by a static analyzer. The analysis employs
> differential checking to identify inconsistent security operations
> (e.g., checks or kfrees) between two code paths and confirms that the
> inconsistent operations are not recovered in the current function or
> the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.
> 
> Builds with CONFIG_ATH11K=m show no new warnings, and our static
> analyzer no longer warns about this code.
> 
> Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> ---
>   drivers/net/wireless/ath/ath11k/mac.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
> index 1cc55602787b..095f1f9b7611 100644
> --- a/drivers/net/wireless/ath/ath11k/mac.c
> +++ b/drivers/net/wireless/ath/ath11k/mac.c
> @@ -3237,8 +3237,13 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
>   	arg.scan_id = ATH11K_SCAN_ID;
>   
>   	if (req->ie_len) {
> -		arg.extraie.len = req->ie_len;
>   		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);

Your patch looks good, but since you are touching this code IMO this 
should be changed to kmemdup() and we should remove the memcpy() below.

> +		if (!arg.extraie.ptr) {
> +			ret = -ENOMEM;
> +			goto exit;
> +		}
> +
> +		arg.extraie.len = req->ie_len;
>   		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
>   	}
>   
> 


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

* Re: [PATCH] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
@ 2021-12-01 17:22   ` Jeff Johnson
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Johnson @ 2021-12-01 17:22 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Manikanta Pubbisetty, Shashidhar Lakkavalli,
	Govindaraj Saminathan, Vasanthakumar Thiagarajan,
	Pradeep Kumar Chitrapu, ath11k, linux-wireless, netdev,
	linux-kernel

On 11/30/2021 12:43 AM, Zhou Qingyang wrote:
> In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
> used in memcpy(), which may lead to a NULL pointer dereference on
> failure of kzalloc().
> 
> Fix this bug by adding a check of arg.extraie.ptr.
> 
> This bug was found by a static analyzer. The analysis employs
> differential checking to identify inconsistent security operations
> (e.g., checks or kfrees) between two code paths and confirms that the
> inconsistent operations are not recovered in the current function or
> the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.
> 
> Builds with CONFIG_ATH11K=m show no new warnings, and our static
> analyzer no longer warns about this code.
> 
> Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> ---
>   drivers/net/wireless/ath/ath11k/mac.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
> index 1cc55602787b..095f1f9b7611 100644
> --- a/drivers/net/wireless/ath/ath11k/mac.c
> +++ b/drivers/net/wireless/ath/ath11k/mac.c
> @@ -3237,8 +3237,13 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
>   	arg.scan_id = ATH11K_SCAN_ID;
>   
>   	if (req->ie_len) {
> -		arg.extraie.len = req->ie_len;
>   		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);

Your patch looks good, but since you are touching this code IMO this 
should be changed to kmemdup() and we should remove the memcpy() below.

> +		if (!arg.extraie.ptr) {
> +			ret = -ENOMEM;
> +			goto exit;
> +		}
> +
> +		arg.extraie.len = req->ie_len;
>   		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
>   	}
>   
> 


-- 
ath11k mailing list
ath11k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath11k

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

* [PATCH v2] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
  2021-12-01 17:22   ` Jeff Johnson
@ 2021-12-02 15:53     ` Zhou Qingyang
  -1 siblings, 0 replies; 8+ messages in thread
From: Zhou Qingyang @ 2021-12-02 15:53 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Pradeep Kumar Chitrapu, Shashidhar Lakkavalli, Ganesh Sesetti,
	kbuild test robot, John Crispin, ath11k, linux-wireless, netdev,
	linux-kernel

In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
used in memcpy(), which may lead to a NULL pointer dereference on
failure of kzalloc().

Fix this bug by adding a check of arg.extraie.ptr.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_ATH11K=m show no new warnings, and our static
analyzer no longer warns about this code.

Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
Changes in v2:
  -  Use kmemdup() instead of kzalloc()

 drivers/net/wireless/ath/ath11k/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1cc55602787b..dcefe444e7e3 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -3237,9 +3237,12 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
 	arg.scan_id = ATH11K_SCAN_ID;
 
 	if (req->ie_len) {
+		arg.extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL);
+		if (!arg.extraie.ptr) {
+			ret = -ENOMEM;
+			goto exit;
+		}
 		arg.extraie.len = req->ie_len;
-		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
-		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
 	}
 
 	if (req->n_ssids) {
-- 
2.25.1


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

* [PATCH v2] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
@ 2021-12-02 15:53     ` Zhou Qingyang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhou Qingyang @ 2021-12-02 15:53 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Pradeep Kumar Chitrapu, Shashidhar Lakkavalli, Ganesh Sesetti,
	kbuild test robot, John Crispin, ath11k, linux-wireless, netdev,
	linux-kernel

In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
used in memcpy(), which may lead to a NULL pointer dereference on
failure of kzalloc().

Fix this bug by adding a check of arg.extraie.ptr.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_ATH11K=m show no new warnings, and our static
analyzer no longer warns about this code.

Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
Changes in v2:
  -  Use kmemdup() instead of kzalloc()

 drivers/net/wireless/ath/ath11k/mac.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1cc55602787b..dcefe444e7e3 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -3237,9 +3237,12 @@ static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
 	arg.scan_id = ATH11K_SCAN_ID;
 
 	if (req->ie_len) {
+		arg.extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL);
+		if (!arg.extraie.ptr) {
+			ret = -ENOMEM;
+			goto exit;
+		}
 		arg.extraie.len = req->ie_len;
-		arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
-		memcpy(arg.extraie.ptr, req->ie, req->ie_len);
 	}
 
 	if (req->n_ssids) {
-- 
2.25.1


-- 
ath11k mailing list
ath11k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath11k

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

* Re: [PATCH v2] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
  2021-12-02 15:53     ` Zhou Qingyang
@ 2021-12-14 15:31       ` Kalle Valo
  -1 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2021-12-14 15:31 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: zhou1615, kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Pradeep Kumar Chitrapu, Shashidhar Lakkavalli, Ganesh Sesetti,
	kbuild test robot, John Crispin, ath11k, linux-wireless, netdev,
	linux-kernel

Zhou Qingyang <zhou1615@umn.edu> wrote:

> In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
> used in memcpy(), which may lead to a NULL pointer dereference on
> failure of kzalloc().
> 
> Fix this bug by adding a check of arg.extraie.ptr.
> 
> This bug was found by a static analyzer. The analysis employs
> differential checking to identify inconsistent security operations
> (e.g., checks or kfrees) between two code paths and confirms that the
> inconsistent operations are not recovered in the current function or
> the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.
> 
> Builds with CONFIG_ATH11K=m show no new warnings, and our static
> analyzer no longer warns about this code.
> 
> Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

eccd25136386 ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20211202155348.71315-1-zhou1615@umn.edu/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

* Re: [PATCH v2] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
@ 2021-12-14 15:31       ` Kalle Valo
  0 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2021-12-14 15:31 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: zhou1615, kjlu, Kalle Valo, David S. Miller, Jakub Kicinski,
	Pradeep Kumar Chitrapu, Shashidhar Lakkavalli, Ganesh Sesetti,
	kbuild test robot, John Crispin, ath11k, linux-wireless, netdev,
	linux-kernel

Zhou Qingyang <zhou1615@umn.edu> wrote:

> In ath11k_mac_op_hw_scan(), the return value of kzalloc() is directly
> used in memcpy(), which may lead to a NULL pointer dereference on
> failure of kzalloc().
> 
> Fix this bug by adding a check of arg.extraie.ptr.
> 
> This bug was found by a static analyzer. The analysis employs
> differential checking to identify inconsistent security operations
> (e.g., checks or kfrees) between two code paths and confirms that the
> inconsistent operations are not recovered in the current function or
> the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.
> 
> Builds with CONFIG_ATH11K=m show no new warnings, and our static
> analyzer no longer warns about this code.
> 
> Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

eccd25136386 ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20211202155348.71315-1-zhou1615@umn.edu/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


-- 
ath11k mailing list
ath11k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath11k

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

end of thread, other threads:[~2021-12-14 15:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30  8:43 [PATCH] ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan() Zhou Qingyang
2021-11-30  8:43 ` Zhou Qingyang
2021-12-01 17:22 ` Jeff Johnson
2021-12-01 17:22   ` Jeff Johnson
2021-12-02 15:53   ` [PATCH v2] " Zhou Qingyang
2021-12-02 15:53     ` Zhou Qingyang
2021-12-14 15:31     ` Kalle Valo
2021-12-14 15:31       ` Kalle Valo

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.