Skip to content

Fix buffer-overflow in LMS leaf cache indexing#9919

Open
anhu wants to merge 1 commit intowolfSSL:masterfrom
anhu:lms-leaf-idx
Open

Fix buffer-overflow in LMS leaf cache indexing#9919
anhu wants to merge 1 commit intowolfSSL:masterfrom
anhu:lms-leaf-idx

Conversation

@anhu
Copy link
Member

@anhu anhu commented Mar 7, 2026

wc_lms_treehash_init() writes leaf node hashes into the leaf cache using an absolute index (i * hash_len), but the cache is only max_cb entries starting from leaf->idx. When leaf->idx > 0 (which occurs when wc_LmsKey_Reload is called after signing more than max_cb times), the write goes past the end of the cache buffer.

Fix by using the relative offset (i - leaf->idx) * hash_len instead.

Added unit tests (test_lms.c):

  • test_wc_LmsKey_sign_verify: basic sign/verify sanity check
  • test_wc_LmsKey_reload_cache: (TDD) reproduces the overflow by signing 33 times then reloading the key

@anhu anhu requested a review from wolfSSL-Bot March 7, 2026 18:38
@anhu anhu self-assigned this Mar 7, 2026
@anhu anhu added the For This Release Release version 5.9.0 label Mar 7, 2026
@anhu
Copy link
Member Author

anhu commented Mar 7, 2026

No ZD, No issue. Found while making a wolfboot demo.

wc_lms_treehash_init() writes leaf node hashes into the leaf cache
using an absolute index (i * hash_len), but the cache is only
max_cb entries starting from leaf->idx. When leaf->idx > 0 (which
occurs when wc_LmsKey_Reload is called after signing more than
max_cb times), the write goes past the end of the cache buffer.

Fix by using the relative offset (i - leaf->idx) * hash_len instead.

Added unit tests (test_lms.c):
  - test_wc_LmsKey_sign_verify: basic sign/verify sanity check
  - test_wc_LmsKey_reload_cache: (TDD) reproduces the overflow by
    signing 33 times then reloading the key
@anhu
Copy link
Member Author

anhu commented Mar 8, 2026

Jenkins retest this please.

@anhu
Copy link
Member Author

anhu commented Mar 8, 2026

jenkins retest this please.

@anhu
Copy link
Member Author

anhu commented Mar 8, 2026

jenkins retest this please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For This Release Release version 5.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant