All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/tipc: Check null mem pointer
@ 2021-12-24  7:46 Jiasheng Jiang
  2021-12-24 22:34 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-24  7:46 UTC (permalink / raw)
  To: jmaloy, ying.xue, davem, kuba
  Cc: netdev, tipc-discussion, linux-kernel, Jiasheng Jiang

For the possible alloc failure of the kmemdup(), it may return null
pointer.
Therefore, the returned pointer should be checked to guarantee the
success of the init.

Fixes: fc1b6d6de220 ("tipc: introduce TIPC encryption & authentication")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 net/tipc/crypto.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index c9391d38de85..19015e08e750 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -596,7 +596,14 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
 	tmp->mode = mode;
 	tmp->cloned = NULL;
 	tmp->authsize = TIPC_AES_GCM_TAG_SIZE;
+
 	tmp->key = kmemdup(ukey, tipc_aead_key_size(ukey), GFP_KERNEL);
+	if (!tmp->key) {
+		free_percpu(tmp->tfm_entry);
+		kfree_sensitive(tmp);
+		return -ENOMEM;
+	}
+
 	memcpy(&tmp->salt, ukey->key + keylen, TIPC_AES_GCM_SALT_SIZE);
 	atomic_set(&tmp->users, 0);
 	atomic64_set(&tmp->seqno, 0);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/tipc: Check null mem pointer
  2021-12-24  7:46 [PATCH] net/tipc: Check null mem pointer Jiasheng Jiang
@ 2021-12-24 22:34 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-12-24 22:34 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: jmaloy, ying.xue, davem, netdev, tipc-discussion, linux-kernel

On Fri, 24 Dec 2021 15:46:46 +0800 Jiasheng Jiang wrote:
> For the possible alloc failure of the kmemdup(), it may return null
> pointer.
> Therefore, the returned pointer should be checked to guarantee the
> success of the init.
> 
> Fixes: fc1b6d6de220 ("tipc: introduce TIPC encryption & authentication")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  net/tipc/crypto.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> index c9391d38de85..19015e08e750 100644
> --- a/net/tipc/crypto.c
> +++ b/net/tipc/crypto.c
> @@ -596,7 +596,14 @@ static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
>  	tmp->mode = mode;
>  	tmp->cloned = NULL;
>  	tmp->authsize = TIPC_AES_GCM_TAG_SIZE;
> +
>  	tmp->key = kmemdup(ukey, tipc_aead_key_size(ukey), GFP_KERNEL);
> +	if (!tmp->key) {
> +		free_percpu(tmp->tfm_entry);
> +		kfree_sensitive(tmp);
> +		return -ENOMEM;
> +	}
> +
>  	memcpy(&tmp->salt, ukey->key + keylen, TIPC_AES_GCM_SALT_SIZE);
>  	atomic_set(&tmp->users, 0);
>  	atomic64_set(&tmp->seqno, 0);

Fixed over a month ago 3e6db079751a ("tipc: check for null after calling
kmemdup")

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-24 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24  7:46 [PATCH] net/tipc: Check null mem pointer Jiasheng Jiang
2021-12-24 22:34 ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.