From nobody Sat Feb 7 05:01:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47217+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1568386271; cv=none; d=zoho.com; s=zohoarc; b=ifBteeliprQkiFAv7im6vdfUkK/rBoqxoxdWpzPMhlO0TV/XKnfWe+ol2lpmw1GrLdIyeuBWRPL22xhiWAe99iFukiDIEzbDRHKE18J6C6VoTCo0XWe43bZI2f+S2R+mCh1shbv/DHJbL9sIQLKitcdM1rit4AwDHjXUOsqOfbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568386271; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=8YlGZk6oUzcsItAxxqQ1v6EuId4ETYPKEHnzYprluas=; b=Nt6psxpeXO1JxJpymgT60RjD16ifSGIc/A5M4tuMZLVqBbsRJuoGoU4JpSRcmtLH8MyWAJ/2vVY6mQmM/lsSsTL17UbmTdy7vFbLJxx6OwXEBFPdrdgz0yfeJTnf318/YXiVaafP29Xj89Znu8W/4TC1l7OxdXUvb27xQNDx8Is= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+47217+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1568386271881353.776140287731; Fri, 13 Sep 2019 07:51:11 -0700 (PDT) Return-Path: X-Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com []) by groups.io with SMTP; Fri, 13 Sep 2019 07:51:10 -0700 Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+47217+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: RuylfgGcqVmDM0HWqFvVTb6r7R49PW+toIafriwtLXe/fADmm1O5dAJePdatTR4U9SIm9LbcdE gqnRK1AopqtGDj6RCQpSsnIqGHjBH008UJeVm7kI5zw4zUOEo1qIw4Zf8x/Mpkj8zxxhKUTaCD BvzooSE052ejgBpepcaq4NAAJS/q9SQAk9yKL46BKmj3k0uhpb7PUKoC3IJd+ETHqy4h08phGI a3PGLOti5/nHeloggWVuWJ3UmjRnDxSf88winG10eO4LAhqdqKj6ufjwZfCjoJnBQflQ0qstyv P1s= X-SBRS: 2.7 X-MesageID: 5595152 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,501,1559534400"; d="scan'208";a="5595152" From: "Anthony PERARD" To: CC: Ard Biesheuvel , Julien Grall , Jordan Justen , , Anthony Perard , Laszlo Ersek Subject: [edk2-devel] [PATCH 08/11] OvmfPkg/XenBus: Change XENBUS_PROTOCOL to not return allocated memory Date: Fri, 13 Sep 2019 15:50:57 +0100 Message-ID: <20190913145100.303433-9-anthony.perard@citrix.com> In-Reply-To: <20190913145100.303433-1-anthony.perard@citrix.com> References: <20190913145100.303433-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,anthony.perard@citrix.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1568386270; bh=8YlGZk6oUzcsItAxxqQ1v6EuId4ETYPKEHnzYprluas=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VDLVyGt+CtPKsJNe9WS0Aada2sAKqGHhNDUVFfvz0jKjnx5g4iF1DqTzpCg/XkRY0ea +z+cM/VzkCBdfPHkM98368b67YH63kblza85zXh2nCySacnn5PefuM8jSj+wKhFvgdMO/ H27vo6t0JIoFJoDliDe0f6Wm9shhcmKpX24= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" XsRead and XsBackendRead of the XENBUS_PROTOCOL return allocated memory but this isn't allowed during the ExitBootServices call. We need XsRead and XsBackendRead to disconnect from the device so XENBUS_PROTOCOL is changed to use a buffer supplied by a child driver. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2190 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- OvmfPkg/Include/Protocol/XenBus.h | 32 ++++++++++++---------- OvmfPkg/XenBusDxe/XenStore.c | 44 +++++------------------------- OvmfPkg/XenBusDxe/XenStore.h | 6 +++-- OvmfPkg/XenPvBlkDxe/BlockFront.c | 45 ++++++++++++++++++------------- 4 files changed, 54 insertions(+), 73 deletions(-) diff --git a/OvmfPkg/Include/Protocol/XenBus.h b/OvmfPkg/Include/Protocol/X= enBus.h index 8ff5ca3575..c22bdfb368 100644 --- a/OvmfPkg/Include/Protocol/XenBus.h +++ b/OvmfPkg/Include/Protocol/XenBus.h @@ -35,6 +35,12 @@ typedef struct =20 #define XST_NIL ((XENSTORE_TRANSACTION *) NULL) =20 +// +// When reading a node from xenstore, if the size of the data to be read is +// unknown, this value can be use for the size of the buffer. +// +#define XENSTORE_PAYLOAD_MAX 4096 + typedef enum { XENSTORE_STATUS_SUCCESS =3D 0, XENSTORE_STATUS_FAIL, @@ -64,19 +70,17 @@ typedef enum { /// =20 /** - Get the contents of the node Node of the PV device. Returns the contents= in - *Result which should be freed after use. + Get the contents of the node Node of the PV device. =20 @param This A pointer to XENBUS_PROTOCOL instance. @param Transaction The XenStore transaction covering this request. @param Node The basename of the file to read. - @param Result The returned contents from this file. + @param BufferSize On input, a pointer to the size of the buffer at B= uffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read wil= l be saved. =20 @return On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value indicating the type of failure. - - @note The results buffer is malloced and should be free'd by the - caller. **/ typedef XENSTORE_STATUS @@ -84,23 +88,22 @@ XENSTORE_STATUS IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 /** - Get the contents of the node Node of the PV device's backend. Returns the - contents in *Result which should be freed after use. + Get the contents of the node Node of the PV device's backend. =20 @param This A pointer to XENBUS_PROTOCOL instance. @param Transaction The XenStore transaction covering this request. @param Node The basename of the file to read. - @param Result The returned contents from this file. + @param BufferSize On input, a pointer to the size of the buffer at B= uffer. + On output, the size of the data written to Buffer. + @param Buffer A pointer to a buffer into which the data read wil= l be saved. =20 @return On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value indicating the type of failure. - - @note The results buffer is malloced and should be free'd by the - caller. **/ typedef XENSTORE_STATUS @@ -108,7 +111,8 @@ XENSTORE_STATUS IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Result + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 /** diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c index b9588bb8c6..cb2d9e1215 100644 --- a/OvmfPkg/XenBusDxe/XenStore.c +++ b/OvmfPkg/XenBusDxe/XenStore.c @@ -1336,27 +1336,11 @@ XenBusXenStoreRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) { - XENSTORE_STATUS Status; - UINTN BufferSize; - VOID *Buffer; - - BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; - Buffer =3D AllocatePool (BufferSize); - if (Buffer =3D=3D NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status =3D XenStoreRead (Transaction, This->Node, Node, &BufferSize, Buf= fer); - - if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { - *Value =3D Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Node, Node, BufferSize, Buffer); } =20 XENSTORE_STATUS @@ -1365,27 +1349,11 @@ XenBusXenStoreBackendRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) { - XENSTORE_STATUS Status; - UINTN BufferSize; - VOID *Buffer; - - BufferSize =3D XENSTORE_PAYLOAD_MAX + 1; - Buffer =3D AllocatePool (BufferSize); - if (Buffer =3D=3D NULL) { - return XENSTORE_STATUS_ENOMEM; - } - - Status =3D XenStoreRead (Transaction, This->Backend, Node, &BufferSize, = Buffer); - - if (Status =3D=3D XENSTORE_STATUS_SUCCESS) { - *Value =3D Buffer; - } else { - FreePool (Buffer); - } - return Status; + return XenStoreRead (Transaction, This->Backend, Node, BufferSize, Buffe= r); } =20 XENSTORE_STATUS diff --git a/OvmfPkg/XenBusDxe/XenStore.h b/OvmfPkg/XenBusDxe/XenStore.h index 13f7d132e6..ca8c080433 100644 --- a/OvmfPkg/XenBusDxe/XenStore.h +++ b/OvmfPkg/XenBusDxe/XenStore.h @@ -289,7 +289,8 @@ XenBusXenStoreRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 XENSTORE_STATUS @@ -298,7 +299,8 @@ XenBusXenStoreBackendRead ( IN XENBUS_PROTOCOL *This, IN CONST XENSTORE_TRANSACTION *Transaction, IN CONST CHAR8 *Node, - OUT VOID **Value + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ); =20 XENSTORE_STATUS diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFr= ont.c index 8dca4c82f0..25a398ccc4 100644 --- a/OvmfPkg/XenPvBlkDxe/BlockFront.c +++ b/OvmfPkg/XenPvBlkDxe/BlockFront.c @@ -41,19 +41,22 @@ XenBusReadUint64 ( ) { XENSTORE_STATUS Status; - CHAR8 *Ptr; + CHAR8 Buffer[22]; + UINTN BufferSize; + + BufferSize =3D sizeof (Buffer) - 1; =20 if (!FromBackend) { - Status =3D This->XsRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status =3D This->XsRead (This, XST_NIL, Node, &BufferSize, Buffer); } else { - Status =3D This->XsBackendRead (This, XST_NIL, Node, (VOID**)&Ptr); + Status =3D This->XsBackendRead (This, XST_NIL, Node, &BufferSize, Buff= er); } if (Status !=3D XENSTORE_STATUS_SUCCESS) { return Status; } + Buffer[BufferSize] =3D '\0'; // AsciiStrDecimalToUint64 will ASSERT if Ptr overflow UINT64. - *ValuePtr =3D AsciiStrDecimalToUint64 (Ptr); - FreePool (Ptr); + *ValuePtr =3D AsciiStrDecimalToUint64 (Buffer); return Status; } =20 @@ -143,43 +146,47 @@ XenPvBlockFrontInitialization ( OUT XEN_BLOCK_FRONT_DEVICE **DevPtr ) { - XENSTORE_TRANSACTION Transaction; - CHAR8 *DeviceType; - blkif_sring_t *SharedRing; - XENSTORE_STATUS Status; + XENSTORE_TRANSACTION Transaction; + CHAR8 Buffer[XENSTORE_PAYLOAD_MAX + 1]; + UINTN BufferSize; + blkif_sring_t *SharedRing; + XENSTORE_STATUS Status; XEN_BLOCK_FRONT_DEVICE *Dev; - XenbusState State; - UINT64 Value; - CHAR8 *Params; + XenbusState State; + UINT64 Value; =20 ASSERT (NodeName !=3D NULL); =20 + BufferSize =3D sizeof (Buffer) - 1; + Dev =3D AllocateZeroPool (sizeof (XEN_BLOCK_FRONT_DEVICE)); Dev->Signature =3D XEN_BLOCK_FRONT_SIGNATURE; Dev->NodeName =3D NodeName; Dev->XenBusIo =3D XenBusIo; Dev->DeviceId =3D XenBusIo->DeviceId; =20 - XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", (VOID**)&DeviceType); - if (AsciiStrCmp (DeviceType, "cdrom") =3D=3D 0) { + BufferSize =3D sizeof (Buffer) - 1; + XenBusIo->XsRead (XenBusIo, XST_NIL, "device-type", &BufferSize, Buffer); + Buffer[BufferSize] =3D '\0'; + if (AsciiStrCmp (Buffer, "cdrom") =3D=3D 0) { Dev->MediaInfo.CdRom =3D TRUE; } else { Dev->MediaInfo.CdRom =3D FALSE; } - FreePool (DeviceType); =20 if (Dev->MediaInfo.CdRom) { - Status =3D XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", (VOID= **)&Params); + BufferSize =3D sizeof (Buffer) - 1; + Status =3D XenBusIo->XsBackendRead (XenBusIo, XST_NIL, "params", + &BufferSize, Buffer); if (Status !=3D XENSTORE_STATUS_SUCCESS) { DEBUG ((EFI_D_ERROR, "%a: Failed to read params (%d)\n", __FUNCTION_= _, Status)); goto Error; } - if (AsciiStrLen (Params) =3D=3D 0 || AsciiStrCmp (Params, "aio:") =3D= =3D 0) { - FreePool (Params); + Buffer[BufferSize] =3D '\0'; + if (AsciiStrLen (Buffer) =3D=3D 0 || AsciiStrCmp (Buffer, "aio:") =3D= =3D 0) { DEBUG ((EFI_D_INFO, "%a: Empty cdrom\n", __FUNCTION__)); goto Error; } - FreePool (Params); } =20 Status =3D XenBusReadUint64 (XenBusIo, "backend-id", FALSE, &Value); --=20 Anthony PERARD -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#47217): https://edk2.groups.io/g/devel/message/47217 Mute This Topic: https://groups.io/mt/34128018/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-