From nobody Sat Nov 30 00:51:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1620900222; cv=none; d=zohomail.com; s=zohoarc; b=SW9CDKaY14V+/d0mTcJU0yzpXTaiQbWyRxCm9pkggDe0bPd0d8WOJweBeC3/XivW5aGpFYjaFD9rOe6Q/L8Z1hmdolhouuryENPUIaJ8r72CrFIh2IA8Xhb2Qxu35sbAiji/ftplMBmSwblKinZfkv8dEWSX1skIi/iio8stcsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620900222; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0Q6ThoS9c4shqaPBcM7YVpxtTsCqScDLVsepBzmlgCI=; b=jIt39MgNQhrSIgoVfLhXN4idZgRKoQJhZrycD0FsXh2zAa/VK9eETIk28bLrN3XAPpvn8fpkvjKZ2bTZNO36CbRu1IVbnQHHFCMUZ6jPboK5SH13iut1abYtSWWXDO4qFCj8mveQzD4MQg3DOGlyMu4rSulyESa3IT7fAmvUtMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620900222336509.6309138216784; Thu, 13 May 2021 03:03:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.126809.238320 (Exim 4.92) (envelope-from ) id 1lh8Ba-0005B6-DM; Thu, 13 May 2021 10:03:18 +0000 Received: by outflank-mailman (output) from mailman id 126809.238320; Thu, 13 May 2021 10:03:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lh8Ba-0005Ar-9m; Thu, 13 May 2021 10:03:18 +0000 Received: by outflank-mailman (input) for mailman id 126809; Thu, 13 May 2021 10:03:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lh8BZ-0003vg-34 for xen-devel@lists.xenproject.org; Thu, 13 May 2021 10:03:17 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1c7d2393-cef0-489a-a074-21fe2b426a38; Thu, 13 May 2021 10:03:06 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EB135AFF6; Thu, 13 May 2021 10:03:05 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1c7d2393-cef0-489a-a074-21fe2b426a38 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1620900186; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Q6ThoS9c4shqaPBcM7YVpxtTsCqScDLVsepBzmlgCI=; b=KB4VO2b29rr8hcdZZAjHAppb7tKug2TKs7hwZV1cULAeBgNVDz9y3rAzxIUyt8uz4zhN1m wbkrBEc19J6BDwt9BDdkNjqE7EkKbsb19lj8El+kyBKqof1o5TWtGOxWrVw6bpy14oUpOL hA7SOkSFBinvHJbDqRzyWiVv2QpDJHA= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe Subject: [PATCH 3/8] xen/blkfront: don't take local copy of a request from the ring page Date: Thu, 13 May 2021 12:02:57 +0200 Message-Id: <20210513100302.22027-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210513100302.22027-1-jgross@suse.com> References: <20210513100302.22027-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Jan Beulich --- drivers/block/xen-blkfront.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index a8b56c153330..c6a05de4f15f 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -546,7 +546,7 @@ static unsigned long blkif_ring_get_request(struct blkf= ront_ring_info *rinfo, rinfo->shadow[id].status =3D REQ_WAITING; rinfo->shadow[id].associated_id =3D NO_ASSOCIATED_ID; =20 - (*ring_req)->u.rw.id =3D id; + rinfo->shadow[id].req.u.rw.id =3D id; =20 return id; } @@ -554,11 +554,12 @@ static unsigned long blkif_ring_get_request(struct bl= kfront_ring_info *rinfo, static int blkif_queue_discard_req(struct request *req, struct blkfront_ri= ng_info *rinfo) { struct blkfront_info *info =3D rinfo->dev_info; - struct blkif_request *ring_req; + struct blkif_request *ring_req, *final_ring_req; unsigned long id; =20 /* Fill out a communications ring structure. */ - id =3D blkif_ring_get_request(rinfo, req, &ring_req); + id =3D blkif_ring_get_request(rinfo, req, &final_ring_req); + ring_req =3D &rinfo->shadow[id].req; =20 ring_req->operation =3D BLKIF_OP_DISCARD; ring_req->u.discard.nr_sectors =3D blk_rq_sectors(req); @@ -569,8 +570,8 @@ static int blkif_queue_discard_req(struct request *req,= struct blkfront_ring_inf else ring_req->u.discard.flag =3D 0; =20 - /* Keep a private copy so we can reissue requests when recovering. */ - rinfo->shadow[id].req =3D *ring_req; + /* Copy the request to the ring page. */ + *final_ring_req =3D *ring_req; =20 return 0; } @@ -703,6 +704,7 @@ static int blkif_queue_rw_req(struct request *req, stru= ct blkfront_ring_info *ri { struct blkfront_info *info =3D rinfo->dev_info; struct blkif_request *ring_req, *extra_ring_req =3D NULL; + struct blkif_request *final_ring_req, *final_extra_ring_req; unsigned long id, extra_id =3D NO_ASSOCIATED_ID; bool require_extra_req =3D false; int i; @@ -747,7 +749,8 @@ static int blkif_queue_rw_req(struct request *req, stru= ct blkfront_ring_info *ri } =20 /* Fill out a communications ring structure. */ - id =3D blkif_ring_get_request(rinfo, req, &ring_req); + id =3D blkif_ring_get_request(rinfo, req, &final_ring_req); + ring_req =3D &rinfo->shadow[id].req; =20 num_sg =3D blk_rq_map_sg(req->q, req, rinfo->shadow[id].sg); num_grant =3D 0; @@ -798,7 +801,9 @@ static int blkif_queue_rw_req(struct request *req, stru= ct blkfront_ring_info *ri ring_req->u.rw.nr_segments =3D num_grant; if (unlikely(require_extra_req)) { extra_id =3D blkif_ring_get_request(rinfo, req, - &extra_ring_req); + &final_extra_ring_req); + extra_ring_req =3D &rinfo->shadow[extra_id].req; + /* * Only the first request contains the scatter-gather * list. @@ -840,10 +845,10 @@ static int blkif_queue_rw_req(struct request *req, st= ruct blkfront_ring_info *ri if (setup.segments) kunmap_atomic(setup.segments); =20 - /* Keep a private copy so we can reissue requests when recovering. */ - rinfo->shadow[id].req =3D *ring_req; + /* Copy request(s) to the ring page. */ + *final_ring_req =3D *ring_req; if (unlikely(require_extra_req)) - rinfo->shadow[extra_id].req =3D *extra_ring_req; + *final_extra_ring_req =3D *extra_ring_req; =20 if (new_persistent_gnts) gnttab_free_grant_references(setup.gref_head); --=20 2.26.2