@@ -4784,11 +4784,17 @@ static int _HandleSha256Dma(whServerContext* ctx, uint16_t magic, int devId,
47844784 res .dmaAddrStatus .badAddr = req .state ;
47854785 }
47864786 else {
4787- /* Save the client devId to be restored later, when the context is
4788- * copied back into client memory. */
4789- clientDevId = sha256 -> devId ;
4790- /* overwrite the devId to that of the server for local crypto */
4791- sha256 -> devId = devId ;
4787+ /* Validate buffLen from untrusted context */
4788+ if (sha256 -> buffLen > WC_SHA256_BLOCK_SIZE ) {
4789+ ret = WH_ERROR_BADARGS ;
4790+ }
4791+ else {
4792+ /* Save the client devId to be restored later, when the context
4793+ * is copied back into client memory. */
4794+ clientDevId = sha256 -> devId ;
4795+ /* overwrite the devId to that of the server for local crypto */
4796+ sha256 -> devId = devId ;
4797+ }
47924798 }
47934799 }
47944800
@@ -4906,11 +4912,17 @@ static int _HandleSha224Dma(whServerContext* ctx, uint16_t magic, int devId,
49064912 res .dmaAddrStatus .badAddr = req .state ;
49074913 }
49084914 else {
4909- /* Save the client devId to be restored later, when the context is
4910- * copied back into client memory. */
4911- clientDevId = sha224 -> devId ;
4912- /* overwrite the devId to that of the server for local crypto */
4913- sha224 -> devId = devId ;
4915+ /* Validate buffLen from untrusted context */
4916+ if (sha224 -> buffLen > WC_SHA224_BLOCK_SIZE ) {
4917+ ret = WH_ERROR_BADARGS ;
4918+ }
4919+ else {
4920+ /* Save the client devId to be restored later, when the context
4921+ * is copied back into client memory. */
4922+ clientDevId = sha224 -> devId ;
4923+ /* overwrite the devId to that of the server for local crypto */
4924+ sha224 -> devId = devId ;
4925+ }
49144926 }
49154927 }
49164928
@@ -5028,11 +5040,17 @@ static int _HandleSha384Dma(whServerContext* ctx, uint16_t magic, int devId,
50285040 res .dmaAddrStatus .badAddr = req .state ;
50295041 }
50305042 else {
5031- /* Save the client devId to be restored later, when the context is
5032- * copied back into client memory. */
5033- clientDevId = sha384 -> devId ;
5034- /* overwrite the devId to that of the server for local crypto */
5035- sha384 -> devId = devId ;
5043+ /* Validate buffLen from untrusted context */
5044+ if (sha384 -> buffLen > WC_SHA384_BLOCK_SIZE ) {
5045+ ret = WH_ERROR_BADARGS ;
5046+ }
5047+ else {
5048+ /* Save the client devId to be restored later, when the context
5049+ * is copied back into client memory. */
5050+ clientDevId = sha384 -> devId ;
5051+ /* overwrite the devId to that of the server for local crypto */
5052+ sha384 -> devId = devId ;
5053+ }
50365054 }
50375055 }
50385056
@@ -5150,13 +5168,25 @@ static int _HandleSha512Dma(whServerContext* ctx, uint16_t magic, int devId,
51505168 res .dmaAddrStatus .badAddr = req .state ;
51515169 }
51525170 else {
5153- /* Save the client devId to be restored later, when the context is
5154- * copied back into client memory. */
5155- clientDevId = sha512 -> devId ;
5156- /* overwrite the devId to that of the server for local crypto */
5157- sha512 -> devId = devId ;
5158- /* retrieve hash Type to handle 512, 512-224, or 512-256 */
5159- hashType = sha512 -> hashType ;
5171+ /* Validate buffLen from untrusted context */
5172+ if (sha512 -> buffLen > WC_SHA512_BLOCK_SIZE ) {
5173+ ret = WH_ERROR_BADARGS ;
5174+ }
5175+ else {
5176+ /* Save the client devId to be restored later, when the context
5177+ * is copied back into client memory. */
5178+ clientDevId = sha512 -> devId ;
5179+ /* overwrite the devId to that of the server for local crypto */
5180+ sha512 -> devId = devId ;
5181+ /* retrieve hash Type to handle 512, 512-224, or 512-256 */
5182+ hashType = sha512 -> hashType ;
5183+ /* Validate hashType from untrusted context */
5184+ if (hashType != WC_HASH_TYPE_SHA512 &&
5185+ hashType != WC_HASH_TYPE_SHA512_224 &&
5186+ hashType != WC_HASH_TYPE_SHA512_256 ) {
5187+ ret = WH_ERROR_BADARGS ;
5188+ }
5189+ }
51605190 }
51615191 }
51625192
0 commit comments