Skip to content

Fix blake2b_final coverity reports#9003

Merged
JacobBarthelmeh merged 2 commits intowolfSSL:masterfrom
embhorn:cov_531298
Jul 14, 2025
Merged

Fix blake2b_final coverity reports#9003
JacobBarthelmeh merged 2 commits intowolfSSL:masterfrom
embhorn:cov_531298

Conversation

@embhorn
Copy link
Copy Markdown
Member

@embhorn embhorn commented Jul 14, 2025

Description

  • OOB access in blake2b_final
  • Use memmove instead of memcpy

Testing

Coverity confirmed

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Jul 14, 2025
@embhorn embhorn requested a review from Copilot July 14, 2025 20:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes an out-of-bounds access in blake2b_final by tightening the buffer-length check and using a safe copy function for overlapping memory regions.

  • Changed the boundary condition to reject more than one full block leftover.
  • Swapped XMEMCPY for XMEMMOVE to safely handle overlapping buffer regions.
Comments suppressed due to low confidence (2)

wolfcrypt/src/blake2b.c:359

  • The new boundary check for leftover bytes isn't covered by existing tests. Add unit tests for cases where buflen is just above and just below BLAKE2B_BLOCKBYTES to ensure correct behavior.
    if ( S->buflen > BLAKE2B_BLOCKBYTES )

wolfcrypt/src/blake2b.c:361

  • [nitpick] Please update the function’s doxygen or inline comments to explain why XMEMMOVE is used instead of XMEMCPY, clarifying the need for safe overlapping memory copies.
    XMEMMOVE( S->buf, S->buf + BLAKE2B_BLOCKBYTES, (wolfssl_word)S->buflen );

@embhorn embhorn added the For This Release Release version 5.9.1 label Jul 14, 2025
@embhorn
Copy link
Copy Markdown
Member Author

embhorn commented Jul 14, 2025

Retest this please

Build [wolfSSL » PRB-140-3-tests #5865](https://cloud.wolfssl-test.com/jenkins/job/wolfSSL/job/PRB-140-3-tests/5865/) completed: FAILURE
[Pipeline] }
[wolfSSL » PRB-140-3-tests #5865](https://cloud.wolfssl-test.com/jenkins/job/wolfSSL/job/PRB-140-3-tests/5865/) completed with status FAILURE (propagate: false to ignore)
org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 3ffca30a-ed4f-48d5-8bdd-d135757929af
java.io.StreamCorruptedException: invalid stream header: 636F7272
	at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:958)
	at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:392)
	at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:50)
	at hudson.remoting.Command.readFrom(Command.java:141)
	at hudson.remoting.Command.readFrom(Command.java:127)

@embhorn embhorn requested a review from rlm2002 July 14, 2025 21:25
@embhorn embhorn assigned wolfSSL-Bot and rlm2002 and unassigned embhorn Jul 14, 2025
@JacobBarthelmeh JacobBarthelmeh merged commit 9430c8a into wolfSSL:master Jul 14, 2025
243 checks passed
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.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants