Skip to contentSkip to conversation

wifi: nxpwifi: bound debugfs output

PATCH In review Heyang Tan 2 participants 5 messages Sep 19 – Sep 21

Subsystems (2)
lore
Share & tools
lore

Heyang Tan

author
#0 lore raw

v3 cover wifi: nxpwifi: bound debugfs output

Bound two nxpwifi debugfs formatting paths to their output buffers.

Changes in v3:
- Split the histogram and debug-info fixes into separate patches.
- Rewrite the commit messages following the feedback from Francesco Dolcini.
- Move test results out of the commit messages.

Testing:
- x86_64 kernel build with CONFIG_NXPWIFI=m, CONFIG_CFG80211=m, and CONFIG_DEBUG_FS=y

Heyang Tan (2):
wifi: nxpwifi: bound histogram debugfs output
wifi: nxpwifi: bound debug info output

 drivers/net/wireless/nxp/nxpwifi/debugfs.c | 31 +++++++++-------
 drivers/net/wireless/nxp/nxpwifi/main.c    |  5 ++-
 drivers/net/wireless/nxp/nxpwifi/util.c    | 43 +++++++++++++---------
 drivers/net/wireless/nxp/nxpwifi/util.h    |  1 +
 4 files changed, 48 insertions(+), 32 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/2 wifi: nxpwifi: bound histogram debugfs output

nxpwifi_histogram_read() writes histogram entries to a PAGE_SIZE buffer. Each entry is formatted with sprintf(), so enough populated buckets can write past the allocation.

Use scnprintf() with the remaining buffer space when formatting the histogram.

Assisted-by LLM
---
 drivers/net/wireless/nxp/nxpwifi/debugfs.c | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)
drivers/net/wireless/nxp/nxpwifi/debugfs.c +17 -12
index ccaf0eae3..fd738a811 100644
@@ -211,25 +211,26 @@ nxpwifi_histogram_read(struct file *file, char __user *ubuf,
 
 	phist_data = priv->hist_data;
 
-	p += sprintf(p, "\n"
+	p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "\n"
 		     "total samples = %d\n",
 		     atomic_read(&phist_data->num_samples));
 
-	p += sprintf(p,
+	p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
 		     "rx rates (in Mbps): 0=1M   1=2M 2=5.5M  3=11M   4=6M   5=9M  6=12M\n"
 		     "7=18M  8=24M  9=36M  10=48M  11=54M 12-27=MCS0-15(BW20) 28-43=MCS0-15(BW40)\n");
 
 	if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
-		p += sprintf(p,
+		p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
 			     "44-53=MCS0-9(VHT:BW20) 54-63=MCS0-9(VHT:BW40) 64-73=MCS0-9(VHT:BW80)\n\n");
 	} else {
-		p += sprintf(p, "\n");
+		p += scnprintf(p, PAGE_SIZE - (p - (char *)page), "\n");
 	}
 
 	for (i = 0; i < NXPWIFI_MAX_RX_RATES; i++) {
 		value = atomic_read(&phist_data->rx_rate[i]);
 		if (value)
-			p += sprintf(p, "rx_rate[%02d] = %d\n", i, value);
+			p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
+				       "rx_rate[%02d] = %d\n", i, value);
 	}
 
 	if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) {
@@ -237,27 +238,31 @@ nxpwifi_histogram_read(struct file *file, char __user *ubuf,
 		     i++) {
 			value = atomic_read(&phist_data->rx_rate[i]);
 			if (value)
-				p += sprintf(p, "rx_rate[%02d] = %d\n",
-					   i, value);
+				p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
+					       "rx_rate[%02d] = %d\n",
+					       i, value);
 		}
 	}
 
 	for (i = 0; i < NXPWIFI_MAX_SNR; i++) {
 		value =  atomic_read(&phist_data->snr[i]);
 		if (value)
-			p += sprintf(p, "snr[%02ddB] = %d\n", i, value);
+			p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
+				       "snr[%02ddB] = %d\n", i, value);
 	}
 	for (i = 0; i < NXPWIFI_MAX_NOISE_FLR; i++) {
 		value = atomic_read(&phist_data->noise_flr[i]);
 		if (value)
-			p += sprintf(p, "noise_flr[%02ddBm] = %d\n",
-				     (int)(i - 128), value);
+			p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
+				       "noise_flr[%02ddBm] = %d\n",
+				       (int)(i - 128), value);
 	}
 	for (i = 0; i < NXPWIFI_MAX_SIG_STRENGTH; i++) {
 		value = atomic_read(&phist_data->sig_str[i]);
 		if (value)
-			p += sprintf(p, "sig_strength[-%02ddBm] = %d\n",
-				i, value);
+			p += scnprintf(p, PAGE_SIZE - (p - (char *)page),
+				       "sig_strength[-%02ddBm] = %d\n",
+				       i, value);
 	}
 
 	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
Signature · 1 line
2.34.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] wifi: nxpwifi: bound histogram debugfs output

Quoted 6 lines · Heyang Tan

nxpwifi_histogram_read() writes histogram entries to a PAGE_SIZE buffer. Each entry is formatted with sprintf(), so enough populated buckets can write past the allocation.

Use scnprintf() with the remaining buffer space when formatting the histogram.

Using seq_file may be a better long-term solution, but the current scnprintf() fix looks good to me.

author
#3 lore raw

PATCH v3 2/2 wifi: nxpwifi: bound debug info output

In reply to Heyang Tan

nxpwifi_debug_read() provides a PAGE_SIZE buffer to nxpwifi_debug_info_to_buffer(), which formats debug state with unbounded sprintf() calls. The same helper is also used for the firmware dump.

Pass the output size to the helper and use scnprintf() while formatting. Clamp the debug table counts and window size to the backing array lengths before accessing them.

Assisted-by LLM
---
 drivers/net/wireless/nxp/nxpwifi/debugfs.c |  2 +-
 drivers/net/wireless/nxp/nxpwifi/main.c    |  5 ++-
 drivers/net/wireless/nxp/nxpwifi/util.c    | 43 +++++++++++++---------
 drivers/net/wireless/nxp/nxpwifi/util.h    |  1 +
 4 files changed, 31 insertions(+), 20 deletions(-)
drivers/net/wireless/nxp/nxpwifi/debugfs.c +1 -1
index fd738a811..cd6e73a21 100644
@@ -304,7 +304,7 @@ nxpwifi_debug_read(struct file *file, char __user *ubuf,
 	if (ret)
 		goto free_and_exit;
 
-	p += nxpwifi_debug_info_to_buffer(priv, p, &info);
+	p += nxpwifi_debug_info_to_buffer(priv, p, PAGE_SIZE, &info);
 
 	ret = simple_read_from_buffer(ubuf, count, ppos, (char *)page,
 				      (unsigned long)p - page);
drivers/net/wireless/nxp/nxpwifi/main.c +4 -1
index 55b962430..b4cac1df9 100644
@@ -1113,7 +1113,10 @@ void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter)
 				continue;
 			priv = adapter->priv[i];
 			nxpwifi_get_debug_info(priv, debug_info);
-			p += nxpwifi_debug_info_to_buffer(priv, p, debug_info);
+			p += nxpwifi_debug_info_to_buffer(priv, p,
+					  NXPWIFI_FW_DUMP_SIZE -
+					  (p - (char *)adapter->devdump_data),
+					  debug_info);
 			break;
 		}
 		kfree(debug_info);
drivers/net/wireless/nxp/nxpwifi/util.c +25 -18

85 lines not on this page · raw message

drivers/net/wireless/nxp/nxpwifi/util.h +1 -0
index 1a47c8c5b..a0ec722e6 100644
@@ -82,6 +82,7 @@ static inline dma_addr_t NXPWIFI_SKB_DMA_ADDR(struct sk_buff *skb)
 }
 
 int nxpwifi_debug_info_to_buffer(struct nxpwifi_private *priv, char *buf,
+				 size_t buf_size,
 				 struct nxpwifi_debug_info *info);
 
 static inline void le16_unaligned_add_cpu(__le16 *var, u16 val)
Signature · 1 line
2.34.1
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] wifi: nxpwifi: bound debug info output

Quoted 9 lines · Heyang Tan

nxpwifi_debug_read() provides a PAGE_SIZE buffer to nxpwifi_debug_info_to_buffer(), which formats debug state with unbounded sprintf() calls. The same helper is also used for the firmware dump.

Pass the output size to the helper and use scnprintf() while formatting. Clamp the debug table counts and window size to the backing array lengths before accessing them.