freerdp: patch CVE-2023-39351
PATCH 1/5 freerdp: patch CVE-2023-39351
Details: https://nvd.nist.gov/vuln/detail/CVE-2023-39351
Pick the patch that is mentioned by Debian[1] to solve the problem.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-39351
--- .../freerdp/freerdp/CVE-2023-39351.patch | 30 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 31 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39351.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39351.patch new file +30 -0
@@ -0,0 +1,30 @@ +From 4a6475e50797218dec507f75477d6c047b14e9f6 Mon Sep 17 00:00:00 2001 +From: Armin Novak <[email protected]> +Date: Sat, 5 Aug 2023 09:29:19 +0200 +Subject: [PATCH] free content of currentMessage on fail + +(cherry picked from commit e17ee48065d1ebcf863e8d0421cd656c4ef04d41) + +CVE: CVE-2023-39351 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/99e243cdbc31f66b5c917452c8fed3276e8bdcd5] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/rfx.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c +index 8c65e7508..3001f71bd 100644 +--- a/libfreerdp/codec/rfx.c ++++ b/libfreerdp/codec/rfx.c +@@ -1225,6 +1225,11 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length, + region16_uninit(&clippingRects); + return TRUE; + } ++ else ++ { ++ rfx_message_free(context, message); ++ context->currentMessage.freeArray = TRUE; ++ } + + return FALSE; + }
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -22,6 +22,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2022-39282.patch \ file://CVE-2022-39320.patch \ file://CVE-2023-39350.patch \ + file://CVE-2023-39351.patch \ " S = "${WORKDIR}/git"
PATCH 2/5 freerdp: patch CVE-2023-39352
Details: https://nvd.nist.gov/vuln/detail/CVE-2023-39352
Backport the commit that was identified[1] by Debian as the solution.
Note: WINPR_ASSERT macro calls have been changed to assert calls, as this macro doesn't exist yet in this version. Looking at the implementation[2], it is basically an assert call with a bit verbose logs.
Even though the original implementation also defines a no-op version, the assert version is enabled by default.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-39352
[2]: https://github.com/FreeRDP/FreeRDP/blob/2.11.0/winpr/include/winpr/assert.h#L31
--- .../freerdp/freerdp/CVE-2023-39352.patch | 124 ++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 125 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39352.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39352.patch new file +124 -0
@@ -0,0 +1,124 @@ +From 5fbd3aa27780d4c1e4610d1e5f1515f50fc3674b Mon Sep 17 00:00:00 2001 +From: Gyorgy Sarvari <[email protected]> +Date: Mon, 22 May 2023 16:03:54 +0800 +Subject: [PATCH] add bound check in gdi_SolidFill + +From: houchengqiu <[email protected]> + +In Windows remote run vulnerabillities exe program, to create +Micorosoft::Windows::RDS::Graphics channel, case Remmina crash. +So, add bound check, limit the size of the requested rect, no larger than the surface data buffer. + +(cherry picked from commit 6a63441e4ee8e2bf333361f5d24156a183b14ecd) + +CVE: CVE-2023-39352 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/856ecaa463e963ecfebc9734423d69139e7b3916] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/gdi/gfx.c | 70 ++++++++++++++++++++++++++++---------------- + 1 file changed, 45 insertions(+), 25 deletions(-) + +diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c +index a3b7505c5..d2ca9cb63 100644 +--- a/libfreerdp/gdi/gfx.c ++++ b/libfreerdp/gdi/gfx.c +@@ -25,6 +25,8 @@ + + #include "../core/update.h" + ++#include <assert.h> ++ + #include <freerdp/log.h> + #include <freerdp/gdi/gfx.h> + #include <freerdp/gdi/region.h> +@@ -1079,6 +1081,28 @@ static UINT gdi_DeleteSurface(RdpgfxClientContext* context, + return rc; + } + ++static BOOL intersect_rect(const RECTANGLE_16* rect, const gdiGfxSurface* surface, ++ RECTANGLE_16* prect) ++{ ++ assert((rect) && "Assert fail: rect"); ++ assert((surface) && "Assert fail: surface"); ++ assert((prect) && "Assert fail: prect"); ++ ++ if (rect->left > rect->right) ++ return FALSE; ++ if (rect->left > surface->width) ++ return FALSE; ++ if (rect->top > rect->bottom) ++ return FALSE; ++ if (rect->top > surface->height) ++ return FALSE; ++ prect->left = rect->left; ++ prect->top = rect->top; ++ prect->right = MIN(rect->right, surface->width); ++ prect->bottom = MIN(rect->bottom, surface->height); ++ return TRUE; ++} ++ + /** + * Function description + * +@@ -1087,40 +1111,36 @@ static UINT gdi_DeleteSurface(RdpgfxClientContext* context, + static UINT gdi_SolidFill(RdpgfxClientContext* context, const RDPGFX_SOLID_FILL_PDU* solidFill) + { + UINT status = ERROR_INTERNAL_ERROR; +- UINT16 index; +- UINT32 color; +- BYTE a, r, g, b; +- UINT32 nWidth, nHeight; +- RECTANGLE_16* rect; +- gdiGfxSurface* surface; +- RECTANGLE_16 invalidRect; ++ BYTE a = 0; ++ RECTANGLE_16 invalidRect = { 0 }; + rdpGdi* gdi = (rdpGdi*)context->custom; ++ + EnterCriticalSection(&context->mux); +- surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId); ++ ++ assert((context->GetSurfaceData) && "Assert fail: context->GetSurfaceData"); ++ gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId); + + if (!surface) + goto fail; + +- b = solidFill->fillPixel.B; +- g = solidFill->fillPixel.G; +- r = solidFill->fillPixel.R; +- /* a = solidFill->fillPixel.XA; +- * Ignore alpha channel, this is a solid fill. */ ++ const BYTE b = solidFill->fillPixel.B; ++ const BYTE g = solidFill->fillPixel.G; ++ const BYTE r = solidFill->fillPixel.R; + a = 0xFF; +- color = FreeRDPGetColor(surface->format, r, g, b, a); ++ const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a); + +- for (index = 0; index < solidFill->fillRectCount; index++) ++ for (UINT16 index = 0; index < solidFill->fillRectCount; index++) + { +- rect = &(solidFill->fillRects[index]); +- nWidth = rect->right - rect->left; +- nHeight = rect->bottom - rect->top; +- invalidRect.left = rect->left; +- invalidRect.top = rect->top; +- invalidRect.right = rect->right; +- invalidRect.bottom = rect->bottom; +- +- if (!freerdp_image_fill(surface->data, surface->format, surface->scanline, rect->left, +- rect->top, nWidth, nHeight, color)) ++ const RECTANGLE_16* rect = &(solidFill->fillRects[index]); ++ ++ if (!intersect_rect(rect, surface, &invalidRect)) ++ goto fail; ++ ++ const UINT32 nWidth = invalidRect.right - invalidRect.left; ++ const UINT32 nHeight = invalidRect.bottom - invalidRect.top; ++ ++ if (!freerdp_image_fill(surface->data, surface->format, surface->scanline, invalidRect.left, ++ invalidRect.top, nWidth, nHeight, color)) + goto fail; + + region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -23,6 +23,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2022-39320.patch \ file://CVE-2023-39350.patch \ file://CVE-2023-39351.patch \ + file://CVE-2023-39352.patch \ " S = "${WORKDIR}/git"
PATCH 3/5 freerdp: patch CVE-2023-39353
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2023-39353
Pick the patch that was identified[1] by Debian as the solution.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-39353
--- .../freerdp/freerdp/CVE-2023-39353.patch | 53 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 54 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39353.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-39353.patch new file +53 -0
@@ -0,0 +1,53 @@ +From 944994cb41d62ea893bd8bdaf436e97f42965de0 Mon Sep 17 00:00:00 2001 +From: Armin Novak <[email protected]> +Date: Sat, 5 Aug 2023 08:57:28 +0200 +Subject: [PATCH] check indices are within range + +reported by pwn2carr + +CVE: CVE-2023-39353 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/e204fc8be5a372626b13f66daf2abafe71dbc2dc] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/rfx.c | 25 ++++++++++++++++++++++++- + 1 file changed, 24 insertions(+), 1 deletion(-) + +diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c +index 8c65e7508..998a7aa56 100644 +--- a/libfreerdp/codec/rfx.c ++++ b/libfreerdp/codec/rfx.c +@@ -932,10 +932,33 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa + rc = FALSE; + break; + } +- + Stream_Read_UINT8(&sub, tile->quantIdxY); /* quantIdxY (1 byte) */ + Stream_Read_UINT8(&sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */ + Stream_Read_UINT8(&sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */ ++ if (tile->quantIdxY >= context->numQuant) ++ { ++ WLog_Print(context->priv->log, WLOG_ERROR, ++ "quantIdxY %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxY, ++ context->numQuant); ++ rc = FALSE; ++ break; ++ } ++ if (tile->quantIdxCb >= context->numQuant) ++ { ++ WLog_Print(context->priv->log, WLOG_ERROR, ++ "quantIdxCb %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxCb, ++ context->numQuant); ++ rc = FALSE; ++ break; ++ } ++ if (tile->quantIdxCr >= context->numQuant) ++ { ++ WLog_Print(context->priv->log, WLOG_ERROR, ++ "quantIdxCr %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxCr, ++ context->numQuant); ++ rc = FALSE; ++ break; ++ } + Stream_Read_UINT16(&sub, tile->xIdx); /* xIdx (2 bytes) */ + Stream_Read_UINT16(&sub, tile->yIdx); /* yIdx (2 bytes) */ + Stream_Read_UINT16(&sub, tile->YLen); /* YLen (2 bytes) */
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -24,6 +24,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-39350.patch \ file://CVE-2023-39351.patch \ file://CVE-2023-39352.patch \ + file://CVE-2023-39353.patch \ " S = "${WORKDIR}/git"
PATCH 4/5 freerdp: patch CVE-2023-40181
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2023-40181
Pick the patch that was identified[1] by Debian as the solution.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-40181
--- .../freerdp/freerdp/CVE-2023-40181.patch | 33 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 34 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40181.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40181.patch new file +33 -0
@@ -0,0 +1,33 @@ +From de011238a720cf80a7f96ee0d7a43d85fbc0552f Mon Sep 17 00:00:00 2001 +From: Armin Novak <[email protected]> +Date: Mon, 21 Aug 2023 14:30:11 +0200 +Subject: [PATCH] fix cBitsRemaining calculation + +fixed out of bound read reported by @pwn2carr + +(cherry picked from commit c39c82277a73332e9c1b64db98a34559f424fe20) + +CVE: CVE-2023-40181 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/c23cbdc4a5756bd723223c7139654de7439fdcc0] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/zgfx.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/libfreerdp/codec/zgfx.c b/libfreerdp/codec/zgfx.c +index 04ddeadb2..4489b3798 100644 +--- a/libfreerdp/codec/zgfx.c ++++ b/libfreerdp/codec/zgfx.c +@@ -259,7 +259,11 @@ static BOOL zgfx_decompress_segment(ZGFX_CONTEXT* zgfx, wStream* stream, size_t + zgfx->pbInputCurrent = pbSegment; + zgfx->pbInputEnd = &pbSegment[cbSegment - 1]; + /* NumberOfBitsToDecode = ((NumberOfBytesToDecode - 1) * 8) - ValueOfLastByte */ +- zgfx->cBitsRemaining = 8 * (cbSegment - 1) - *zgfx->pbInputEnd; ++ const UINT32 bits = 8u * (cbSegment - 1u); ++ if (bits < *zgfx->pbInputEnd) ++ return FALSE; ++ ++ zgfx->cBitsRemaining = bits - *zgfx->pbInputEnd; + zgfx->cBitsCurrent = 0; + zgfx->BitsCurrent = 0; +
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -25,6 +25,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-39351.patch \ file://CVE-2023-39352.patch \ file://CVE-2023-39353.patch \ + file://CVE-2023-40181.patch \ " S = "${WORKDIR}/git"
PATCH 5/5 freerdp: patch CVE-2023-40569
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2023-40569
Pick the patch that was identified[1] by Debian as the solution.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-40569
--- .../freerdp/freerdp/CVE-2023-40569.patch | 38 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 39 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40569.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40569.patch new file +38 -0
@@ -0,0 +1,38 @@ +From acc25a2257a960c82adea14faf48730c9139811d Mon Sep 17 00:00:00 2001 +From: akallabeth <[email protected]> +Date: Tue, 22 Aug 2023 15:05:20 +0200 +Subject: [PATCH] fix missing destination checks + +(cherry picked from commit ef7e0d60c207dae478952d795e74751d1516629d) + +CVE: CVE-2023-40569 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/23c3daeca1598393f8c93f563f7847a4d67919f1] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/progressive.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c +index 60343b881..a30da6201 100644 +--- a/libfreerdp/codec/progressive.c ++++ b/libfreerdp/codec/progressive.c +@@ -2425,11 +2425,17 @@ INT32 progressive_decompress_ex(PROGRESSIVE_CONTEXT* progressive, const BYTE* pS + for (j = 0; j < nbUpdateRects; j++) + { + const RECTANGLE_16* rect = &updateRects[j]; +- const UINT32 nXSrc = rect->left - (nXDst + tile->x); +- const UINT32 nYSrc = rect->top - (nYDst + tile->y); ++ if (rect->left < updateRect.left) ++ goto fail; ++ const UINT32 nXSrc = rect->left - updateRect.left; ++ const UINT32 nYSrc = rect->top - updateRect.top; + const UINT32 width = rect->right - rect->left; + const UINT32 height = rect->bottom - rect->top; + ++ if (rect->left + width > surface->width) ++ goto fail; ++ if (rect->top + height > surface->height) ++ goto fail; + if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, rect->left, rect->top, width, + height, tile->data, progressive->format, tile->stride, nXSrc, + nYSrc, NULL, FREERDP_FLIP_NONE))
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -26,6 +26,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-39352.patch \ file://CVE-2023-39353.patch \ file://CVE-2023-40181.patch \ + file://CVE-2023-40569.patch \ " S = "${WORKDIR}/git"