Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1288470

[PATCH v2] staging: gdm72xx: add userspace data struct

From Wim de With <nauxuron@wimdewith.com>
Newsgroups linux.kernel
Subject [PATCH v2] staging: gdm72xx: add userspace data struct
Date 2015-12-10 12:50 +0100
Message-ID <qE7Tr-5EP-9@gated-at.bofh.it> (permalink)
References <qE7JN-5B8-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This fixes the sparse warnings about dereferencing a userspace pointer.

Once I updated the sparse annotations, I noticed a bug in
gdm_wimax_ioctl() where we pass a user space pointer to gdm_update_fsm()
which dereferences it. I fixed this.

Signed-off-by: Wim de With <nauxuron@wimdewith.com>
---
 drivers/staging/gdm72xx/gdm_wimax.c | 17 +++++++++++++----
 drivers/staging/gdm72xx/wm_ioctl.h  |  7 ++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c
index d9ddced..16eac61 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -368,7 +368,7 @@ static void kdelete(void **buf)
 	}
 }
 
-static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_get_data(struct udata_s *dst, struct data_s *src)
 {
 	int size;
 
@@ -384,7 +384,7 @@ static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
 	return 0;
 }
 
-static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src)
+static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct udata_s *src)
 {
 	if (!src->size) {
 		dst->size = 0;
@@ -460,6 +460,7 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct wm_req_s *req = (struct wm_req_s *)ifr;
 	struct nic *nic = netdev_priv(dev);
 	int ret;
+	void *fsm_buf;
 
 	if (cmd != SIOCWMIOCTL)
 		return -EOPNOTSUPP;
@@ -482,8 +483,16 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 				/* NOTE: gdm_update_fsm should be called
 				 * before gdm_wimax_ioctl_set_data is called.
 				 */
-				gdm_update_fsm(dev,
-					       req->data.buf);
+				fsm_buf = kmalloc(sizeof(fsm_s), GFP_KERNEL);
+				if (!fsm_buf)
+					return -ENOMEM;
+				if (copy_from_user(fsm_buf, req->data.buf,
+						   sizeof(fsm_s))) {
+					kfree(fsm_buf);
+					return -EFAULT;
+				}
+				gdm_update_fsm(dev, fsm_buf);
+				kfree(fsm_buf);
 			}
 			ret = gdm_wimax_ioctl_set_data(
 				&nic->sdk_data[req->data_id], &req->data);
diff --git a/drivers/staging/gdm72xx/wm_ioctl.h b/drivers/staging/gdm72xx/wm_ioctl.h
index ed8f649..631cb1d 100644
--- a/drivers/staging/gdm72xx/wm_ioctl.h
+++ b/drivers/staging/gdm72xx/wm_ioctl.h
@@ -78,13 +78,18 @@ struct data_s {
 	void	*buf;
 };
 
+struct udata_s {
+	int		size;
+	void __user	*buf;
+};
+
 struct wm_req_s {
 	union {
 		char ifrn_name[IFNAMSIZ];
 	} ifr_ifrn;
 	unsigned short	cmd;
 	unsigned short	data_id;
-	struct data_s	data;
+	struct udata_s	data;
 
 /* NOTE: sizeof(struct wm_req_s) must be less than sizeof(struct ifreq). */
 };
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] staging: gdm72xx: add userspace data struct Wim de With <nauxuron@wimdewith.com> - 2015-12-10 10:20 +0100
  Re: [PATCH] staging: gdm72xx: add userspace data struct Dan Carpenter <dan.carpenter@oracle.com> - 2015-12-10 10:40 +0100
    Re: [PATCH] staging: gdm72xx: add userspace data struct Wim de With <nauxuron@wimdewith.com> - 2015-12-10 11:00 +0100
      Re: [PATCH] staging: gdm72xx: add userspace data struct Dan Carpenter <dan.carpenter@oracle.com> - 2015-12-10 12:40 +0100
        [PATCH v2] staging: gdm72xx: add userspace data struct Wim de With <nauxuron@wimdewith.com> - 2015-12-10 12:50 +0100
          Re: [PATCH v2] staging: gdm72xx: add userspace data struct One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2015-12-10 15:50 +0100
            Re: [PATCH v2] staging: gdm72xx: add userspace data struct Wim de With <nauxuron@wimdewith.com> - 2015-12-11 00:50 +0100
              Re: [PATCH v2] staging: gdm72xx: add userspace data struct One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> - 2015-12-11 01:20 +0100
                [PATCH v3] staging: gdm72xx: add userspace data struct Wim de With <nauxuron@wimdewith.com> - 2015-12-11 10:30 +0100

csiph-web