libiec61850: upgrade 1.5.1 -> 1.5.3
PATCH 1/5 libiec61850: upgrade 1.5.1 -> 1.5.3
From: Wang Mingyu <[email protected]>
Changelog:
=============
- config file parser dynamically allocates linebuffer to allow multithreaded applications
- parse time values in model configuration file
- config file generator: added missing code for GSEControl
- Config file generator: support multiple access points for GOOSE and SMV control blocks
- config file generator: added code to add SMVCBs to config files
- IED server: added code to create SMVCBs with the dynamic model API
- MMS server: added support for write access with component alternate access
- MMS client: added function MmsConnection_writeVariableComponent to write to variables with alternate component access
- make write access to RCB elements configurable according to ReportSettings
- Added function IedConnection_setLocalAddress to define local IP address and optionally local port of a client connection
- IED server: added ControlAction_getSynchroCheck and ControlAction_getInterlockCheck functions
- fixed - IEC 61580 server: dataset is not released when RCB.Datset is set to empty string by client
- PAL: fixed wrong order of function arguments for fread and fwrite functions
- MMS client: parsing of servicecsSupported in MMS init response is off by one
- fixed - potential memory leaks in goose publisher code
- fixed - server sends dchg report when only dupd is enabled in RCB
- GOOSE subscriber: fixed - possible heap corruption in parseAllData due to missing validity check in bit-string handling
- IED server: fixed problem with implicit ResvTms setting when reserved with RptEna
- IED server: fixed - segmentation fault when compiled with CONFIG_MMS_THREADLESS_STACK
- fixed - MMS server: messages can be corrupted when TCP buffer is full
- fixed - .NET: IedConenction.WriteDataSetValues throws a NullReferenceException
- fixed - server send invalid response- when client uses wrong ctlModel
- fixed - IedConnection_setRCBValuesAsync crashes when RCB is already reserved by other client
- fixed - outstanding call not released in IedConnection_getDataSetDirectoryAsync
---
.../libiec61850/{libiec61850_1.5.1.bb => libiec61850_1.5.3.bb} | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename meta-networking/recipes-connectivity/libiec61850/{libiec61850_1.5.1.bb => libiec61850_1.5.3.bb} (96%)meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.3.bb renamed from meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.1.bb +1 -1
@@ -13,7 +13,7 @@ SECTION = "console/network" LICENSE = "GPL-3.0-only" LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504" DEPENDS = "swig-native python3" -SRCREV = "210cf30897631fe2006ac50483caf8fd616622a2" +SRCREV = "6f557c490f0b46ab5d7ef1b01bb3bc9fab3f442f" SRC_URI = "git://github.com/mz-automation/${BPN}.git;branch=v1.5;protocol=https \ file://0001-pyiec61850-don-t-break-CMAKE_INSTALL_PATH-by-trying-.patch \
PATCH 2/5 libiec61850: ignore CVE-2023-27772
Details https://nvd.nist.gov/vuln/detail/CVE-2023-27772
$ git tag --contains 79a8eaf | grep 1.5.3 v1.5.3
--- .../recipes-connectivity/libiec61850/libiec61850_1.5.3.bb | 2 ++ 1 file changed, 2 insertions(+)
meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.3.bb +2 -0
@@ -36,3 +36,5 @@ FILES:${PN} += " \ ${PYTHON_SITEPACKAGES_DIR}/iec61850.py \ ${PYTHON_SITEPACKAGES_DIR}/_iec61850.so \ " + +CVE_STATUS[CVE-2023-27772] = "fixed-version: The vulnerability has been addressed and the fix is included in current version (1.5.3)"
PATCH 3/5 libiec61850: patch CVE-2024-26529
In reply to Ankur TyagiDetails https://nvd.nist.gov/vuln/detail/CVE-2024-26529
--- .../libiec61850/files/CVE-2024-26529.patch | 33 +++++++++++++++++++ .../libiec61850/libiec61850_1.5.3.bb | 1 + 2 files changed, 34 insertions(+) create mode 100644 meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-26529.patch
meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-26529.patch new file +33 -0
@@ -0,0 +1,33 @@ +From e29799cba6f1d08cf6463a2b190c0e6502b885df Mon Sep 17 00:00:00 2001 +From: Michael Zillgith <[email protected]> +Date: Fri, 2 Feb 2024 06:44:47 +0000 +Subject: [PATCH] CVE-2024-26529 + +fixed - null pointer dereference in mmsServer_handleDeleteNamedVariableListRequest when receiving malformed message (LIB61850-430) + +CVE: CVE-2024-26529 +Upstream-Status: Backport [https://github.com/mz-automation/libiec61850/commit/cf94d64206cf53298edf4799a75b31657bb7cbb3] + +(cherry picked from commit cf94d64206cf53298edf4799a75b31657bb7cbb3) +Signed-off-by: Ankur Tyagi <[email protected]> +--- + src/mms/iso_mms/server/mms_named_variable_list_service.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/src/mms/iso_mms/server/mms_named_variable_list_service.c b/src/mms/iso_mms/server/mms_named_variable_list_service.c +index 3a27061c..3365f771 100644 +--- a/src/mms/iso_mms/server/mms_named_variable_list_service.c ++++ b/src/mms/iso_mms/server/mms_named_variable_list_service.c +@@ -140,6 +140,12 @@ mmsServer_handleDeleteNamedVariableListRequest(MmsServerConnection connection, + mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); + goto exit_function; + } ++ ++ if (request->listOfVariableListName == NULL) ++ { ++ mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); ++ goto exit_function; ++ } + + long scopeOfDelete = DeleteNamedVariableListRequest__scopeOfDelete_specific; +
meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.3.bb +1 -0
@@ -18,6 +18,7 @@ SRCREV = "6f557c490f0b46ab5d7ef1b01bb3bc9fab3f442f" SRC_URI = "git://github.com/mz-automation/${BPN}.git;branch=v1.5;protocol=https \ file://0001-pyiec61850-don-t-break-CMAKE_INSTALL_PATH-by-trying-.patch \ file://0001-pyiec61850-Use-CMAKE_INSTALL_LIBDIR-from-GNUInstallD.patch \ + file://CVE-2024-26529.patch \ " S = "${WORKDIR}/git"
PATCH 4/5 libiec61850: patch CVE-2024-45970
In reply to Ankur TyagiDetails https://nvd.nist.gov/vuln/detail/CVE-2024-45970
--- .../libiec61850/files/CVE-2024-45970.patch | 74 +++++++++++++++++++ .../libiec61850/libiec61850_1.5.3.bb | 1 + 2 files changed, 75 insertions(+) create mode 100644 meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-45970.patch
meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-45970.patch new file +74 -0
@@ -0,0 +1,74 @@ +From d5bd7cbf26b0254ce068ba7d940c26adbf9ce8e8 Mon Sep 17 00:00:00 2001 +From: Michael Zillgith <[email protected]> +Date: Tue, 23 Jul 2024 18:50:15 +0100 +Subject: [PATCH] CVE-2024-45970 + +fixed potential buffer overflows in MMS client file service handling (LIB61850-449) + +CVE: CVE-2024-45970 +Upstream-Status: Backport [https://github.com/mz-automation/libiec61850/commit/ac925fae8e281ac6defcd630e9dd756264e9c5bc] + +(cherry picked from commit ac925fae8e281ac6defcd630e9dd756264e9c5bc) +Signed-off-by: Ankur Tyagi <[email protected]> +--- + src/mms/iso_mms/client/mms_client_files.c | 23 +++++++++++++++++++---- + 1 file changed, 19 insertions(+), 4 deletions(-) + +diff --git a/src/mms/iso_mms/client/mms_client_files.c b/src/mms/iso_mms/client/mms_client_files.c +index 4fca418e..935ba1a4 100644 +--- a/src/mms/iso_mms/client/mms_client_files.c ++++ b/src/mms/iso_mms/client/mms_client_files.c +@@ -487,8 +487,13 @@ parseFileAttributes(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t* fileSi + break; + case 0x81: /* lastModified */ + { +- if (lastModified != NULL) { ++ if (lastModified != NULL) ++ { + char gtString[40]; ++ ++ if (length > sizeof(gtString) - 1) ++ return false; /* lastModified string too long */ ++ + memcpy(gtString, buffer + bufPos, length); + gtString[length] = 0; + *lastModified = Conversions_generalizedTimeToMsTime(gtString); +@@ -515,12 +520,14 @@ parseDirectoryEntry(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeI + uint32_t fileSize = 0; + uint64_t lastModified = 0; + +- while (bufPos < maxBufPos) { ++ while (bufPos < maxBufPos) ++ { + uint8_t tag = buffer[bufPos++]; + int length; + + bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); +- if (bufPos < 0) { ++ if (bufPos < 0) ++ { + if (DEBUG_MMS_CLIENT) + printf("MMS_CLIENT: invalid length field\n"); + return false; +@@ -534,12 +541,20 @@ parseDirectoryEntry(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeI + tag = buffer[bufPos++]; + + bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); +- if (bufPos < 0) { ++ if (bufPos < 0) ++ { + if (DEBUG_MMS_CLIENT) + printf("MMS_CLIENT: invalid length field\n"); + return false; + } + ++ if (length > (sizeof(fileNameMemory) - 1)) ++ { ++ if (DEBUG_MMS_CLIENT) ++ printf("MMS_CLIENT: filename too long\n"); ++ return false; ++ } ++ + memcpy(filename, buffer + bufPos, length); + filename[length] = 0; +
meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.3.bb +1 -0
@@ -19,6 +19,7 @@ SRC_URI = "git://github.com/mz-automation/${BPN}.git;branch=v1.5;protocol=https file://0001-pyiec61850-don-t-break-CMAKE_INSTALL_PATH-by-trying-.patch \ file://0001-pyiec61850-Use-CMAKE_INSTALL_LIBDIR-from-GNUInstallD.patch \ file://CVE-2024-26529.patch \ + file://CVE-2024-45970.patch \ " S = "${WORKDIR}/git"
PATCH 5/5 libiec61850: patch CVE-2024-45971
In reply to Ankur TyagiDetails https://nvd.nist.gov/vuln/detail/CVE-2024-45971
--- .../libiec61850/files/CVE-2024-45971.patch | 218 ++++++++++++++++++ .../libiec61850/libiec61850_1.5.3.bb | 1 + 2 files changed, 219 insertions(+) create mode 100644 meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-45971.patch
meta-networking/recipes-connectivity/libiec61850/files/CVE-2024-45971.patch new file +218 -0
@@ -0,0 +1,218 @@ +From b9bebc0d74998195422d104e4d430e2511d6c40f Mon Sep 17 00:00:00 2001 +From: Michael Zillgith <[email protected]> +Date: Mon, 22 Jul 2024 16:34:03 +0100 +Subject: [PATCH] CVE-2024-45971 + +LIB61850-447: replaced unsafe function StringUtils_createStringFromBufferInBuffer with function with length check to not exceed target buffer + +CVE: CVE-2024-45971 +Upstream-Status: Backport [https://github.com/mz-automation/libiec61850/commit/1f52be9ddeae00e69cd43e4cac3cb4f0c880c4f0] + +(cherry picked from commit 1f52be9ddeae00e69cd43e4cac3cb4f0c880c4f0) +Signed-off-by: Ankur Tyagi <[email protected]> +--- + src/common/inc/string_utilities.h | 3 ++ + src/common/string_utilities.c | 12 +++++ + src/iec61850/server/mms_mapping/mms_mapping.c | 6 ++- + src/mms/iso_mms/client/mms_client_identify.c | 6 +-- + .../server/mms_named_variable_list_service.c | 52 +++++++++---------- + 5 files changed, 48 insertions(+), 31 deletions(-) + +diff --git a/src/common/inc/string_utilities.h b/src/common/inc/string_utilities.h +index b6b238ff..9a5d868a 100644 +--- a/src/common/inc/string_utilities.h ++++ b/src/common/inc/string_utilities.h +@@ -63,6 +63,9 @@ StringUtils_createStringFromBuffer(const uint8_t* buf, int size); + LIB61850_INTERNAL char* + StringUtils_createStringFromBufferInBuffer(char* newString, const uint8_t* buf, int size); + ++LIB61850_INTERNAL char* ++StringUtils_createStringFromBufferInBufferMax(char* newString, const uint8_t* buf, int size, int maxBufSize); ++ + LIB61850_INTERNAL void + StringUtils_replace(char* string, char oldChar, char newChar); + +diff --git a/src/common/string_utilities.c b/src/common/string_utilities.c +index 37e62ad7..378acbde 100644 +--- a/src/common/string_utilities.c ++++ b/src/common/string_utilities.c +@@ -85,6 +85,18 @@ StringUtils_createStringFromBufferInBuffer(char* newString, const uint8_t* buf, + return newString; + } + ++char* ++StringUtils_createStringFromBufferInBufferMax(char* newString, const uint8_t* buf, int size, int maxBufSize) ++{ ++ if (size >= maxBufSize) ++ size = maxBufSize - 1; ++ ++ memcpy(newString, buf, size); ++ newString[size] = 0; ++ ++ return newString; ++} ++ + char* + StringUtils_createStringInBuffer(char* newStr, int bufSize, int count, ...) + { +diff --git a/src/iec61850/server/mms_mapping/mms_mapping.c b/src/iec61850/server/mms_mapping/mms_mapping.c +index 707e8b57..4a700a27 100644 +--- a/src/iec61850/server/mms_mapping/mms_mapping.c ++++ b/src/iec61850/server/mms_mapping/mms_mapping.c +@@ -3268,7 +3268,9 @@ mmsReadAccessHandler (void* parameter, MmsDomain* domain, char* variableId, MmsS + } + else + { +- StringUtils_createStringFromBufferInBuffer(str, (uint8_t*) variableId, separator - variableId); ++ char str[65]; ++ ++ StringUtils_createStringFromBufferInBufferMax(str, (uint8_t*) variableId, separator - variableId, sizeof(str)); + + LogicalNode* ln = LogicalDevice_getLogicalNode(ld, str); + +@@ -3286,7 +3288,7 @@ mmsReadAccessHandler (void* parameter, MmsDomain* domain, char* variableId, MmsS + else { + doEnd--; + +- StringUtils_createStringFromBufferInBuffer(str, (uint8_t*) (doStart + 1), doEnd - doStart); ++ StringUtils_createStringFromBufferInBufferMax(str, (uint8_t*) (doStart + 1), doEnd - doStart, sizeof(str)); + } + + if (fc == IEC61850_FC_SP) { +diff --git a/src/mms/iso_mms/client/mms_client_identify.c b/src/mms/iso_mms/client/mms_client_identify.c +index 831b439d..c679a423 100644 +--- a/src/mms/iso_mms/client/mms_client_identify.c ++++ b/src/mms/iso_mms/client/mms_client_identify.c +@@ -84,15 +84,15 @@ mmsClient_parseIdentifyResponse(MmsConnection self, ByteBuffer* response, uint32 + + switch (tag) { + case 0x80: /* vendorName */ +- vendorName = StringUtils_createStringFromBufferInBuffer(vendorNameBuf, buffer + bufPos, length); ++ vendorName = StringUtils_createStringFromBufferInBufferMax(vendorNameBuf, buffer + bufPos, length, sizeof(vendorNameBuf)); + bufPos += length; + break; + case 0x81: /* modelName */ +- modelName = StringUtils_createStringFromBufferInBuffer(modelNameBuf, buffer + bufPos, length); ++ modelName = StringUtils_createStringFromBufferInBufferMax(modelNameBuf, buffer + bufPos, length, sizeof(modelNameBuf)); + bufPos += length; + break; + case 0x82: /* revision */ +- revision = StringUtils_createStringFromBufferInBuffer(revisionBuf, buffer + bufPos, length); ++ revision = StringUtils_createStringFromBufferInBufferMax(revisionBuf, buffer + bufPos, length, sizeof (revisionBuf)); + bufPos += length; + break; + case 0x83: /* list of abstract syntaxes */ +diff --git a/src/mms/iso_mms/server/mms_named_variable_list_service.c b/src/mms/iso_mms/server/mms_named_variable_list_service.c +index 3365f771..757d0ed3 100644 +--- a/src/mms/iso_mms/server/mms_named_variable_list_service.c ++++ b/src/mms/iso_mms/server/mms_named_variable_list_service.c +@@ -401,13 +401,13 @@ createNamedVariableList(MmsServer server, MmsDomain* domain, MmsDevice* device, + char variableName[65]; + char domainId[65]; + +- StringUtils_createStringFromBufferInBuffer(variableName, +- varSpec->choice.name.choice.domainspecific.itemId.buf, +- varSpec->choice.name.choice.domainspecific.itemId.size); ++ StringUtils_createStringFromBufferInBufferMax(variableName, ++ varSpec->choice.name.choice.domainspecific.itemId.buf, ++ varSpec->choice.name.choice.domainspecific.itemId.size, sizeof(variableName)); + +- StringUtils_createStringFromBufferInBuffer(domainId, +- varSpec->choice.name.choice.domainspecific.domainId.buf, +- varSpec->choice.name.choice.domainspecific.domainId.size); ++ StringUtils_createStringFromBufferInBufferMax(domainId, ++ varSpec->choice.name.choice.domainspecific.domainId.buf, ++ varSpec->choice.name.choice.domainspecific.domainId.size, sizeof(domainId)); + + MmsDomain* elementDomain = MmsDevice_getDomain(device, domainId); + +@@ -494,9 +494,9 @@ mmsServer_handleDefineNamedVariableListRequest( + goto exit_free_struct; + } + +- StringUtils_createStringFromBufferInBuffer(domainName, +- request->variableListName.choice.domainspecific.domainId.buf, +- request->variableListName.choice.domainspecific.domainId.size); ++ StringUtils_createStringFromBufferInBufferMax(domainName, ++ request->variableListName.choice.domainspecific.domainId.buf, ++ request->variableListName.choice.domainspecific.domainId.size, sizeof(domainName)); + + MmsDomain* domain = MmsDevice_getDomain(device, domainName); + +@@ -517,9 +517,9 @@ mmsServer_handleDefineNamedVariableListRequest( + goto exit_free_struct; + } + +- StringUtils_createStringFromBufferInBuffer(variableListName, +- request->variableListName.choice.domainspecific.itemId.buf, +- request->variableListName.choice.domainspecific.itemId.size); ++ StringUtils_createStringFromBufferInBufferMax(variableListName, ++ request->variableListName.choice.domainspecific.itemId.buf, ++ request->variableListName.choice.domainspecific.itemId.size, sizeof(variableListName)); + + if (MmsDomain_getNamedVariableList(domain, variableListName) != NULL) { + mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); +@@ -567,9 +567,9 @@ mmsServer_handleDefineNamedVariableListRequest( + goto exit_free_struct; + } + +- StringUtils_createStringFromBufferInBuffer(variableListName, +- request->variableListName.choice.aaspecific.buf, +- request->variableListName.choice.aaspecific.size); ++ StringUtils_createStringFromBufferInBufferMax(variableListName, ++ request->variableListName.choice.aaspecific.buf, ++ request->variableListName.choice.aaspecific.size, sizeof(variableListName)); + + if (MmsServerConnection_getNamedVariableList(connection, variableListName) != NULL) { + mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); +@@ -611,9 +611,9 @@ mmsServer_handleDefineNamedVariableListRequest( + goto exit_free_struct; + } + +- StringUtils_createStringFromBufferInBuffer(variableListName, +- request->variableListName.choice.vmdspecific.buf, +- request->variableListName.choice.vmdspecific.size); ++ StringUtils_createStringFromBufferInBufferMax(variableListName, ++ request->variableListName.choice.vmdspecific.buf, ++ request->variableListName.choice.vmdspecific.size, sizeof(variableListName)); + + if (mmsServer_getNamedVariableListWithName(MmsDevice_getNamedVariableLists(connection->server->device), variableListName) != NULL) { + mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); +@@ -757,11 +757,11 @@ mmsServer_handleGetNamedVariableListAttributesRequest( + goto exit_function; + } + +- StringUtils_createStringFromBufferInBuffer(domainName, request->choice.domainspecific.domainId.buf, +- request->choice.domainspecific.domainId.size); ++ StringUtils_createStringFromBufferInBufferMax(domainName, request->choice.domainspecific.domainId.buf, ++ request->choice.domainspecific.domainId.size, sizeof(domainName)); + +- StringUtils_createStringFromBufferInBuffer(itemName, request->choice.domainspecific.itemId.buf, +- request->choice.domainspecific.itemId.size); ++ StringUtils_createStringFromBufferInBufferMax(itemName, request->choice.domainspecific.itemId.buf, ++ request->choice.domainspecific.itemId.size, sizeof(itemName)); + + MmsDevice* mmsDevice = MmsServer_getDevice(connection->server); + +@@ -798,8 +798,8 @@ mmsServer_handleGetNamedVariableListAttributesRequest( + goto exit_function; + } + +- StringUtils_createStringFromBufferInBuffer(listName, request->choice.aaspecific.buf, +- request->choice.aaspecific.size); ++ StringUtils_createStringFromBufferInBufferMax(listName, request->choice.aaspecific.buf, ++ request->choice.aaspecific.size, sizeof(listName)); + + MmsNamedVariableList varList = MmsServerConnection_getNamedVariableList(connection, listName); + +@@ -817,8 +817,8 @@ mmsServer_handleGetNamedVariableListAttributesRequest( + goto exit_function; + } + +- StringUtils_createStringFromBufferInBuffer(listName, request->choice.vmdspecific.buf, +- request->choice.vmdspecific.size); ++ StringUtils_createStringFromBufferInBufferMax(listName, request->choice.vmdspecific.buf, ++ request->choice.vmdspecific.size, sizeof(listName)); + + MmsDevice* mmsDevice = MmsServer_getDevice(connection->server); +
meta-networking/recipes-connectivity/libiec61850/libiec61850_1.5.3.bb +1 -0
@@ -20,6 +20,7 @@ SRC_URI = "git://github.com/mz-automation/${BPN}.git;branch=v1.5;protocol=https file://0001-pyiec61850-Use-CMAKE_INSTALL_LIBDIR-from-GNUInstallD.patch \ file://CVE-2024-26529.patch \ file://CVE-2024-45970.patch \ + file://CVE-2024-45971.patch \ " S = "${WORKDIR}/git"