]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: qrtr: make checks in qrtr_endpoint_post() stricter
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 30 Aug 2021 08:37:17 +0000 (11:37 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 15 Oct 2021 09:27:46 +0000 (11:27 +0200)
BugLink: https://bugs.launchpad.net/bugs/1946788
[ Upstream commit aaa8e4922c887ff47ad66ef918193682bccc1905 ]

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: 0baa99ee353c ("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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
net/qrtr/qrtr.c

index 7d79d2004b13330beb65f4f27e3a17d00df21c65..626fc23c5e6c2717df03740e1c1e50ce2b6e235d 100644 (file)
@@ -492,7 +492,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 &&
@@ -505,8 +505,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));
        }