Merge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[deliverable/linux.git] / drivers / rpmsg / virtio_rpmsg_bus.c
index 4db9cf8754a0e211ba4cc1900540e99add01b46b..75506ec2840e2ec4d1e331f209377d874f604386 100644 (file)
@@ -778,6 +778,16 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
        print_hex_dump(KERN_DEBUG, "rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
                                        msg, sizeof(*msg) + msg->len, true);
 
+       /*
+        * We currently use fixed-sized buffers, so trivially sanitize
+        * the reported payload length.
+        */
+       if (len > RPMSG_BUF_SIZE ||
+               msg->len > (len - sizeof(struct rpmsg_hdr))) {
+               dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
+               return;
+       }
+
        /* use the dst addr to fetch the callback of the appropriate user */
        mutex_lock(&vrp->endpoints_lock);
        ept = idr_find(&vrp->endpoints, msg->dst);
@@ -788,7 +798,8 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
        else
                dev_warn(dev, "msg received with no recepient\n");
 
-       sg_init_one(&sg, msg, sizeof(*msg) + len);
+       /* publish the real size of the buffer */
+       sg_init_one(&sg, msg, RPMSG_BUF_SIZE);
 
        /* add the buffer back to the remote processor's virtqueue */
        err = virtqueue_add_buf(vrp->rvq, &sg, 0, 1, msg, GFP_KERNEL);
@@ -905,8 +916,8 @@ static int rpmsg_probe(struct virtio_device *vdev)
        if (!bufs_va)
                goto vqs_del;
 
-       dev_dbg(&vdev->dev, "buffers: va %p, dma 0x%x\n", bufs_va,
-                                               vrp->bufs_dma);
+       dev_dbg(&vdev->dev, "buffers: va %p, dma 0x%llx\n", bufs_va,
+                                       (unsigned long long)vrp->bufs_dma);
 
        /* half of the buffers is dedicated for RX */
        vrp->rbufs = bufs_va;
This page took 0.029756 seconds and 5 git commands to generate.