Skip to content

Commit

Permalink
net: qrtr: make checks in qrtr_endpoint_post() stricter
Browse files Browse the repository at this point in the history
[ Upstream commit aaa8e49 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed Sep 15, 2021
1 parent 5ae0621 commit 02f8b42
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions net/qrtr/qrtr.c
Expand Up @@ -493,7 +493,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
goto err;
}

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

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

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

if (size < sizeof(*pkt))
goto err;

pkt = data + hdrlen;
qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
}

Expand Down

0 comments on commit 02f8b42

Please sign in to comment.