-
Notifications
You must be signed in to change notification settings - Fork 31
Add missing input validation to VERIFY_ACERT and VERIFY cert handler #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -515,6 +515,16 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |
| wh_MessageCert_TranslateVerifyRequest( | ||
| magic, (whMessageCert_VerifyRequest*)req_packet, &req); | ||
|
|
||
| /* Validate certificate data fits within request */ | ||
| if (req.cert_len > req_size - sizeof(req)) { | ||
| resp.rc = WH_ERROR_BADARGS; | ||
| wh_MessageCert_TranslateVerifyResponse( | ||
| magic, &resp, | ||
| (whMessageCert_VerifyResponse*)resp_packet); | ||
| *out_resp_size = sizeof(resp); | ||
| break; | ||
| } | ||
|
Comment on lines
+519
to
+526
|
||
|
|
||
| /* Get pointer to certificate data */ | ||
| cert_data = (const uint8_t*)req_packet + sizeof(req); | ||
|
|
||
|
|
@@ -703,10 +713,28 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |
| whMessageCert_SimpleResponse resp = {0}; | ||
| const uint8_t* cert_data = NULL; | ||
|
|
||
| /* Validate minimum request size */ | ||
| if (req_size < sizeof(req)) { | ||
| resp.rc = WH_ERROR_ABORTED; | ||
| wh_MessageCert_TranslateSimpleResponse( | ||
| magic, &resp, (whMessageCert_SimpleResponse*)resp_packet); | ||
| *out_resp_size = sizeof(resp); | ||
| break; | ||
| } | ||
|
|
||
| /* Convert request struct */ | ||
| wh_MessageCert_TranslateVerifyAcertRequest( | ||
| magic, (whMessageCert_VerifyAcertRequest*)req_packet, &req); | ||
|
|
||
| /* Validate certificate data fits within request */ | ||
| if (req.cert_len > req_size - sizeof(req)) { | ||
| resp.rc = WH_ERROR_BADARGS; | ||
| wh_MessageCert_TranslateSimpleResponse( | ||
| magic, &resp, (whMessageCert_SimpleResponse*)resp_packet); | ||
| *out_resp_size = sizeof(resp); | ||
| break; | ||
| } | ||
|
|
||
| cert_data = (const uint8_t*)req_packet + sizeof(req); | ||
|
|
||
| /* Process the verify action */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the VERIFY handler, the request is translated before any minimum-size check, which can allow an out-of-bounds read if
req_size < sizeof(req). Additionally,req_size - sizeof(req)can underflow (if unsigned) and incorrectly bypass the bounds check. Add a minimum request-size validation (like the VERIFY_ACERT path) beforewh_MessageCert_TranslateVerifyRequest(...), and only computereq_size - sizeof(req)after confirmingreq_size >= sizeof(req).