Skip to content

Add checking in SHE response handlers#391

Open
padelsbach wants to merge 2 commits into
wolfSSL:mainfrom
padelsbach:she-response-checking
Open

Add checking in SHE response handlers#391
padelsbach wants to merge 2 commits into
wolfSSL:mainfrom
padelsbach:she-response-checking

Conversation

@padelsbach

Copy link
Copy Markdown
Contributor

Check for group, action and len in SHE response handlers. Found with experimental fuzzing.

Comment thread src/wh_client_she.c Outdated
@padelsbach padelsbach marked this pull request as ready for review May 29, 2026 23:07

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #391

Scan targets checked: wolfhsm-core-bugs, wolfhsm-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/wh_client_she.c Outdated
@padelsbach padelsbach force-pushed the she-response-checking branch from d367077 to 8616f78 Compare June 1, 2026 20:56
@padelsbach padelsbach removed their assignment Jun 1, 2026
Comment thread src/wh_client_she.c Outdated
Comment on lines +100 to +101
if (group != WH_MESSAGE_GROUP_SHE ||
action != WH_SHE_SET_UID ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

all these group and action checks are redundant, as they are handled in the comm layer. Otherwise every single client response check would need these.

Also, do you think the size check could be pushed down to the comm layer somehow in a uniform way, perhaps via same mechanism as #389 and #388? Currently these would need to be done inline everywhere.

Note we dont care THAT much about this fuzzing style stuff - currently the threat model is such that transports are trusted. If someone can modify data in your transport, all bets are off. So temped to just not do the infinite bikeshedding around input sanitation that fenrir keeps pointing out....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair. Updated the PR to add only the dataSz < sizeof(*resp) which seems legit useful

@bigbrett bigbrett assigned padelsbach and unassigned bigbrett Jun 9, 2026
@padelsbach padelsbach force-pushed the she-response-checking branch from 8616f78 to 6042240 Compare June 17, 2026 19:19
@padelsbach padelsbach force-pushed the she-response-checking branch from 6042240 to b22d178 Compare June 17, 2026 21:24
@padelsbach padelsbach assigned bigbrett and unassigned padelsbach Jun 17, 2026
@padelsbach

Copy link
Copy Markdown
Contributor Author

Passing over to @AlexLanzano in Brett's absence

@padelsbach padelsbach assigned AlexLanzano and unassigned bigbrett Jun 23, 2026
@padelsbach padelsbach requested a review from AlexLanzano June 23, 2026 20:58
AlexLanzano
AlexLanzano approved these changes Jun 24, 2026

@AlexLanzano AlexLanzano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, Actually on a second look these checks still wouldn't prevent an overflow since the data is copied prior to these check. This needs to be handled at the comm layer probably by adding a dataLen arg to the wh_Client_RecvResponse and propagating that to the comm layer.

@padelsbach

Copy link
Copy Markdown
Contributor Author

Hmm, Actually on a second look these checks still wouldn't prevent an overflow since the data is copied prior to these check. This needs to be handled at the comm layer probably by adding a dataLen arg to the wh_Client_RecvResponse and propagating that to the comm layer.

I think you're referring to this copy down in wh_CommClient_RecvResponse:

            if (    (data != NULL) &&
                    (data_size != 0) &&
                    (data != context->data)) {
                memcpy(data, context->data, data_size);
            }

The vast majority of the handlers provide the data buffer matching context->data, so the data != context->data check prevents this memcpy.

In any case, the checks added here are recv < expected so they wouldn't catch an overflow anyway. They're mainly to prevent a too small buffer from being over indexed.

But...

I see your point that this could be done in a more uniform way, perhaps by passing sizeof(*resp) into wh_Client_RecvResponse. I'm into it if we don't care about breaking the public API.

@AlexLanzano

Copy link
Copy Markdown
Member

I see your point that this could be done in a more uniform way, perhaps by passing sizeof(*resp) into wh_Client_RecvResponse. I'm into it if we don't care about breaking the public API.

Yeah, I think in this case it's fine to break the API. I don't believe that many (if any) users are calling the comm client send/recv functions directly in their applications

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants