Commit 8ff41cc2 authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

net: qrtr: Fix an out of bounds read qrtr_endpoint_post()

This code assumes that the user passed in enough data for a
qrtr_hdr_v1 or qrtr_hdr_v2 struct, but it's not necessarily true.  If
the buffer is too small then it will read beyond the end.
Reported-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reported-by: syzbot+b8fe393f999a291a9ea6@syzkaller.appspotmail.com
Fixes: 194ccc88 ("net: qrtr: Support decoding incoming v2 packets")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6a2febec
...@@ -429,7 +429,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) ...@@ -429,7 +429,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
unsigned int ver; unsigned int ver;
size_t hdrlen; size_t hdrlen;
if (len & 3) if (len == 0 || len & 3)
return -EINVAL; return -EINVAL;
skb = netdev_alloc_skb(NULL, len); skb = netdev_alloc_skb(NULL, len);
...@@ -443,6 +443,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) ...@@ -443,6 +443,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
switch (ver) { switch (ver) {
case QRTR_PROTO_VER_1: case QRTR_PROTO_VER_1:
if (len < sizeof(*v1))
goto err;
v1 = data; v1 = data;
hdrlen = sizeof(*v1); hdrlen = sizeof(*v1);
...@@ -456,6 +458,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) ...@@ -456,6 +458,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
size = le32_to_cpu(v1->size); size = le32_to_cpu(v1->size);
break; break;
case QRTR_PROTO_VER_2: case QRTR_PROTO_VER_2:
if (len < sizeof(*v2))
goto err;
v2 = data; v2 = data;
hdrlen = sizeof(*v2) + v2->optlen; hdrlen = sizeof(*v2) + v2->optlen;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment