Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMS: make cms->selected_digest an index (again)
In 926782c, we switched cms->selected_digest to be a pointer to the entry in cms->digests. Because cms->digests is lazily allocated, setting the selected_digest pointer has to be done at the right part of the CMS context life cycle, and in some cases it clearly is not: ==334217== Command: ./src/pesign -n tmp -s --pinfile tmp/pinfile -t OpenSC\ Card\ (testcard) -c kernel-signer -i tmp/unsigned.efi -o tmp/signed.efi --force ==334217== ==334217== Invalid read of size 8 ==334217== at 0x115E7D: digest_get_digest_oid (cms_common.c:59) ==334217== by 0x11CF41: generate_algorithm_id_list (signed_data.c:33) ==334217== by 0x11D348: generate_spc_signed_data (signed_data.c:279) ==334217== by 0x11EDFD: calculate_signature_space (wincert.c:297) ==334217== by 0x11467D: pe_handle_action (file_pe.c:298) ==334217== by 0x10F962: main (pesign.c:585) ==334217== Address 0x10 is not stack'd, malloc'd or (recently) free'd ==334217== ==334217== ==334217== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==334217== Access not within mapped region at address 0x10 ==334217== at 0x115E7D: digest_get_digest_oid (cms_common.c:59) ==334217== by 0x11CF41: generate_algorithm_id_list (signed_data.c:33) ==334217== by 0x11D348: generate_spc_signed_data (signed_data.c:279) ==334217== by 0x11EDFD: calculate_signature_space (wincert.c:297) ==334217== by 0x11467D: pe_handle_action (file_pe.c:298) ==334217== by 0x10F962: main (pesign.c:585) ==334217== If you believe this happened as a result of a stack ==334217== overflow in your program's main thread (unlikely but ==334217== possible), you can try to increase the size of the ==334217== main thread stack using the --main-stacksize= flag. ==334217== The main thread stack size used in this run was 8388608. ==334217== ==334217== HEAP SUMMARY: ==334217== in use at exit: 588,544 bytes in 4,388 blocks ==334217== total heap usage: 8,568 allocs, 4,180 frees, 2,077,115 bytes allocated ==334217== ==334217== LEAK SUMMARY: ==334217== definitely lost: 25 bytes in 1 blocks ==334217== indirectly lost: 0 bytes in 0 blocks ==334217== possibly lost: 51,378 bytes in 166 blocks ==334217== still reachable: 537,141 bytes in 4,221 blocks ==334217== of which reachable via heuristic: ==334217== length64 : 321,312 bytes in 590 blocks ==334217== suppressed: 0 bytes in 0 blocks ==334217== Rerun with --leak-check=full to see details of leaked memory ==334217== ==334217== For lists of detected and suppressed errors, rerun with: -s ==334217== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) Segmentation fault (core dumped) There is also a similar issue in the daemon code, and how to fix it there is not immediately clear to me. Currently, we realistically only support using sha256 digests, so for now I've chosen to paper over the issue by switching back to cms->selected_digest be an index into both ctx->digests and digest_params, but switching the default value from -1 to 0, aka DIGEST_PARAM_SHA256. We can revisit this issue later whenever we add sha384 support (or whichever other digest). Signed-off-by: Peter Jones <[email protected]>
- Loading branch information