Skip to content

Commit

Permalink
xen/disk: don't leak stack data via response ring
Browse files Browse the repository at this point in the history
Rather than constructing a local structure instance on the stack, fill
the fields directly on the shared ring, just like other (Linux)
backends do. Build on the fact that all response structure flavors are
actually identical (aside from alignment and padding at the end).

This is XSA-216.

Reported by: Anthony Perard <anthony.perard@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
  • Loading branch information
sstabellini committed Jun 27, 2017
1 parent 577caa2 commit b0ac694
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions hw/block/xen_disk.c
Expand Up @@ -769,31 +769,30 @@ static int blk_send_response_one(struct ioreq *ioreq)
struct XenBlkDev *blkdev = ioreq->blkdev;
int send_notify = 0;
int have_requests = 0;
blkif_response_t resp;
void *dst;

resp.id = ioreq->req.id;
resp.operation = ioreq->req.operation;
resp.status = ioreq->status;
blkif_response_t *resp;

/* Place on the response ring for the relevant domain. */
switch (blkdev->protocol) {
case BLKIF_PROTOCOL_NATIVE:
dst = RING_GET_RESPONSE(&blkdev->rings.native, blkdev->rings.native.rsp_prod_pvt);
resp = (blkif_response_t *) RING_GET_RESPONSE(&blkdev->rings.native,
blkdev->rings.native.rsp_prod_pvt);
break;
case BLKIF_PROTOCOL_X86_32:
dst = RING_GET_RESPONSE(&blkdev->rings.x86_32_part,
blkdev->rings.x86_32_part.rsp_prod_pvt);
resp = (blkif_response_t *) RING_GET_RESPONSE(&blkdev->rings.x86_32_part,
blkdev->rings.x86_32_part.rsp_prod_pvt);
break;
case BLKIF_PROTOCOL_X86_64:
dst = RING_GET_RESPONSE(&blkdev->rings.x86_64_part,
blkdev->rings.x86_64_part.rsp_prod_pvt);
resp = (blkif_response_t *) RING_GET_RESPONSE(&blkdev->rings.x86_64_part,
blkdev->rings.x86_64_part.rsp_prod_pvt);
break;
default:
dst = NULL;
return 0;
}
memcpy(dst, &resp, sizeof(resp));

resp->id = ioreq->req.id;
resp->operation = ioreq->req.operation;
resp->status = ioreq->status;

blkdev->rings.common.rsp_prod_pvt++;

RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blkdev->rings.common, send_notify);
Expand Down

0 comments on commit b0ac694

Please sign in to comment.