linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: prameela.j04cs@gmail.com
Cc: linux-wireless@vger.kernel.org
Subject: [bug report] rsi: Add new host interface operations
Date: Mon, 12 Jun 2017 22:59:08 +0300	[thread overview]
Message-ID: <20170612195908.GA2079@elgon.mountain> (raw)

Hello Prameela Rani Garnepudi,

The patch b97e9b94ad75: "rsi: Add new host interface operations" from
May 16, 2017, leads to the following static checker warning:

	drivers/net/wireless/rsi/rsi_91x_usb.c:400 rsi_usb_master_reg_read()
	warn: passing casted pointer 'value' to 'rsi_usb_reg_read()' 32 vs 16.

drivers/net/wireless/rsi/rsi_91x_usb.c
   156  static int rsi_usb_reg_read(struct usb_device *usbdev,
   157                              u32 reg,
   158                              u16 *value,
   159                              u16 len)
   160  {
   161          u8 *buf;
   162          int status = -ENOMEM;
   163  
   164          buf  = kmalloc(0x04, GFP_KERNEL);

Why are we allocating 0x4 bytes?

   165          if (!buf)
   166                  return status;
   167  
   168          status = usb_control_msg(usbdev,
   169                                   usb_rcvctrlpipe(usbdev, 0),
   170                                   USB_VENDOR_REGISTER_READ,
   171                                   RSI_USB_REQ_IN,
   172                                   ((reg & 0xffff0000) >> 16), (reg & 0xffff),
   173                                   (void *)buf,
   174                                   len,
                                         ^^^
If len is more than 4 then we have memory corruption.

   175                                   USB_CTRL_GET_TIMEOUT);
   176  
   177          *value = (buf[0] | (buf[1] << 8));
   178          if (status < 0) {
   179                  rsi_dbg(ERR_ZONE,
   180                          "%s: Reg read failed with error code :%d\n",
   181                          __func__, status);
   182          }

[ snip ]

   394  static int rsi_usb_master_reg_read(struct rsi_hw *adapter, u32 reg,
   395                                     u32 *value, u16 len)
   396  {
   397          struct usb_device *usbdev =
   398                  ((struct rsi_91x_usbdev *)adapter->rsi_dev)->usbdev;
   399  
   400          return rsi_usb_reg_read(usbdev, reg, (u16 *)value, len);

This is an endian bug because we're assuming the CPU is little endian.

	u16 tmp;
	int ret;

	if (len != sizeof(*value)) /* Or maybe sizeof(tmp), who knows? */
		return -EINVAL;
	ret = rsi_usb_reg_read(usbdev, reg, &tmp, len);
	if (ret)
		return ret;

	*value = tmp;
	return 0;


   401  }

regards,
dan carpenter

             reply	other threads:[~2017-06-12 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-12 19:59 Dan Carpenter [this message]
2017-07-07 14:28 ` [bug report] rsi: Add new host interface operations Dan Carpenter
2017-07-11 14:34   ` Amitkumar Karwar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170612195908.GA2079@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=prameela.j04cs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).