Commit d2bdd268 authored by Vakul Garg's avatar Vakul Garg Committed by David S. Miller

net/tls: Use aead_request_alloc/free for request alloc/free

Instead of kzalloc/free for aead_request allocation and free, use
functions aead_request_alloc(), aead_request_free(). It ensures that
any sensitive crypto material held in crypto transforms is securely
erased from memory.
Signed-off-by: default avatarVakul Garg <vakul.garg@nxp.com>
Acked-by: default avatarDave Watson <davejwatson@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cba54f9c
...@@ -57,14 +57,11 @@ static int tls_do_decryption(struct sock *sk, ...@@ -57,14 +57,11 @@ static int tls_do_decryption(struct sock *sk,
struct aead_request *aead_req; struct aead_request *aead_req;
int ret; int ret;
unsigned int req_size = sizeof(struct aead_request) +
crypto_aead_reqsize(ctx->aead_recv);
aead_req = kzalloc(req_size, flags); aead_req = aead_request_alloc(ctx->aead_recv, flags);
if (!aead_req) if (!aead_req)
return -ENOMEM; return -ENOMEM;
aead_request_set_tfm(aead_req, ctx->aead_recv);
aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE); aead_request_set_ad(aead_req, TLS_AAD_SPACE_SIZE);
aead_request_set_crypt(aead_req, sgin, sgout, aead_request_set_crypt(aead_req, sgin, sgout,
data_len + tls_ctx->rx.tag_size, data_len + tls_ctx->rx.tag_size,
...@@ -86,7 +83,7 @@ static int tls_do_decryption(struct sock *sk, ...@@ -86,7 +83,7 @@ static int tls_do_decryption(struct sock *sk,
ctx->saved_data_ready(sk); ctx->saved_data_ready(sk);
out: out:
kfree(aead_req); aead_request_free(aead_req);
return ret; return ret;
} }
...@@ -224,8 +221,7 @@ static int tls_push_record(struct sock *sk, int flags, ...@@ -224,8 +221,7 @@ static int tls_push_record(struct sock *sk, int flags,
struct aead_request *req; struct aead_request *req;
int rc; int rc;
req = kzalloc(sizeof(struct aead_request) + req = aead_request_alloc(ctx->aead_send, sk->sk_allocation);
crypto_aead_reqsize(ctx->aead_send), sk->sk_allocation);
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
...@@ -267,7 +263,7 @@ static int tls_push_record(struct sock *sk, int flags, ...@@ -267,7 +263,7 @@ static int tls_push_record(struct sock *sk, int flags,
tls_advance_record_sn(sk, &tls_ctx->tx); tls_advance_record_sn(sk, &tls_ctx->tx);
out_req: out_req:
kfree(req); aead_request_free(req);
return rc; return rc;
} }
......
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