Skip to contentSkip to conversation

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

PATCH In review Tuo Li 2 participants 2 messages Aug 5, 2021 – Oct 11, 2021

Subsystems (3)
lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create()

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.

---
 drivers/net/wireless/ath/dfs_pattern_detector.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/dfs_pattern_detector.c +6 -4
index 80390495ea25..75cb53a3ec15 100644
@@ -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);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Tuo Li

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];

Quoted 6 lines

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

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

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

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

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