Commit 0e579cd1 authored by Namjae Jeon's avatar Namjae Jeon

cifsd: return -ENOMEM about error from ksmbd_crypto_ctx_find_xxx calls

Return -ENOMEM about error from ksmbd_crypto_ctx_find_xxx calls.
And remove unneeded return value print in debug message.
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent d3cd8c49
...@@ -128,7 +128,7 @@ static int ksmbd_enc_md4(unsigned char *md4_hash, unsigned char *link_str, ...@@ -128,7 +128,7 @@ static int ksmbd_enc_md4(unsigned char *md4_hash, unsigned char *link_str,
ctx = ksmbd_crypto_ctx_find_md4(); ctx = ksmbd_crypto_ctx_find_md4();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "Crypto md4 allocation error\n"); ksmbd_debug(AUTH, "Crypto md4 allocation error\n");
return -EINVAL; return -ENOMEM;
} }
rc = crypto_shash_init(CRYPTO_MD4(ctx)); rc = crypto_shash_init(CRYPTO_MD4(ctx));
...@@ -160,7 +160,7 @@ static int ksmbd_enc_update_sess_key(unsigned char *md5_hash, char *nonce, ...@@ -160,7 +160,7 @@ static int ksmbd_enc_update_sess_key(unsigned char *md5_hash, char *nonce,
ctx = ksmbd_crypto_ctx_find_md5(); ctx = ksmbd_crypto_ctx_find_md5();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "Crypto md5 allocation error\n"); ksmbd_debug(AUTH, "Crypto md5 allocation error\n");
return -EINVAL; return -ENOMEM;
} }
rc = crypto_shash_init(CRYPTO_MD5(ctx)); rc = crypto_shash_init(CRYPTO_MD5(ctx));
...@@ -200,11 +200,13 @@ static int ksmbd_gen_sess_key(struct ksmbd_session *sess, char *hash, ...@@ -200,11 +200,13 @@ static int ksmbd_gen_sess_key(struct ksmbd_session *sess, char *hash,
char *hmac) char *hmac)
{ {
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
int rc = -EINVAL; int rc;
ctx = ksmbd_crypto_ctx_find_hmacmd5(); ctx = ksmbd_crypto_ctx_find_hmacmd5();
if (!ctx) if (!ctx) {
goto out; ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
return -ENOMEM;
}
rc = crypto_shash_setkey(CRYPTO_HMACMD5_TFM(ctx), rc = crypto_shash_setkey(CRYPTO_HMACMD5_TFM(ctx),
hash, hash,
...@@ -244,7 +246,7 @@ static int ksmbd_gen_sess_key(struct ksmbd_session *sess, char *hash, ...@@ -244,7 +246,7 @@ static int ksmbd_gen_sess_key(struct ksmbd_session *sess, char *hash,
static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash, static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash,
char *dname) char *dname)
{ {
int ret = -EINVAL, len; int ret, len;
wchar_t *domain = NULL; wchar_t *domain = NULL;
__le16 *uniname = NULL; __le16 *uniname = NULL;
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
...@@ -252,7 +254,7 @@ static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash, ...@@ -252,7 +254,7 @@ static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash,
ctx = ksmbd_crypto_ctx_find_hmacmd5(); ctx = ksmbd_crypto_ctx_find_hmacmd5();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "can't generate ntlmv2 hash\n"); ksmbd_debug(AUTH, "can't generate ntlmv2 hash\n");
goto out; return -ENOMEM;
} }
ret = crypto_shash_setkey(CRYPTO_HMACMD5_TFM(ctx), ret = crypto_shash_setkey(CRYPTO_HMACMD5_TFM(ctx),
...@@ -374,12 +376,12 @@ int ksmbd_auth_ntlmv2(struct ksmbd_session *sess, struct ntlmv2_resp *ntlmv2, ...@@ -374,12 +376,12 @@ int ksmbd_auth_ntlmv2(struct ksmbd_session *sess, struct ntlmv2_resp *ntlmv2,
char ntlmv2_rsp[CIFS_HMAC_MD5_HASH_SIZE]; char ntlmv2_rsp[CIFS_HMAC_MD5_HASH_SIZE];
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
char *construct = NULL; char *construct = NULL;
int rc = -EINVAL, len; int rc, len;
ctx = ksmbd_crypto_ctx_find_hmacmd5(); ctx = ksmbd_crypto_ctx_find_hmacmd5();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5 rc %d\n", rc); ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
goto out; return -ENOMEM;
} }
rc = calc_ntlmv2_hash(sess, ntlmv2_hash, domain_name); rc = calc_ntlmv2_hash(sess, ntlmv2_hash, domain_name);
...@@ -731,13 +733,12 @@ int ksmbd_sign_smb2_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, ...@@ -731,13 +733,12 @@ int ksmbd_sign_smb2_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov,
int n_vec, char *sig) int n_vec, char *sig)
{ {
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
int rc = -EINVAL; int rc, i;
int i;
ctx = ksmbd_crypto_ctx_find_hmacsha256(); ctx = ksmbd_crypto_ctx_find_hmacsha256();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5 rc %d\n", rc); ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
goto out; return -ENOMEM;
} }
rc = crypto_shash_setkey(CRYPTO_HMACSHA256_TFM(ctx), rc = crypto_shash_setkey(CRYPTO_HMACSHA256_TFM(ctx),
...@@ -783,13 +784,12 @@ int ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, ...@@ -783,13 +784,12 @@ int ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov,
int n_vec, char *sig) int n_vec, char *sig)
{ {
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
int rc = -EINVAL; int rc, i;
int i;
ctx = ksmbd_crypto_ctx_find_cmacaes(); ctx = ksmbd_crypto_ctx_find_cmacaes();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not crypto alloc cmac rc %d\n", rc); ksmbd_debug(AUTH, "could not crypto alloc cmac\n");
goto out; return -ENOMEM;
} }
rc = crypto_shash_setkey(CRYPTO_CMACAES_TFM(ctx), rc = crypto_shash_setkey(CRYPTO_CMACAES_TFM(ctx),
...@@ -835,7 +835,7 @@ static int generate_key(struct ksmbd_session *sess, struct kvec label, ...@@ -835,7 +835,7 @@ static int generate_key(struct ksmbd_session *sess, struct kvec label,
__u8 i[4] = {0, 0, 0, 1}; __u8 i[4] = {0, 0, 0, 1};
__u8 L128[4] = {0, 0, 0, 128}; __u8 L128[4] = {0, 0, 0, 128};
__u8 L256[4] = {0, 0, 1, 0}; __u8 L256[4] = {0, 0, 1, 0};
int rc = -EINVAL; int rc;
unsigned char prfhash[SMB2_HMACSHA256_SIZE]; unsigned char prfhash[SMB2_HMACSHA256_SIZE];
unsigned char *hashptr = prfhash; unsigned char *hashptr = prfhash;
struct ksmbd_crypto_ctx *ctx; struct ksmbd_crypto_ctx *ctx;
...@@ -845,8 +845,8 @@ static int generate_key(struct ksmbd_session *sess, struct kvec label, ...@@ -845,8 +845,8 @@ static int generate_key(struct ksmbd_session *sess, struct kvec label,
ctx = ksmbd_crypto_ctx_find_hmacsha256(); ctx = ksmbd_crypto_ctx_find_hmacsha256();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5 rc %d\n", rc); ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
goto smb3signkey_ret; return -ENOMEM;
} }
rc = crypto_shash_setkey(CRYPTO_HMACSHA256_TFM(ctx), rc = crypto_shash_setkey(CRYPTO_HMACSHA256_TFM(ctx),
...@@ -1057,7 +1057,7 @@ int ksmbd_gen_smb311_encryptionkey(struct ksmbd_session *sess) ...@@ -1057,7 +1057,7 @@ int ksmbd_gen_smb311_encryptionkey(struct ksmbd_session *sess)
int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf, int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
__u8 *pi_hash) __u8 *pi_hash)
{ {
int rc = -1; int rc;
struct smb2_hdr *rcv_hdr = (struct smb2_hdr *)buf; struct smb2_hdr *rcv_hdr = (struct smb2_hdr *)buf;
char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId; char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId;
int msg_size = be32_to_cpu(rcv_hdr->smb2_buf_length); int msg_size = be32_to_cpu(rcv_hdr->smb2_buf_length);
...@@ -1069,8 +1069,8 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf, ...@@ -1069,8 +1069,8 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
ctx = ksmbd_crypto_ctx_find_sha512(); ctx = ksmbd_crypto_ctx_find_sha512();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not alloc sha512 rc %d\n", rc); ksmbd_debug(AUTH, "could not alloc sha512\n");
goto out; return -ENOMEM;
} }
rc = crypto_shash_init(CRYPTO_SHA512(ctx)); rc = crypto_shash_init(CRYPTO_SHA512(ctx));
...@@ -1104,13 +1104,13 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf, ...@@ -1104,13 +1104,13 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
int ksmbd_gen_sd_hash(struct ksmbd_conn *conn, char *sd_buf, int len, int ksmbd_gen_sd_hash(struct ksmbd_conn *conn, char *sd_buf, int len,
__u8 *pi_hash) __u8 *pi_hash)
{ {
int rc = -1; int rc;
struct ksmbd_crypto_ctx *ctx = NULL; struct ksmbd_crypto_ctx *ctx = NULL;
ctx = ksmbd_crypto_ctx_find_sha256(); ctx = ksmbd_crypto_ctx_find_sha256();
if (!ctx) { if (!ctx) {
ksmbd_debug(AUTH, "could not alloc sha256 rc %d\n", rc); ksmbd_debug(AUTH, "could not alloc sha256\n");
goto out; return -ENOMEM;
} }
rc = crypto_shash_init(CRYPTO_SHA256(ctx)); rc = crypto_shash_init(CRYPTO_SHA256(ctx));
...@@ -1262,7 +1262,7 @@ int ksmbd_crypt_message(struct ksmbd_conn *conn, struct kvec *iov, ...@@ -1262,7 +1262,7 @@ int ksmbd_crypt_message(struct ksmbd_conn *conn, struct kvec *iov,
ctx = ksmbd_crypto_ctx_find_ccm(); ctx = ksmbd_crypto_ctx_find_ccm();
if (!ctx) { if (!ctx) {
ksmbd_err("crypto alloc failed\n"); ksmbd_err("crypto alloc failed\n");
return -EINVAL; return -ENOMEM;
} }
if (conn->cipher_type == SMB2_ENCRYPTION_AES128_GCM || if (conn->cipher_type == SMB2_ENCRYPTION_AES128_GCM ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment