summaryrefslogtreecommitdiff
path: root/crypto_libraries/src/nx_crypto_drbg.c
AgeCommit message (Collapse)Author
2026-08-13Released the DRBG mutex when _nx_crypto_drbg_generate fails (#412)Edouard Malot
Released the DRBG mutex when generation fails _nx_crypto_drbg() acquired NX_CRYPTO_DRBG_MUTEX_GET, called _nx_crypto_drbg_generate(), and then returned on a non-zero status from above the matching NX_CRYPTO_DRBG_MUTEX_PUT. That return abandoned the mutex. It is the only acquire/release pair in the file, so there is no second imbalance and no compensating release elsewhere: once that path is taken the mutex is held for good. Move the release above the status check rather than adding a second release on the error path, which would leave two call sites to keep in step. The bit masking that follows stays outside the critical section, which is safe: it reads bits, computes mask and writes result[0], all of it local or caller owned, with no DRBG state involved. The failure this fixes is the only one this caller can produce, not an obscure one. _nx_crypto_drbg_generate() has three failure returns. Two are NX_CRYPTO_SIZE_ERROR conditions on additional_input_len, and _nx_crypto_drbg() passes NX_CRYPTO_NULL and 0 for those arguments, so neither is reachable from here. The third is NX_CRYPTO_NO_INSTANCE when nx_crypto_drbg_instantiated is false, and that flag is false in exactly one circumstance: the _nx_crypto_drbg_initialize() call on the line above failed and its return value was discarded. So the abandoned mutex sits on the one error this function can actually return. That also disposes of the discarded initialisation return as a separate concern. With the release moved, an initialisation failure now propagates NX_CRYPTO_NO_INSTANCE to the caller with the mutex released, which is the correct behaviour; checking the return explicitly would change nothing observable. How reachable this is depends on the port. Both macros default to empty under #ifndef in nx_crypto_drbg.h, and nothing in the repository defines them, so no configuration built here observes the leak. A port that supplies real ones does. In NX_CRYPTO_SELF_TEST builds NX_CRYPTO_RBG resolves to _nx_crypto_drbg (nx_crypto.h), so on such a port this deadlocks the generator behind EC key generation and ECDSA signing, which reach it through NX_CRYPTO_RBG in nx_crypto_ec.c. That is the random number generator for the whole FIPS configuration rather than a peripheral path. No regression test accompanies this. There is no configuration the project builds in which the change is observable, since both mutex macros expand to nothing everywhere in tree, so a test could only assert that empty macros remain empty. Two points worth knowing about it: The reachability paragraph is the part that earns its place. Without it the change reads as defensive tidying of a rare error path; with it, the leak sits on the only failure this caller can produce, and the thing producing it is the unchecked call immediately above. That's also why the discarded _nx_crypto_drbg_initialize() return needs no separate fix — worth stating, since it's the obvious follow-up question a reviewer would raise. I verified every reference against the code rather than reusing the review's numbers: the acquire and release are the file's only pair (lines 1169 and 1178 after the fix), the macros default empty at nx_crypto_drbg.h:79-85, NX_CRYPTO_RBG aliases _nx_crypto_drbg inside the NX_CRYPTO_SELF_TEST branch of nx_crypto.h, and the EC callers are nx_crypto_ec.c:2945 and :4671. I left bare line numbers out of the message itself — they rot, and the identifiers locate everything unambiguously.
2026-03-07Updated copyright headers and version strings. Removed version historyFrédéric Desbiens
2025-03-18Updated version numbers to 6.4.3Frédéric Desbiens
2024-01-29Update copyright.Bo Chen (from Dev Box)
2023-10-23Update on 23 Oct 2023. Expand to see details.v6.3.0_relTiejun Zhou
002a5890e Generated rtxp demo in netxduo/samples folder. c09d9da51 Add function header in .h for RTP and RTSP f5a96f35b Update function header and version for 6.3.0 0ff7a6809 Correct dhcpv6 server for ignoring lifetime fields in client request 9a2129c35 Fixed dhcpv6 server not update client record issue e59d2b5f1 Fix dhcp coverage test compile wanrning d00655d71 Fix infinite loop issue in TCP & UDP free port find function c194c74ca Optimize rtp_sender and fix pipeline reported issues b6df8dea0 Add RTxP feature 38e57e633 Added test case for _nx_snmp_utility_object_id_get(). 321c88bd9 Added check for pdu length. 36ffb7c39 Fixed packet double release. 92166d736 Fixed SNMP test cases for v4_small_build 67f071552 Improved buffer length verification for padding. 30cc5d8b2 Fix wait option used in FTP test case 098a97213 Avoid duplicate packet release when DTLS send fails 15313e868 Improved buffer length verification for _nx_snmp_utility_object_id_set(). ecd3904d3 Fixed MSRC 81018 caa004007 Fix the logic of handling close notify packet from peer 2b8c87685 Removed main.c into netxduo/samples folder, then all addons can use it. c72c66cdc Fixed MSARC 81019 and MSRC 81079 8169be7a6 Fixed MSRC81005 and MSRC81020 41389b76b Fixed packet double release issue in _nx_ftp_client_file_write 19348e408 Combined the functions of processing snmp v1 and v2. 9174b6457 Fixed icmpv6 ra buffer overwrite test case. 6bdc703d9 Fixed packet double release issue in _nx_nat_process_packet 403ecd128 Set nx_smtp_server_packet to NULL to avoided duplicate packet release in _nx_smtp_utility_read_server_code af5dd00c6 Disable FTP server MSS test case when packet chain is disabled beadbce12 Enable weekly pipeline build to avoid CodeQL expiration 5a3d88f97 Fixed MSRC 81528 df6a1fc57 unify the code. 18c13bfdb Fixed MSRC 80745. 2cce43f48 Fixed bug in utility/iperf/nx_iperf.c pointer used before set its value. 2477fb81c Update product owners 2f5734ada Fixed MSRC 80686 34e713e26 Fixed data length underflow when TCP MSS is less than 255 7097a7859 Improved the test cases for packet chain. 1ffa13cfa Fixed MSRC 80685 97e2b8d8e Set packet pointer to NULL after released to fix duplicate packet release issue c1e47efa7 Fix ICMPv6 NS buffer overwrite issue. c2770ea68 Add ICMPv6 NA buffer overwrite test case. 36bb05f85 Validated TCP header buffer to avoid span in multiple packets 84070bb2a Correct the length of packet buffer to avoid write overflow 5b3b3a10b Dropped packet chain for SNTP data to avoid write overflow 82699872d Onebranch build Image Update: Move pipelines to supported and compliant OneBranch container images a30171f93 Add a test case to demonstrate IGMP override caused by IP assembly. 72472ff4b Fix MSRC 80746 5d9f1266a Corrected the acked packet count when out of order is enabled b113ebdc9 Fixed DHCP server local variable type issue b70863299 Enable codeql in onebranch pipeline
2023-06-30Update on 30 Jun 2023. Expand to see details.Tiejun Zhou
06cb10f01 Fix typo in NetXDuo Crypto 996dd14fc BSD functions overriding option 3b756c219 Fix mqtt interoperability issue when upgrade to ubuntu 20.04 01ca51021 Added support for skipping failed step 3e3a15e79 Add record length checking in nxe_secure_tls_session_send. ec617d178 Fix demo_netx_secure_tls test link issue under nightly build a934cb718 Fix pipeline libgcc issue in nx_secure_interoperability test f08024578 Fix illegal access when NXD_MQTT_OVER_WEBSOCKET enabled 9798e2b89 Corrected the mDNS symbols check 456007dd1 Fixed multiple proxy update issue cf0bf15b5 Add TLS sample demo_netx_secure_tls.c. 87ea505bf Add sha256 in driver preprocess command for ADU 7e1b9686a Add pnp check for ADU ef78d336d Improved the code to ignore null file url.
2020-10-096.1 ReleaseScott Larson
2020-07-13updated to 6.0.1 and added additional processors/toolchainsv6.0.1_relScott Larson
2020-05-11Initial commitPProvost