Skip to content

Commit

Permalink
Application-supplied buffer addresses not checked for validity
Browse files Browse the repository at this point in the history
Code must check for valid buffer address to avoid potential corruption
Signed-off-by: Tammy Leino <[email protected]>
  • Loading branch information
tammyleino committed Oct 4, 2022
1 parent afed3bd commit a30441c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,14 @@ static int _rpmsg_virtio_get_buffer_size(struct rpmsg_virtio_device *rvdev)

static void rpmsg_virtio_hold_rx_buffer(struct rpmsg_device *rdev, void *rxbuf)
{
struct rpmsg_virtio_device *rvdev;
struct rpmsg_hdr *rp_hdr;

(void)rdev;
rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

if (!metal_io_is_block_valid(rvdev->rvq->shm_io, sizeof(struct rpmsg_hdr),
rxbuf, 0))
return;

rp_hdr = RPMSG_LOCATE_HDR(rxbuf);

Expand All @@ -307,6 +312,11 @@ static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev,
uint32_t len;

rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

if (!metal_io_is_block_valid(rvdev->rvq->shm_io, sizeof(struct rpmsg_hdr),
rxbuf, 0))
return;

rp_hdr = RPMSG_LOCATE_HDR(rxbuf);
/* The reserved field contains buffer index */
idx = (uint16_t)(rp_hdr->reserved & ~RPMSG_BUF_HELD);
Expand Down Expand Up @@ -377,6 +387,10 @@ static int rpmsg_virtio_send_offchannel_nocopy(struct rpmsg_device *rdev,
/* Get the associated remote device for channel. */
rvdev = metal_container_of(rdev, struct rpmsg_virtio_device, rdev);

if (!metal_io_is_block_valid(rvdev->rvq->shm_io, sizeof(struct rpmsg_hdr),
data, len))
return RPMSG_ERR_PARAM;

hdr = RPMSG_LOCATE_HDR(data);
/* The reserved field contains buffer index */
idx = hdr->reserved;
Expand Down

0 comments on commit a30441c

Please sign in to comment.