diff mbox series

[2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write()

Message ID YsUydUx6FEz1ETq5@kili (mailing list archive)
State Changes Requested
Delegated to: Kalle Valo
Headers show
Series [1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() | expand

Commit Message

Dan Carpenter July 6, 2022, 6:57 a.m. UTC
This code has a check for "if (rc != len) {" so it will fail if the
simple_write_to_buffer() does not completely fill the buffer.  In
particular it will fail if "*ppos != 0". Although this code works, it is
more complicated than necessary.  Just use strndup_user() instead.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/net/wireless/ath/wil6210/debugfs.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Dan Carpenter July 6, 2022, 10:39 a.m. UTC | #1
On Wed, Jul 06, 2022 at 09:57:57AM +0300, Dan Carpenter wrote:
> This code has a check for "if (rc != len) {" so it will fail if the
> simple_write_to_buffer() does not completely fill the buffer.  In
> particular it will fail if "*ppos != 0". Although this code works, it is
> more complicated than necessary.  Just use strndup_user() instead.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

NAK.  This one is buggy.  strndup_user() is too strict.  This will break
stuff.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index fe84362718de..591ba7f61c64 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -1937,18 +1937,15 @@  static ssize_t wil_link_stats_write(struct file *file, const char __user *buf,
 	struct wil6210_priv *wil = s->private;
 	int cid, interval, rc, i;
 	struct wil6210_vif *vif;
-	char *kbuf = kmalloc(len + 1, GFP_KERNEL);
+	char *kbuf;
 
-	if (!kbuf)
-		return -ENOMEM;
+	if (*ppos != 0)
+		return -EINVAL;
 
-	rc = simple_write_to_buffer(kbuf, len, ppos, buf, len);
-	if (rc != len) {
-		kfree(kbuf);
-		return rc >= 0 ? -EIO : rc;
-	}
+	kbuf = strndup_user(buf, len + 1);
+	if (IS_ERR(kbuf))
+		return -ENOMEM;
 
-	kbuf[len] = '\0';
 	/* specify cid (use -1 for all cids) and snapshot interval in ms */
 	rc = sscanf(kbuf, "%d %d", &cid, &interval);
 	kfree(kbuf);