Skip to content

Commit 80f8c5b

Browse files
jkivilinlinvjw
authored andcommitted
rndis_wlan: copy only useful data from rndis_command respond
rndis_query_oid() uses full output buffer size to copy response buffer from rndis_command()/device. This doesn't cause problems as response buffer is sized based on output buffer but does copy extra unset bytes. So change rndis_query_oid() so that only meaningful bytes are being copied. Also in case of malfunctioning device/cable/etc returned data offset from device might be wrong so bound check memory access correctly, so add checks for this. v2: fixed to use new netdev_dbg/warn/etc instead of old devdbg/warn/etc Signed-off-by: Jussi Kivilinna <[email protected]> Signed-off-by: John W. Linville <[email protected]>
1 parent eae4475 commit 80f8c5b

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

drivers/net/wireless/rndis_wlan.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
704704
struct rndis_query_c *get_c;
705705
} u;
706706
int ret, buflen;
707+
int resplen, respoffs, copylen;
707708

708709
buflen = *len + sizeof(*u.get);
709710
if (buflen < CONTROL_BUFFER_SIZE)
@@ -733,11 +734,34 @@ static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
733734
le32_to_cpu(u.get_c->status));
734735

735736
if (ret == 0) {
736-
memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
737+
resplen = le32_to_cpu(u.get_c->len);
738+
respoffs = le32_to_cpu(u.get_c->offset) + 8;
737739

738-
ret = le32_to_cpu(u.get_c->len);
739-
if (ret > *len)
740-
*len = ret;
740+
if (respoffs > buflen) {
741+
/* Device returned data offset outside buffer, error. */
742+
netdev_dbg(dev->net, "%s(%s): received invalid "
743+
"data offset: %d > %d\n", __func__,
744+
oid_to_string(oid), respoffs, buflen);
745+
746+
ret = -EINVAL;
747+
goto exit_unlock;
748+
}
749+
750+
if ((resplen + respoffs) > buflen) {
751+
/* Device would have returned more data if buffer would
752+
* have been big enough. Copy just the bits that we got.
753+
*/
754+
copylen = buflen - respoffs;
755+
} else {
756+
copylen = resplen;
757+
}
758+
759+
if (copylen > *len)
760+
copylen = *len;
761+
762+
memcpy(data, u.buf + respoffs, copylen);
763+
764+
*len = resplen;
741765

742766
ret = rndis_error_status(u.get_c->status);
743767
if (ret < 0)
@@ -746,6 +770,7 @@ static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
746770
le32_to_cpu(u.get_c->status), ret);
747771
}
748772

773+
exit_unlock:
749774
mutex_unlock(&priv->command_lock);
750775

751776
if (u.buf != priv->command_buffer)

0 commit comments

Comments
 (0)