Skip to content

Commit

Permalink
net: qrtr: Fix an out of bounds read qrtr_endpoint_post()
Browse files Browse the repository at this point in the history
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: Manivannan Sadhasivam <[email protected]>
Reported-by: [email protected]
Fixes: 194ccc8 ("net: qrtr: Support decoding incoming v2 packets")
Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Dan Carpenter authored and davem330 committed Jul 1, 2020
1 parent 6a2febe commit 8ff41cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/qrtr/qrtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
unsigned int ver;
size_t hdrlen;

if (len & 3)
if (len == 0 || len & 3)
return -EINVAL;

skb = netdev_alloc_skb(NULL, len);
Expand All @@ -443,6 +443,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)

switch (ver) {
case QRTR_PROTO_VER_1:
if (len < sizeof(*v1))
goto err;
v1 = data;
hdrlen = sizeof(*v1);

Expand All @@ -456,6 +458,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
size = le32_to_cpu(v1->size);
break;
case QRTR_PROTO_VER_2:
if (len < sizeof(*v2))
goto err;
v2 = data;
hdrlen = sizeof(*v2) + v2->optlen;

Expand Down

0 comments on commit 8ff41cc

Please sign in to comment.