All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi()
@ 2022-07-06  6:55 Dan Carpenter
  2022-07-06  6:57 ` [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write() Dan Carpenter
  2022-07-10 13:04 ` [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-07-06  6:55 UTC (permalink / raw)
  To: Kalle Valo, Jiri Slaby
  Cc: Paolo Abeni, Johannes Berg, Vladimir Kondratiev,
	John W. Linville, linux-wireless, kernel-janitors

The simple_write_to_buffer() function will succeed if even a single
byte is initialized.  However we need to initialize the whole buffer
to prevent information leaks.  Just use memdup_user().

Fixes: ff974e408334 ("wil6210: debugfs interface to send raw WMI command")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/net/wireless/ath/wil6210/debugfs.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 64d6c98174c8..fe84362718de 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -1012,18 +1012,12 @@ static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
 	u16 cmdid;
 	int rc, rc1;
 
-	if (cmdlen < 0)
+	if (cmdlen < 0 || *ppos != 0)
 		return -EINVAL;
 
-	wmi = kmalloc(len, GFP_KERNEL);
-	if (!wmi)
-		return -ENOMEM;
-
-	rc = simple_write_to_buffer(wmi, len, ppos, buf, len);
-	if (rc < 0) {
-		kfree(wmi);
-		return rc;
-	}
+	wmi = memdup_user(buf, len);
+	if (IS_ERR(wmi))
+		return PTR_ERR(wmi);
 
 	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
 	cmdid = le16_to_cpu(wmi->command_id);
-- 
2.35.1


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

* [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write()
  2022-07-06  6:55 [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() Dan Carpenter
@ 2022-07-06  6:57 ` Dan Carpenter
  2022-07-06 10:39   ` Dan Carpenter
  2022-07-10 13:04 ` [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() kernel test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-07-06  6:57 UTC (permalink / raw)
  To: Kalle Valo, Jiri Slaby
  Cc: Paolo Abeni, Johannes Berg, linux-wireless, kernel-janitors

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

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);
-- 
2.35.1


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

* Re: [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write()
  2022-07-06  6:57 ` [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write() Dan Carpenter
@ 2022-07-06 10:39   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-07-06 10:39 UTC (permalink / raw)
  To: Kalle Valo, Jiri Slaby
  Cc: Paolo Abeni, Johannes Berg, linux-wireless, kernel-janitors

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


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

* Re: [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi()
  2022-07-06  6:55 [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() Dan Carpenter
  2022-07-06  6:57 ` [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write() Dan Carpenter
@ 2022-07-10 13:04 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-07-10 13:04 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: llvm, kbuild-all

Hi Dan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main kvalo-ath/ath-next linus/master kvalo-wireless-drivers/master v5.19-rc5 next-20220708]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dan-Carpenter/wil6210-debugfs-fix-info-leak-in-wil_write_file_wmi/20220706-145900
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20220710/202207102127.7EJG1r1i-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project f553287b588916de09c66e3e32bf75e5060f967f)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/9c358c3b4049c36e9f0f49ea9a491c68dc8c9a89
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Dan-Carpenter/wil6210-debugfs-fix-info-leak-in-wil_write_file_wmi/20220706-145900
        git checkout 9c358c3b4049c36e9f0f49ea9a491c68dc8c9a89
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/gpio/ drivers/net/ethernet/marvell/octeontx2/af/ drivers/net/wireless/ath/wil6210/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/net/wireless/ath/wil6210/debugfs.c:1030:9: warning: variable 'rc' is uninitialized when used here [-Wuninitialized]
           return rc;
                  ^~
   drivers/net/wireless/ath/wil6210/debugfs.c:1013:8: note: initialize the variable 'rc' to silence this warning
           int rc, rc1;
                 ^
                  = 0
   1 warning generated.


vim +/rc +1030 drivers/net/wireless/ath/wil6210/debugfs.c

2be7d22f062535 Vladimir Kondratiev 2012-12-20  1000  
ff974e40833413 Vladimir Kondratiev 2014-06-16  1001  /* Write WMI command (w/o mbox header) to this file to send it
ff974e40833413 Vladimir Kondratiev 2014-06-16  1002   * WMI starts from wil6210_mbox_hdr_wmi header
ff974e40833413 Vladimir Kondratiev 2014-06-16  1003   */
ff974e40833413 Vladimir Kondratiev 2014-06-16  1004  static ssize_t wil_write_file_wmi(struct file *file, const char __user *buf,
ff974e40833413 Vladimir Kondratiev 2014-06-16  1005  				  size_t len, loff_t *ppos)
ff974e40833413 Vladimir Kondratiev 2014-06-16  1006  {
ff974e40833413 Vladimir Kondratiev 2014-06-16  1007  	struct wil6210_priv *wil = file->private_data;
e00243fab84b4e Lior David          2018-02-26  1008  	struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
b874ddecae0a08 Lior David          2016-03-01  1009  	struct wmi_cmd_hdr *wmi;
ff974e40833413 Vladimir Kondratiev 2014-06-16  1010  	void *cmd;
b874ddecae0a08 Lior David          2016-03-01  1011  	int cmdlen = len - sizeof(struct wmi_cmd_hdr);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1012  	u16 cmdid;
ff974e40833413 Vladimir Kondratiev 2014-06-16  1013  	int rc, rc1;
ff974e40833413 Vladimir Kondratiev 2014-06-16  1014  
9c358c3b4049c3 Dan Carpenter       2022-07-06  1015  	if (cmdlen < 0 || *ppos != 0)
ff974e40833413 Vladimir Kondratiev 2014-06-16  1016  		return -EINVAL;
ff974e40833413 Vladimir Kondratiev 2014-06-16  1017  
9c358c3b4049c3 Dan Carpenter       2022-07-06  1018  	wmi = memdup_user(buf, len);
9c358c3b4049c3 Dan Carpenter       2022-07-06  1019  	if (IS_ERR(wmi))
9c358c3b4049c3 Dan Carpenter       2022-07-06  1020  		return PTR_ERR(wmi);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1021  
69218a48005d0c Lior David          2016-03-21  1022  	cmd = (cmdlen > 0) ? &wmi[1] : NULL;
b874ddecae0a08 Lior David          2016-03-01  1023  	cmdid = le16_to_cpu(wmi->command_id);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1024  
e00243fab84b4e Lior David          2018-02-26  1025  	rc1 = wmi_send(wil, cmdid, vif->mid, cmd, cmdlen);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1026  	kfree(wmi);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1027  
af3db60a30331d Lazar Alexei        2017-01-20  1028  	wil_info(wil, "0x%04x[%d] -> %d\n", cmdid, cmdlen, rc1);
ff974e40833413 Vladimir Kondratiev 2014-06-16  1029  
ff974e40833413 Vladimir Kondratiev 2014-06-16 @1030  	return rc;
ff974e40833413 Vladimir Kondratiev 2014-06-16  1031  }
ff974e40833413 Vladimir Kondratiev 2014-06-16  1032  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-07-10 13:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06  6:55 [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() Dan Carpenter
2022-07-06  6:57 ` [PATCH 2/2] wil6210: debugfs: replace in wil_link_stats_write() in wil_link_stats_write() Dan Carpenter
2022-07-06 10:39   ` Dan Carpenter
2022-07-10 13:04 ` [PATCH 1/2] wil6210: debugfs: fix info leak in wil_write_file_wmi() kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.