Skip to content

Commit aaa8e49

Browse files
Dan Carpenterdavem330
authored andcommitted
net: qrtr: make checks in qrtr_endpoint_post() stricter
These checks are still not strict enough. The main problem is that if "cb->type == QRTR_TYPE_NEW_SERVER" is true then "len - hdrlen" is guaranteed to be 4 but we need to be at least 16 bytes. In fact, we can reject everything smaller than sizeof(*pkt) which is 20 bytes. Also I don't like the ALIGN(size, 4). It's better to just insist that data is needs to be aligned at the start. Fixes: 0baa99e ("net: qrtr: Allow non-immediate node routing") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent efe487f commit aaa8e49

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎net/qrtr/qrtr.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
493493
goto err;
494494
}
495495

496-
if (!size || len != ALIGN(size, 4) + hdrlen)
496+
if (!size || size & 3 || len != size + hdrlen)
497497
goto err;
498498

499499
if (cb->dst_port != QRTR_PORT_CTRL && cb->type != QRTR_TYPE_DATA &&
@@ -506,8 +506,12 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
506506

507507
if (cb->type == QRTR_TYPE_NEW_SERVER) {
508508
/* Remote node endpoint can bridge other distant nodes */
509-
const struct qrtr_ctrl_pkt *pkt = data + hdrlen;
509+
const struct qrtr_ctrl_pkt *pkt;
510510

511+
if (size < sizeof(*pkt))
512+
goto err;
513+
514+
pkt = data + hdrlen;
511515
qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
512516
}
513517

0 commit comments

Comments
 (0)