linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create()
@ 2021-08-05 15:38 Tuo Li
  2021-10-11  6:26 ` Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: Tuo Li @ 2021-08-05 15:38 UTC (permalink / raw)
  To: kvalo, davem, kuba
  Cc: linux-wireless, netdev, linux-kernel, baijiaju1990, Tuo Li, TOTE Robot

kzalloc() is used to allocate memory for cd->detectors, and if it fails,
channel_detector_exit() behind the label fail will be called:
  channel_detector_exit(dpd, cd);

In channel_detector_exit(), cd->detectors is dereferenced through:
  struct pri_detector *de = cd->detectors[i];

To fix this possible null-pointer dereference, check cd->detectors before 
the for loop to dereference cd->detectors. 

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/net/wireless/ath/dfs_pattern_detector.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ath/dfs_pattern_detector.c b/drivers/net/wireless/ath/dfs_pattern_detector.c
index 80390495ea25..75cb53a3ec15 100644
--- a/drivers/net/wireless/ath/dfs_pattern_detector.c
+++ b/drivers/net/wireless/ath/dfs_pattern_detector.c
@@ -183,10 +183,12 @@ static void channel_detector_exit(struct dfs_pattern_detector *dpd,
 	if (cd == NULL)
 		return;
 	list_del(&cd->head);
-	for (i = 0; i < dpd->num_radar_types; i++) {
-		struct pri_detector *de = cd->detectors[i];
-		if (de != NULL)
-			de->exit(de);
+	if (cd->detectors) {
+		for (i = 0; i < dpd->num_radar_types; i++) {
+			struct pri_detector *de = cd->detectors[i];
+			if (de != NULL)
+				de->exit(de);
+		}
 	}
 	kfree(cd->detectors);
 	kfree(cd);
-- 
2.25.1


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

* Re: [PATCH] ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create()
  2021-08-05 15:38 [PATCH] ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create() Tuo Li
@ 2021-10-11  6:26 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2021-10-11  6:26 UTC (permalink / raw)
  To: Tuo Li
  Cc: davem, kuba, linux-wireless, netdev, linux-kernel, baijiaju1990,
	Tuo Li, TOTE Robot

Tuo Li <islituo@gmail.com> wrote:

> kzalloc() is used to allocate memory for cd->detectors, and if it fails,
> channel_detector_exit() behind the label fail will be called:
>   channel_detector_exit(dpd, cd);
> 
> In channel_detector_exit(), cd->detectors is dereferenced through:
>   struct pri_detector *de = cd->detectors[i];
> 
> To fix this possible null-pointer dereference, check cd->detectors before
> the for loop to dereference cd->detectors.
> 
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Tuo Li <islituo@gmail.com>
> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

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

4b6012a7830b ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create()

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20210805153854.154066-1-islituo@gmail.com/

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


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

end of thread, other threads:[~2021-10-11  6:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 15:38 [PATCH] ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create() Tuo Li
2021-10-11  6:26 ` Kalle Valo

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