Skip to content

Commit af2e53f

Browse files
ryaotonyhutter
authored andcommitted
Fix possible NULL pointer dereference in sha2_mac_init()
If mechanism->cm_param is NULL, passing mechanism to PROV_SHA2_GET_DIGEST_LEN() will dereference a NULL pointer. Coverity reported this. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes openzfs#14044
1 parent 89c41f3 commit af2e53f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

module/icp/io/sha2_mod.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,15 @@ sha2_mac_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
823823
*/
824824
if (mechanism->cm_type % 3 == 2) {
825825
if (mechanism->cm_param == NULL ||
826-
mechanism->cm_param_len != sizeof (ulong_t))
827-
ret = CRYPTO_MECHANISM_PARAM_INVALID;
828-
PROV_SHA2_GET_DIGEST_LEN(mechanism,
829-
PROV_SHA2_HMAC_CTX(ctx)->hc_digest_len);
830-
if (PROV_SHA2_HMAC_CTX(ctx)->hc_digest_len > sha_digest_len)
826+
mechanism->cm_param_len != sizeof (ulong_t)) {
831827
ret = CRYPTO_MECHANISM_PARAM_INVALID;
828+
} else {
829+
PROV_SHA2_GET_DIGEST_LEN(mechanism,
830+
PROV_SHA2_HMAC_CTX(ctx)->hc_digest_len);
831+
if (PROV_SHA2_HMAC_CTX(ctx)->hc_digest_len >
832+
sha_digest_len)
833+
ret = CRYPTO_MECHANISM_PARAM_INVALID;
834+
}
832835
}
833836

834837
if (ret != CRYPTO_SUCCESS) {

0 commit comments

Comments
 (0)