test: [kat-app] remove unsafe SNOW3G key pointer casts#178
Closed
iragimov-arm wants to merge 1 commit into
Closed
Conversation
Change submit_uea2_jobs() to take snow3g_key_schedule_t *const *keys instead of uint8_t **const keys and update the call sites to pass typed key-schedule pointers directly. This removes unsafe pointer casts in the SNOW3G KAT job API path and fixes invalid key handling that triggers IMB_STATUS_INVALID_ARGS with newer Clang compilers such as clang-21 and clang-22. Signed-off-by: Islam Ragimov <islam.ragimov@arm.com>
Contributor
|
This is now merged into main. Closing this PR. Thank you for your contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
submit_uea2_jobs()to takesnow3g_key_schedule_t *const *keysinstead ofuint8_t **constkeys and update the call sites to pass typed key-schedule pointers directly. This removes unsafe pointer casts in the SNOW3G KAT job API path and fixes invalid key handling that triggersIMB_STATUS_INVALID_ARGSwith newer Clang compilers such as clang-21 and clang-22.Description
When built with clang version >= 20, the KAT tests fail for SNOW3G-UEA.
Clang-22: SNOW3G KAT output before the patch:
./build/test/kat-app/imb-kat --test-type snow3g Detected library version: 3.0.0-dev Tool version: 3.0.0-dev Detected hardware features: XSAVE : OK OSXSAVE : OK SHANI : OK AESNI : OK PCLMULQDQ : OK MOVBE : OK CMOV : OK SSE4.2 : OK AVX : OK AVX2 : OK AVX512(SKX) : n/a VAES : OK VPCLMULQDQ : OK GFNI : OK AVX512-IFMA : n/a AVX-IFMA : n/a BMI2 : OK HYBRID-CORE : OK SM3NI : n/a SM4NI : n/a SHA512NI : n/a APX : n/a AVX10-256 : n/a AVX10-512 : n/a SELF-TEST: PASS [INFO] [ARCH] using SSE interface [SSE-SHANI-GFNI] 199 error status:4, job 0IMB_SNOW3G_F8_8_BUFFER(Enc) vector:1 buffer:0 Actual:: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Expected:: 0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 199 error status:4, job 0snow3g_f8_8_multi_buffer(Enc) vector:1 buffer:0 Actual:: 0x91 0x09 0x68 0xF8 0x95 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C Expected:: 0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C [INFO] [ALGO] SNOW3G-UEA2 FAIL [INFO] [ALGO] SNOW3G-UIA2 PASS SELF-TEST: PASS [INFO] [ARCH] using AVX2 interface [AVX2] 199 error status:4, job 0IMB_SNOW3G_F8_8_BUFFER(Enc) vector:1 buffer:0 Actual:: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Expected:: 0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C 199 error status:4, job 0snow3g_f8_8_multi_buffer(Enc) vector:1 buffer:0 Actual:: 0xB1 0x01 0x68 0xF8 0x95 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C Expected:: 0x5D 0x5B 0xFE 0x75 0xEB 0x04 0xF6 0x8C 0xE0 0xA1 0x23 0x77 0xEA 0x00 0xB3 0x7D 0x47 0xC6 0xA0 0xBA 0x06 0x30 0x91 0x55 0x08 0x6A 0x85 0x9C 0x43 0x41 0xB3 0x7C [INFO] [ALGO] SNOW3G-UEA2 FAIL [INFO] [ALGO] SNOW3G-UIA2 PASS Test completed: FAILAs indicated by the error message specifically:
199 error status:4the problem occurs at the stage of passing data through the Job API. Status 4 is a
job->statusvalue equal toIMB_STATUS_INVALID_ARGS.After a brief analysis, it became clear that the root cause of the error is an attempt to pass an invalid pointer to the keys for SNOW3G algorithms. In the
is_job_invalid()function fromlib/include/mb_mgr_job_check.hfile, the keys are checked againstNULLand fail this validation:This issue is unrelated to the algorithm implementations themselves, since execution never reaches them. The algorithms have also been tested via the Direct API. The problem is not an internal issue of the Job API either, as all keys are properly initialized in the test source code before the algorithms are executed.
This error occurs only in the Release build and is not detected in the Debug build.
It turns out that the root cause lies in the test code. Specifically, the issue is caused by passing keys between functions using a cast to
uint8_t **.How Has This Been Tested?
Hardware:
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Vendor ID: GenuineIntel Model name: 13th Gen Intel(R) Core(TM) i7-1365U CPU family: 6 Model: 186 Thread(s) per core: 2 Core(s) per socket: 10 Socket(s): 1 Stepping: 3 CPU max MHz: 5200.0000 CPU min MHz: 400.0000 BogoMIPS: 5376.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_kno wn_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanc ed tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_not ify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_userCompiler:
Test command line:
./build/test/kat-app/imb-kat --test-type snow3gTest output:
Detected library version: 3.0.0-dev Tool version: 3.0.0-dev Detected hardware features: XSAVE : OK OSXSAVE : OK SHANI : OK AESNI : OK PCLMULQDQ : OK MOVBE : OK CMOV : OK SSE4.2 : OK AVX : OK AVX2 : OK AVX512(SKX) : n/a VAES : OK VPCLMULQDQ : OK GFNI : OK AVX512-IFMA : n/a AVX-IFMA : n/a BMI2 : OK HYBRID-CORE : OK SM3NI : n/a SM4NI : n/a SHA512NI : n/a APX : n/a AVX10-256 : n/a AVX10-512 : n/a SELF-TEST: PASS [INFO] [ARCH] using SSE interface [SSE-SHANI-GFNI] [INFO] [ALGO] SNOW3G-UEA2 PASS [INFO] [ALGO] SNOW3G-UIA2 PASS SELF-TEST: PASS [INFO] [ARCH] using AVX2 interface [AVX2] [INFO] [ALGO] SNOW3G-UEA2 PASS [INFO] [ALGO] SNOW3G-UIA2 PASS Test completed: PASSChecklist