Skip to content

Commit 8f5a695

Browse files
committed
xen/blkfront: don't take local copy of a request from the ring page
In order to avoid a malicious backend being able to influence the local copy of a request build the request locally first and then copy it to the ring page instead of doing it the other way round as today. Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Jan Beulich <jbeulich@suse.com> Acked-by: Roger Pau Monné <roger.pau@citrix.com> Link: https://lore.kernel.org/r/20210730103854.12681-3-jgross@suse.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 71b6624 commit 8f5a695

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

drivers/block/xen-blkfront.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -533,19 +533,20 @@ static unsigned long blkif_ring_get_request(struct blkfront_ring_info *rinfo,
533533
rinfo->shadow[id].status = REQ_WAITING;
534534
rinfo->shadow[id].associated_id = NO_ASSOCIATED_ID;
535535

536-
(*ring_req)->u.rw.id = id;
536+
rinfo->shadow[id].req.u.rw.id = id;
537537

538538
return id;
539539
}
540540

541541
static int blkif_queue_discard_req(struct request *req, struct blkfront_ring_info *rinfo)
542542
{
543543
struct blkfront_info *info = rinfo->dev_info;
544-
struct blkif_request *ring_req;
544+
struct blkif_request *ring_req, *final_ring_req;
545545
unsigned long id;
546546

547547
/* Fill out a communications ring structure. */
548-
id = blkif_ring_get_request(rinfo, req, &ring_req);
548+
id = blkif_ring_get_request(rinfo, req, &final_ring_req);
549+
ring_req = &rinfo->shadow[id].req;
549550

550551
ring_req->operation = BLKIF_OP_DISCARD;
551552
ring_req->u.discard.nr_sectors = blk_rq_sectors(req);
@@ -556,8 +557,8 @@ static int blkif_queue_discard_req(struct request *req, struct blkfront_ring_inf
556557
else
557558
ring_req->u.discard.flag = 0;
558559

559-
/* Keep a private copy so we can reissue requests when recovering. */
560-
rinfo->shadow[id].req = *ring_req;
560+
/* Copy the request to the ring page. */
561+
*final_ring_req = *ring_req;
561562

562563
return 0;
563564
}
@@ -690,6 +691,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
690691
{
691692
struct blkfront_info *info = rinfo->dev_info;
692693
struct blkif_request *ring_req, *extra_ring_req = NULL;
694+
struct blkif_request *final_ring_req, *final_extra_ring_req = NULL;
693695
unsigned long id, extra_id = NO_ASSOCIATED_ID;
694696
bool require_extra_req = false;
695697
int i;
@@ -734,7 +736,8 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
734736
}
735737

736738
/* Fill out a communications ring structure. */
737-
id = blkif_ring_get_request(rinfo, req, &ring_req);
739+
id = blkif_ring_get_request(rinfo, req, &final_ring_req);
740+
ring_req = &rinfo->shadow[id].req;
738741

739742
num_sg = blk_rq_map_sg(req->q, req, rinfo->shadow[id].sg);
740743
num_grant = 0;
@@ -785,7 +788,9 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
785788
ring_req->u.rw.nr_segments = num_grant;
786789
if (unlikely(require_extra_req)) {
787790
extra_id = blkif_ring_get_request(rinfo, req,
788-
&extra_ring_req);
791+
&final_extra_ring_req);
792+
extra_ring_req = &rinfo->shadow[extra_id].req;
793+
789794
/*
790795
* Only the first request contains the scatter-gather
791796
* list.
@@ -827,10 +832,10 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
827832
if (setup.segments)
828833
kunmap_atomic(setup.segments);
829834

830-
/* Keep a private copy so we can reissue requests when recovering. */
831-
rinfo->shadow[id].req = *ring_req;
835+
/* Copy request(s) to the ring page. */
836+
*final_ring_req = *ring_req;
832837
if (unlikely(require_extra_req))
833-
rinfo->shadow[extra_id].req = *extra_ring_req;
838+
*final_extra_ring_req = *extra_ring_req;
834839

835840
if (new_persistent_gnts)
836841
gnttab_free_grant_references(setup.gref_head);

0 commit comments

Comments
 (0)