freerdp: add ptest support
PATCH 1/5 freerdp: add ptest support
The tests take about 50s to execute on my machine.
--- .../recipes-support/freerdp/freerdp/run-ptest | 66 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 24 ++++++- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/run-ptest
meta-oe/recipes-support/freerdp/freerdp/run-ptest new file +66 -0
@@ -0,0 +1,66 @@ +#!/bin/sh +#These test cases were determined by running the actual test binary +#which lists all available test cases. Couldn't find a way to just simply +#run all. Also, BusyBox seems to have no associative array support, so +#plain variables are used with eval. +TestAsn="TestAsn1Module TestAsn1Encoder TestAsn1Decoder TestAsn1Encode TestAsn1Decode TestAsn1String TestAsn1Integer TestAsn1Compare TestAsn1BerEnc TestAsn1BerDec TestAsn1DerEnc TestAsn1DerDec" +TestClient="TestClientRdpFile TestClientChannels TestClientCmdLine" +TestClipboard="TestClipboardFormats" +TestCommon="TestCommonAssistance" +TestCore="TestVersion TestSettings" +TestCredUI="TestCredUIParseUserName TestCredUIConfirmCredentials TestCredUIPromptForCredentials TestCredUICmdLinePromptForCredentials" +TestCrt="TestTypes TestFormatSpecifiers TestAlignment TestString TestUnicodeConversion" +TestCrypto="TestCryptoHash TestCryptoRand TestCryptoCipher TestCryptoProtectData TestCryptoProtectMemory TestCryptoCertEnumCertificatesInStore" +TestDsParse="TestDsMakeSpn TestDsCrackNames" +TestEnvironment="TestEnvironmentGetEnvironmentStrings TestEnvironmentSetEnvironmentVariable TestEnvironmentMergeEnvironmentStrings TestEnvironmentGetSetEB" +TestError="TestErrorSetLastError" +TestFile="TestFileCreateFile TestFileDeleteFile TestFileReadFile TestSetFileAttributes TestFileWriteFile TestFilePatternMatch TestFileFindFirstFile TestFileFindFirstFileEx TestFileFindNextFile TestFileGetStdHandle" +TestFreeRDPCodec="TestFreeRDPRegion TestFreeRDPCodecMppc TestFreeRDPCodecNCrush TestFreeRDPCodecXCrush TestFreeRDPCodecZGfx TestFreeRDPCodecPlanar TestFreeRDPCodecClear TestFreeRDPCodecInterleaved TestFreeRDPCodecProgressive TestFreeRDPCodecRemoteFX" +TestFreeRDPCrypto="TestKnownHosts TestBase64 Test_x509_cert_info" +TestFreeRDPUtils="TestRingBuffer" +TestGdi="TestGdiRop3 TestGdiLine TestGdiRegion TestGdiRect TestGdiBitBlt TestGdiCreate TestGdiEllipse TestGdiClip" +TestInterlocked="TestInterlockedAccess TestInterlockedSList TestInterlockedDList" +TestIo="TestIoDevice TestIoGetOverlappedResult" +TestLibrary="TestLibraryLoadLibrary TestLibraryGetProcAddress TestLibraryGetModuleFileName" +TestLocale="TestLocaleFormatMessage" +TestMemory="TestMemoryCreateFileMapping" +TestNt="TestNtCreateFile TestNtCurrentTeb" +TestPath="TestPathCchAddBackslash TestPathCchRemoveBackslash TestPathCchAddBackslashEx TestPathCchRemoveBackslashEx TestPathCchAddExtension TestPathCchAppend TestPathCchAppendEx TestPathCchCanonicalize TestPathCchCanonicalizeEx TestPathAllocCanonicalize TestPathCchCombine TestPathCchCombineEx TestPathAllocCombine TestPathCchFindExtension TestPathCchRenameExtension TestPathCchRemoveExtension TestPathCchIsRoot TestPathIsUNCEx TestPathCchSkipRoot TestPathCchStripToRoot TestPathCchStripPrefix TestPathCchRemoveFileSpec TestPathShell TestPathMakePath" +TestPipe="TestPipeCreatePipe TestPipeCreateNamedPipe TestPipeCreateNamedPipeOverlapped" +TestPool="TestPoolIO TestPoolSynch TestPoolThread TestPoolTimer TestPoolWork" +TestPrimitives="TestPrimitivesAdd TestPrimitivesAlphaComp TestPrimitivesAndOr TestPrimitivesColors TestPrimitivesCopy TestPrimitivesSet TestPrimitivesShift TestPrimitivesSign TestPrimitivesYUV TestPrimitivesYCbCr TestPrimitivesYCoCg" +TestRdTk="TestRdTkNinePatch" +TestSecurity="TestSecurityToken" +TestSmartCard="TestSmartCardListReaders" +TestSspi="TestQuerySecurityPackageInfo TestEnumerateSecurityPackages TestInitializeSecurityContext TestAcquireCredentialsHandle TestCredSSP TestNTLM" +TestSynch="TestSynchInit TestSynchEvent TestSynchMutex TestSynchBarrier TestSynchCritical TestSynchSemaphore TestSynchThread TestSynchMultipleThreads TestSynchTimerQueue TestSynchWaitableTimer TestSynchWaitableTimerAPC TestSynchAPC" +TestSysInfo="TestGetNativeSystemInfo TestCPUFeatures TestGetComputerName TestSystemTime TestLocalTime" +TestThread="TestThreadCommandLineToArgv TestThreadCreateProcess TestThreadExitThread" +TestWinPR="TestIntrinsics TestTypes" +TestWinPRUtils="TestIni TestVersion TestImage TestBipBuffer TestBacktrace TestQueue TestPrint TestPubSub TestStream TestBitStream TestArrayList TestLinkedList TestListDictionary TestCmdLine TestWLog TestWLogCallback TestHashTable TestBufferPool TestStreamPool TestMessageQueue TestMessagePipe" +TestWnd="TestWndCreateWindowEx TestWndWmCopyData" +TestWtsApi="TestWtsApiEnumerateProcesses TestWtsApiEnumerateSessions TestWtsApiQuerySessionInformation TestWtsApiSessionNotification TestWtsApiShutdownSystem TestWtsApiWaitSystemEvent" + +run_test(){ + tc=$(eval "echo \$${1}") + if [ -z "$tc" -o "$tc" = ".so" ]; then + return + fi + + EXTRA_ARG="" + if [ "$1" = "TestFile" ]; then + # this testcase needs an extra argument + EXTRA_ARG="TestFileArea" + fi + + for t in $tc; do + ./$1 $t $EXTRA_ARG > ../${1}_${t}.out && echo PASS: $1 $t || echo FAIL: $1 $t + done +} + + +cd Testing + +for testbin in *; do + run_test $testbin +done
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +23 -1
@@ -8,13 +8,16 @@ SECTION = "net" LICENSE = "Apache-2.0" LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57" -inherit pkgconfig cmake gitpkgv +inherit pkgconfig cmake gitpkgv ptest + +RDEPENDS:${PN}-ptest += "coreutils pcsc-lite-lib" PE = "1" PKGV = "${GITPKGVTAG}" SRCREV = "658a72980f6e93241d927c46cfa664bf2547b8b1" SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https \ + file://run-ptest \ file://winpr-makecert-Build-with-install-RPATH.patch \ file://CVE-2022-39316.patch \ file://CVE-2022-39318-39319.patch \
@@ -43,6 +46,7 @@ EXTRA_OECMAKE += " \ PACKAGECONFIG ??= " \ ${@bb.utils.filter('DISTRO_FEATURES', 'directfb pam pulseaudio wayland x11', d)}\ + ${@bb.utils.contains('PTEST_ENABLED', '1', 'test', '', d)} \ gstreamer cups pcsc \ "
@@ -55,6 +59,7 @@ PACKAGECONFIG[pcsc] = "-DWITH_PCSC=ON,-DWITH_PCSC=OFF,pcsc-lite" PACKAGECONFIG[pulseaudio] = "-DWITH_PULSEAUDIO=ON,-DWITH_PULSEAUDIO=OFF,pulseaudio" PACKAGECONFIG[gstreamer] = "-DWITH_GSTREAMER_1_0=ON,-DWITH_GSTREAMER_1_0=OFF,gstreamer1.0 gstreamer1.0-plugins-base" PACKAGECONFIG[cups] = "-DWITH_CUPS=ON,-DWITH_CUPS=OFF,cups" +PACKAGECONFIG[test] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF" PACKAGES =+ "libfreerdp"
@@ -63,6 +68,14 @@ FILES:libfreerdp = "${libdir}/lib*${SOLIBS}" PACKAGES_DYNAMIC += "^libfreerdp-plugin-.*" +do_configure:prepend() { + if ${@bb.utils.contains('PTEST_ENABLED', '1', 'true', 'false', d)}; then + sed -i 's,CMAKE_CURRENT_SOURCE_DIR,"${PTEST_PATH}/test_data",' ${S}/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c + sed -i 's,\${CMAKE_CURRENT_SOURCE_DIR},"${PTEST_PATH}/test_data",' ${S}/libfreerdp/crypto/test/CMakeLists.txt + sed -i 's,\${CMAKE_CURRENT_SOURCE_DIR},${PTEST_PATH}/test_data,' ${S}/winpr/libwinpr/utils/test/CMakeLists.txt + fi +} + # we will need winpr-makecert to generate TLS certificates do_install:append () { install -d ${D}${bindir}
@@ -71,6 +84,15 @@ do_install:append () { rm -rf ${D}${libdir}/freerdp } +do_install_ptest() { + install -d ${D}${PTEST_PATH}/test_data + cp -r ${B}/Testing ${D}${PTEST_PATH} + install -m 0644 ${S}/libfreerdp/codec/test/progressive.bmp ${D}${PTEST_PATH}/test_data/ + install -m 0644 ${S}/libfreerdp/crypto/test/Test_x509_cert_info.pem ${D}${PTEST_PATH}/test_data/ + install -m 0644 ${S}/winpr/libwinpr/utils/test/lodepng_32bit.png ${D}${PTEST_PATH}/test_data/ + install -m 0644 ${S}/winpr/libwinpr/utils/test/lodepng_32bit.bmp ${D}${PTEST_PATH}/test_data/ +} + python populate_packages:prepend () { freerdp_root = d.expand('${libdir}/freerdp')
PATCH 2/5 freerdp: patch CVE-2023-40589
Details: https://nvd.nist.gov/vuln/detail/CVE-2023-40589
Pick the patch that was identified[1] by Debian to solve the issue on the 2.x branch.
[1]: https://security-tracker.debian.org/tracker/CVE-2023-40589
--- .../freerdp/freerdp/CVE-2023-40589.patch | 319 ++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 320 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40589.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2023-40589.patch new file +319 -0
@@ -0,0 +1,319 @@ +From 2bbed980cf8cf9066d96e9aa29afcedc540ee47c Mon Sep 17 00:00:00 2001 +From: Armin Novak <[email protected]> +Date: Mon, 28 Aug 2023 09:06:42 +0200 +Subject: [PATCH] fix index checks + +properly verify all offsets while decoding data. + +(cherry picked from commit 880285c332a1d98334fd8fa4b06c10fba0fb6959) + +CVE: CVE-2023-40589 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/c659973bb4cd65c065f2fe1a807dbc6805c684c6] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/ncrush.c | 137 ++++++++++++++++++++++++++++++-------- + 1 file changed, 108 insertions(+), 29 deletions(-) + +diff --git a/libfreerdp/codec/ncrush.c b/libfreerdp/codec/ncrush.c +index 3d6a216d3..c1d622a9c 100644 +--- a/libfreerdp/codec/ncrush.c ++++ b/libfreerdp/codec/ncrush.c +@@ -1994,15 +1994,9 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + UINT32* pDstSize, UINT32 flags) + { + UINT32 index; +- UINT32 bits; +- INT32 nbits; +- const BYTE* SrcPtr; +- const BYTE* SrcEnd; +- UINT16 Mask; + BYTE Literal; + UINT32 IndexLEC; + UINT32 BitLength; +- UINT32 MaskedBits; + UINT32 CopyOffset; + UINT32 CopyLength; + UINT32 OldCopyOffset; +@@ -2010,9 +2004,6 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + UINT32 LengthOfMatch; + UINT32 CopyOffsetIndex; + UINT32 OffsetCacheIndex; +- BYTE* HistoryPtr; +- BYTE* HistoryBuffer; +- BYTE* HistoryBufferEnd; + UINT32 CopyOffsetBits; + UINT32 CopyOffsetBase; + UINT32 LengthOfMatchBits; +@@ -2021,8 +2012,8 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + if (ncrush->HistoryEndOffset != 65535) + return -1001; + +- HistoryBuffer = ncrush->HistoryBuffer; +- HistoryBufferEnd = &HistoryBuffer[ncrush->HistoryEndOffset]; ++ BYTE* HistoryBuffer = ncrush->HistoryBuffer; ++ const BYTE* HistoryBufferEnd = &HistoryBuffer[ncrush->HistoryEndOffset]; + + if (flags & PACKET_AT_FRONT) + { +@@ -2041,7 +2032,7 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + ZeroMemory(&(ncrush->OffsetCache), sizeof(ncrush->OffsetCache)); + } + +- HistoryPtr = ncrush->HistoryPtr; ++ BYTE* HistoryPtr = ncrush->HistoryPtr; + + if (!(flags & PACKET_COMPRESSED)) + { +@@ -2050,17 +2041,19 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + return 1; + } + +- SrcEnd = &pSrcData[SrcSize]; +- nbits = 32; +- bits = get_dword(pSrcData); +- SrcPtr = pSrcData + 4; ++ const BYTE* SrcEnd = &pSrcData[SrcSize]; ++ const BYTE* SrcPtr = pSrcData + 4; + ++ INT32 nbits = 32; ++ UINT32 bits = get_dword(pSrcData); + while (1) + { + while (1) + { +- Mask = get_word(&HuffTableMask[29]); +- MaskedBits = bits & Mask; ++ const UINT16 Mask = get_word(&HuffTableMask[29]); ++ const UINT32 MaskedBits = bits & Mask; ++ if (MaskedBits >= ARRAYSIZE(HuffTableLEC)) ++ return -1; + IndexLEC = HuffTableLEC[MaskedBits] & 0xFFF; + BitLength = HuffTableLEC[MaskedBits] >> 12; + bits >>= BitLength; +@@ -2096,8 +2089,10 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + return -1004; + + CopyOffset = ncrush->OffsetCache[OffsetCacheIndex]; +- Mask = get_word(&HuffTableMask[21]); +- MaskedBits = bits & Mask; ++ const UINT16 Mask = get_word(&HuffTableMask[21]); ++ const UINT32 MaskedBits = bits & Mask; ++ if (MaskedBits > ARRAYSIZE(HuffTableLOM)) ++ return -1; + LengthOfMatch = HuffTableLOM[MaskedBits] & 0xFFF; + BitLength = HuffTableLOM[MaskedBits] >> 12; + bits >>= BitLength; +@@ -2106,13 +2101,23 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + if (!NCrushFetchBits(&SrcPtr, &SrcEnd, &nbits, &bits)) + return -1; + ++ if (LengthOfMatch >= ARRAYSIZE(LOMBitsLUT)) ++ return -1; ++ + LengthOfMatchBits = LOMBitsLUT[LengthOfMatch]; ++ ++ if (LengthOfMatch >= ARRAYSIZE(LOMBaseLUT)) ++ return -1; + LengthOfMatchBase = LOMBaseLUT[LengthOfMatch]; + + if (LengthOfMatchBits) + { +- Mask = get_word(&HuffTableMask[(2 * LengthOfMatchBits) + 3]); +- MaskedBits = bits & Mask; ++ const size_t idx = (2ull * LengthOfMatchBits) + 3ull; ++ if (idx >= ARRAYSIZE(HuffTableMask)) ++ return -1; ++ ++ const UINT16 Mask = get_word(&HuffTableMask[idx]); ++ const UINT32 MaskedBits = bits & Mask; + bits >>= LengthOfMatchBits; + nbits -= LengthOfMatchBits; + LengthOfMatchBase += MaskedBits; +@@ -2127,15 +2132,28 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + } + else + { ++ if (CopyOffsetIndex >= ARRAYSIZE(CopyOffsetBitsLUT)) ++ return -1; ++ + CopyOffsetBits = CopyOffsetBitsLUT[CopyOffsetIndex]; ++ ++ if (CopyOffsetIndex >= ARRAYSIZE(CopyOffsetBaseLUT)) ++ return -1; + CopyOffsetBase = CopyOffsetBaseLUT[CopyOffsetIndex]; + CopyOffset = CopyOffsetBase - 1; + + if (CopyOffsetBits) + { +- Mask = get_word(&HuffTableMask[(2 * CopyOffsetBits) + 3]); +- MaskedBits = bits & Mask; +- CopyOffset = CopyOffsetBase + MaskedBits - 1; ++ const size_t idx = (2ull * CopyOffsetBits) + 3ull; ++ if (idx >= ARRAYSIZE(HuffTableMask)) ++ return -1; ++ ++ const UINT16 Mask = get_word(&HuffTableMask[idx]); ++ const UINT32 MaskedBits = bits & Mask; ++ const UINT32 tmp = CopyOffsetBase + MaskedBits; ++ if (tmp < 1) ++ return -1; ++ CopyOffset = tmp - 1; + bits >>= CopyOffsetBits; + nbits -= CopyOffsetBits; + +@@ -2143,8 +2161,11 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + return -1; + } + +- Mask = get_word(&HuffTableMask[21]); +- MaskedBits = bits & Mask; ++ const UINT16 Mask = get_word(&HuffTableMask[21]); ++ const UINT32 MaskedBits = bits & Mask; ++ if (MaskedBits >= ARRAYSIZE(HuffTableLOM)) ++ return -1; ++ + LengthOfMatch = HuffTableLOM[MaskedBits] & 0xFFF; + BitLength = HuffTableLOM[MaskedBits] >> 12; + bits >>= BitLength; +@@ -2153,13 +2174,23 @@ int ncrush_decompress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BY + if (!NCrushFetchBits(&SrcPtr, &SrcEnd, &nbits, &bits)) + return -1; + ++ if (LengthOfMatch >= ARRAYSIZE(LOMBitsLUT)) ++ return -1; ++ + LengthOfMatchBits = LOMBitsLUT[LengthOfMatch]; ++ ++ if (LengthOfMatch >= ARRAYSIZE(LOMBaseLUT)) ++ return -1; + LengthOfMatchBase = LOMBaseLUT[LengthOfMatch]; + + if (LengthOfMatchBits) + { +- Mask = get_word(&HuffTableMask[(2 * LengthOfMatchBits) + 3]); +- MaskedBits = bits & Mask; ++ const size_t idx = (2ull * LengthOfMatchBits) + 3ull; ++ if (idx >= ARRAYSIZE(HuffTableMask)) ++ return -1; ++ ++ const UINT16 Mask = get_word(&HuffTableMask[idx]); ++ const UINT32 MaskedBits = bits & Mask; + bits >>= LengthOfMatchBits; + nbits -= LengthOfMatchBits; + LengthOfMatchBase += MaskedBits; +@@ -2583,7 +2614,12 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + } + + IndexLEC = Literal; ++ if (IndexLEC >= ARRAYSIZE(HuffLengthLEC)) ++ return -1; + BitLength = HuffLengthLEC[IndexLEC]; ++ ++ if (IndexLEC * 2ull >= ARRAYSIZE(HuffCodeLEC)) ++ return -1; + CodeLEC = get_word(&HuffCodeLEC[IndexLEC * 2]); + + if (BitLength > 15) +@@ -2666,9 +2702,18 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + bits = CopyOffset; + + CopyOffsetIndex = ncrush->HuffTableCopyOffset[bits + 2]; ++ ++ if (CopyOffsetIndex >= ARRAYSIZE(CopyOffsetBitsLUT)) ++ return -1; ++ + CopyOffsetBits = CopyOffsetBitsLUT[CopyOffsetIndex]; + IndexLEC = 257 + CopyOffsetIndex; ++ if (IndexLEC >= ARRAYSIZE(HuffLengthLEC)) ++ return -1; + BitLength = HuffLengthLEC[IndexLEC]; ++ ++ if (IndexLEC * 2ull >= ARRAYSIZE(HuffCodeLEC)) ++ return -1; + CodeLEC = get_word(&HuffCodeLEC[IndexLEC * 2]); + + if (BitLength > 15) +@@ -2687,13 +2732,23 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + else + IndexCO = ncrush->HuffTableLOM[MatchLength]; + ++ if (IndexCO >= ARRAYSIZE(HuffLengthLOM)) ++ return -1; + BitLength = HuffLengthLOM[IndexCO]; ++ ++ if (IndexCO >= ARRAYSIZE(LOMBitsLUT)) ++ return -1; + IndexLOM = LOMBitsLUT[IndexCO]; ++ ++ if (IndexCO >= ARRAYSIZE(HuffCodeLOM)) ++ return -1; + NCrushWriteBits(&DstPtr, &accumulator, &offset, HuffCodeLOM[IndexCO], BitLength); + Mask = ((1 << IndexLOM) - 1); + MaskedBits = (MatchLength - 2) & Mask; + NCrushWriteBits(&DstPtr, &accumulator, &offset, MaskedBits, IndexLOM); + ++ if (IndexCO >= ARRAYSIZE(LOMBaseLUT)) ++ return -1; + if ((MaskedBits + LOMBaseLUT[IndexCO]) != MatchLength) + return -1010; + } +@@ -2701,7 +2756,11 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + { + /* CopyOffset in OffsetCache */ + IndexLEC = 289 + OffsetCacheIndex; ++ if (IndexLEC >= ARRAYSIZE(HuffLengthLEC)) ++ return -1; + BitLength = HuffLengthLEC[IndexLEC]; ++ if (IndexLEC * 2ull >= ARRAYSIZE(HuffCodeLEC)) ++ return -1; + CodeLEC = get_word(&HuffCodeLEC[IndexLEC * 2]); + + if (BitLength >= 15) +@@ -2714,13 +2773,24 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + else + IndexCO = ncrush->HuffTableLOM[MatchLength]; + ++ if (IndexCO >= ARRAYSIZE(HuffLengthLOM)) ++ return -1; ++ + BitLength = HuffLengthLOM[IndexCO]; ++ ++ if (IndexCO >= ARRAYSIZE(LOMBitsLUT)) ++ return -1; + IndexLOM = LOMBitsLUT[IndexCO]; ++ ++ if (IndexCO >= ARRAYSIZE(HuffCodeLOM)) ++ return -1; + NCrushWriteBits(&DstPtr, &accumulator, &offset, HuffCodeLOM[IndexCO], BitLength); + Mask = ((1 << IndexLOM) - 1); + MaskedBits = (MatchLength - 2) & Mask; + NCrushWriteBits(&DstPtr, &accumulator, &offset, MaskedBits, IndexLOM); + ++ if (IndexCO >= ARRAYSIZE(LOMBaseLUT)) ++ return -1; + if ((MaskedBits + LOMBaseLUT[IndexCO]) != MatchLength) + return -1012; + } +@@ -2745,6 +2815,10 @@ int ncrush_compress(NCRUSH_CONTEXT* ncrush, BYTE* pSrcData, UINT32 SrcSize, BYTE + Literal = *SrcPtr++; + HistoryPtr++; + IndexLEC = Literal; ++ if (IndexLEC >= ARRAYSIZE(HuffLengthLEC)) ++ return -1; ++ if (IndexLEC * 2ull >= ARRAYSIZE(HuffCodeLEC)) ++ return -1; + BitLength = HuffLengthLEC[IndexLEC]; + CodeLEC = get_word(&HuffCodeLEC[IndexLEC * 2]); + +@@ -2817,6 +2891,11 @@ static int ncrush_generate_tables(NCRUSH_CONTEXT* context) + else + i = context->HuffTableLOM[k]; + ++ if (i >= ARRAYSIZE(LOMBitsLUT)) ++ return -1; ++ if (i >= ARRAYSIZE(LOMBaseLUT)) ++ return -1; ++ + if (((((1 << LOMBitsLUT[i]) - 1) & (k - 2)) + LOMBaseLUT[i]) != k) + return -1; + }
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -30,6 +30,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-39353.patch \ file://CVE-2023-40181.patch \ file://CVE-2023-40569.patch \ + file://CVE-2023-40589.patch \ " S = "${WORKDIR}/git"
PATCH 3/5 freerdp: patch CVE-2024-22211
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2024-22211
Pick the patch that is referenced by the NVD report as the solution.
--- .../freerdp/freerdp/CVE-2024-22211.patch | 36 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 37 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2024-22211.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2024-22211.patch new file +36 -0
@@ -0,0 +1,36 @@ +From 4d3dcfcf537a32ffbebbdba11a7b0748baec4e31 Mon Sep 17 00:00:00 2001 +From: Armin Novak <[email protected]> +Date: Sat, 13 Jan 2024 21:01:55 +0100 +Subject: [PATCH] check resolution for overflow + +If the codec resolution is too large return an error as the internal +buffers would otherwise overflow. + +(cherry picked from commit 44edab1deae4f8c901c00a00683f888cef36d853) + +CVE: CVE-2024-22211 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/aeac3040cc99eeaff1e1171a822114c857b9dca9] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/planar.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c +index 12b9f6daf..58d4e4bae 100644 +--- a/libfreerdp/codec/planar.c ++++ b/libfreerdp/codec/planar.c +@@ -1486,7 +1486,13 @@ BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context, UINT32 + context->bgr = FALSE; + context->maxWidth = ALIGN(width, 4); + context->maxHeight = ALIGN(height, 4); +- context->maxPlaneSize = context->maxWidth * context->maxHeight; ++ const UINT64 tmp = (UINT64)context->maxWidth * context->maxHeight; ++ if (tmp > UINT32_MAX) ++ return FALSE; ++ context->maxPlaneSize = tmp; ++ ++ if (context->maxWidth > UINT32_MAX /4) ++ return FALSE; + context->nTempStep = context->maxWidth * 4; + free(context->planesBuffer); + free(context->pTempData);
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -31,6 +31,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-40181.patch \ file://CVE-2023-40569.patch \ file://CVE-2023-40589.patch \ + file://CVE-2024-22211.patch \ " S = "${WORKDIR}/git"
PATCH 4/5 freerdp: patch CVE-2024-32039
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2024-32039
Pick the commit that is marked to resolve this vulerability, mentioned by the Github advisory[1].
[1]: https://github.com/FreeRDP/FreeRDP/security/advisories/GHSA-q5h8-7j42-j4r9
--- .../freerdp/freerdp/CVE-2024-32039.patch | 78 +++++++++++++++++++ .../recipes-support/freerdp/freerdp_2.6.1.bb | 1 + 2 files changed, 79 insertions(+) create mode 100644 meta-oe/recipes-support/freerdp/freerdp/CVE-2024-32039.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2024-32039.patch new file +78 -0
@@ -0,0 +1,78 @@ +From 519c08d4720950dbeef8e671431ff8a6ea4e2927 Mon Sep 17 00:00:00 2001 +From: akallabeth <[email protected]> +Date: Tue, 16 Apr 2024 08:35:05 +0200 +Subject: [PATCH] fix integer overflow + +reorder check to prevent possible integer overflow + +(cherry picked from commit 3a2a241b8fcfee853e35cc54bec00375096fedd9) + +CVE: CVE-2024-32039 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/d88ad1acd142769650a6159906ac90f46a766265] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/clear.c | 2 +- + libfreerdp/codec/zgfx.c | 16 +++++++++++----- + 2 files changed, 12 insertions(+), 6 deletions(-) + +diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c +index fadd98e67..0e169cf9d 100644 +--- a/libfreerdp/codec/clear.c ++++ b/libfreerdp/codec/clear.c +@@ -410,7 +410,7 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, wStream* s, + } + } + +- if ((pixelIndex + runLengthFactor) > pixelCount) ++ if ((pixelIndex >= pixelCount) || (runLengthFactor > (pixelCount - pixelIndex))) + { + WLog_ERR(TAG, + "pixelIndex %" PRIu32 " + runLengthFactor %" PRIu32 " > pixelCount %" PRIu32 +diff --git a/libfreerdp/codec/zgfx.c b/libfreerdp/codec/zgfx.c +index 4489b3798..3ed5067c8 100644 +--- a/libfreerdp/codec/zgfx.c ++++ b/libfreerdp/codec/zgfx.c +@@ -23,6 +23,8 @@ + #include "config.h" + #endif + ++#include <assert.h> ++ + #include <winpr/crt.h> + #include <winpr/print.h> + #include <winpr/bitstream.h> +@@ -230,7 +232,10 @@ static BOOL zgfx_decompress_segment(ZGFX_CONTEXT* zgfx, wStream* stream, size_t + BYTE* pbSegment; + size_t cbSegment; + +- if (!zgfx || !stream || (segmentSize < 2)) ++ assert((zgfx) && "Assert failed: zgfx"); ++ assert((stream) && "Assert failed: stream"); ++ ++ if (segmentSize < 2) + return FALSE; + + cbSegment = segmentSize - 1; +@@ -349,8 +354,9 @@ static BOOL zgfx_decompress_segment(ZGFX_CONTEXT* zgfx, wStream* stream, size_t + + if (count > sizeof(zgfx->OutputBuffer) - zgfx->OutputCount) + return FALSE; +- +- if (count > zgfx->cBitsRemaining / 8) ++ else if (count > zgfx->cBitsRemaining / 8) ++ return FALSE; ++ else if (zgfx->pbInputCurrent + count > zgfx->pbInputEnd) + return FALSE; + + CopyMemory(&(zgfx->OutputBuffer[zgfx->OutputCount]), zgfx->pbInputCurrent, +@@ -377,8 +383,8 @@ int zgfx_decompress(ZGFX_CONTEXT* zgfx, const BYTE* pSrcData, UINT32 SrcSize, BY + BYTE descriptor; + wStream* stream = Stream_New((BYTE*)pSrcData, SrcSize); + +- if (!stream) +- return -1; ++ assert((zgfx) && "Assert failed: zgfx"); ++ assert((stream) && "Assert failed: stream"); + + if (Stream_GetRemainingLength(stream) < 1) + goto fail;
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -32,6 +32,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-40569.patch \ file://CVE-2023-40589.patch \ file://CVE-2024-22211.patch \ + file://CVE-2024-32039.patch \ " S = "${WORKDIR}/git"
PATCH 5/5 freerdp: patch CVE-2024-32040
In reply to Gyorgy SarvariDetails: https://nvd.nist.gov/vuln/detail/CVE-2024-32040
Pick the patch that is marked to resolve this vulnerability, from the related Github advisory[1].
[1]: https://github.com/FreeRDP/FreeRDP/security/advisories/GHSA-23c5-cp23-h2h5
--- .../freerdp/freerdp/CVE-2024-32040.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-2024-32040.patch
meta-oe/recipes-support/freerdp/freerdp/CVE-2024-32040.patch new file +30 -0
@@ -0,0 +1,30 @@ +From a7e801f42a3a71332cca22aedccfcda378b8dfcc Mon Sep 17 00:00:00 2001 +From: akallabeth <[email protected]> +Date: Tue, 16 Apr 2024 08:26:37 +0200 +Subject: [PATCH] fix missing check + +in nsc_rle_decode abort if there are more bytes to be read then there +are left. + +(cherry picked from commit fb4f2d6e4db563077afcae4d270ba78ff905f6cf) + +CVE: CVE-2024-32040 +Upstream-Status: Backport [https://github.com/FreeRDP/FreeRDP/commit/5893b5f277db38b0040c572b078de838b84cfc07] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + libfreerdp/codec/nsc.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libfreerdp/codec/nsc.c b/libfreerdp/codec/nsc.c +index dc3a978ed..007364ee7 100644 +--- a/libfreerdp/codec/nsc.c ++++ b/libfreerdp/codec/nsc.c +@@ -147,7 +147,7 @@ static BOOL nsc_rle_decode(BYTE* in, BYTE* out, UINT32 outSize, UINT32 originalS + len |= ((UINT32)(*in++)) << 24U; + } + +- if (outSize < len) ++ if ((outSize < len) || (left < len)) + return FALSE; + + outSize -= len;
meta-oe/recipes-support/freerdp/freerdp_2.6.1.bb +1 -0
@@ -33,6 +33,7 @@ SRC_URI = "git://github.com/FreeRDP/FreeRDP.git;branch=stable-2.0;protocol=https file://CVE-2023-40589.patch \ file://CVE-2024-22211.patch \ file://CVE-2024-32039.patch \ + file://CVE-2024-32040.patch \ " S = "${WORKDIR}/git"