Skip to contentSkip to conversation

ath10k: fix out of bounds access to local buffer

PATCH Superseded Michael Mera 3 participants 6 messages Apr 24, 2017 – May 22, 2017 Qualcomm Atheros ATH10K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath10k: fix out of bounds access to local buffer

During write to debugfs file simulate_fw_crash, fixed-size local buffer 'buf' is accessed and modified at index 'count-1', where 'count' is the size of the write (so potentially out of bounds).
This patch fixes this problem.

---
 drivers/net/wireless/ath/ath10k/debug.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath10k/debug.c +10 -6
index fb0ade3adb07..7f3c17e55693 100644
@@ -628,17 +628,21 @@ static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
 					      size_t count, loff_t *ppos)
 {
 	struct ath10k *ar = file->private_data;
-	char buf[32];
+	char buf[32] = {0};
+	ssize_t rc;
 	int ret;
 
-	simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
+	/* filter partial writes and invalid commands */
+	if (*ppos != 0 || count >= sizeof(buf) || count == 0)
+		return -EINVAL;
 
-	/* make sure that buf is null terminated */
-	buf[sizeof(buf) - 1] = 0;
+	rc = simple_write_to_buffer(buf, sizeof(buf)-1, ppos, user_buf, count);
+	if (rc < 0)
+		return rc;
 
 	/* drop the possible '\n' from the end */
-	if (buf[count - 1] == '\n')
-		buf[count - 1] = 0;
+	if (buf[*ppos - 1] == '\n')
+		buf[*ppos - 1] = '\0';
 
 	mutex_lock(&ar->conf_mutex);
 
Signature · 1 line
2.9.3
#1 lore raw

Hi,

Please send again to [email protected] with cc [email protected]

Thanks.

2017-04-24 7:39 GMT+02:00 Michael Mera <[email protected]>:

Quoted 45 lines

During write to debugfs file simulate_fw_crash, fixed-size local buffer 'buf' is accessed and modified at index 'count-1', where 'count' is the size of the write (so potentially out of bounds).
This patch fixes this problem.

---
 drivers/net/wireless/ath/ath10k/debug.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath10k/debug.c +10 -7
index fb0ade3adb07..7f3c17e55693 100644
@@ -628,17 +628,21 @@ static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
                                              size_t count, loff_t *ppos)
 {
        struct ath10k *ar = file->private_data;
-       char buf[32];
+       char buf[32] = {0};
+       ssize_t rc;
        int ret;
 
-       simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
+       /* filter partial writes and invalid commands */
+       if (*ppos != 0 || count >= sizeof(buf) || count == 0)
+               return -EINVAL;
 
-       /* make sure that buf is null terminated */
-       buf[sizeof(buf) - 1] = 0;
+       rc = simple_write_to_buffer(buf, sizeof(buf)-1, ppos, user_buf, count);
+       if (rc < 0)
+               return rc;
 
        /* drop the possible '\n' from the end */
-       if (buf[count - 1] == '\n')
-               buf[count - 1] = 0;
+       if (buf[*ppos - 1] == '\n')
+               buf[*ppos - 1] = '\0';
 
        mutex_lock(&ar->conf_mutex);
 
--

2.9.3

#3 lore raw

2017-04-24 9:41 GMT+02:00 Michael Mera <[email protected]>:

Quoted 6 lines
Quoted 3 lines · Marcin Rokicki

Please send again to [email protected] with cc [email protected]

Sorry for the mistake. Resent as requested.

No problem.

Quoted 5 lines

Just for the record, I followed instructions at:
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches?s[]=submit#who_to_address

So, maybe this needs to be updated to reflect the ath10k case.

Check this page:
https://wireless.wiki.kernel.org/en/users/drivers/ath10k/sources

Quoted 3 lines

Thanks,
Michael Mera

#4 lore raw
In reply to Michael Mera
Quoted 9 lines · Michael Mera
Quoted 3 lines · Marcin Rokicki

Please send again to [email protected] with cc [email protected]

Sorry for the mistake. Resent as requested.

Just for the record, I followed instructions at:
https://wireless.wiki.kernel.org/en/developers/documentation/submitting=

patches?s[]=3Dsubmit#who_to_address

Quoted 2 lines

So, maybe this needs to be updated to reflect the ath10k case.

I added a link to the corresponding ath10k page. BTW, it's a wiki so everyone are free to improve the instructions on their own.

--=20
Kalle Valo=

#5 lore raw
Quoted 2 lines · Kalle Valo

I added a link to the corresponding ath10k page. BTW, it's a wiki so everyone are free to improve the instructions on their own.

As it was my first contribution, I didn't feel like editing things without some sort of approval first. I will try to be more audacious next time.

Thank you very much,
Michael Mera