All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
To: jmaloy@redhat.com, ying.xue@windriver.com, davem@davemloft.net,
	kuba@kernel.org
Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	Jiasheng Jiang <jiasheng@iscas.ac.cn>
Subject: [PATCH] net/tipc: Check null mem pointer
Date: Fri, 24 Dec 2021 15:46:46 +0800	[thread overview]
Message-ID: <20211224074646.1588903-1-jiasheng@iscas.ac.cn> (raw)

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


             reply	other threads:[~2021-12-24  7:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24  7:46 Jiasheng Jiang [this message]
2021-12-24 22:34 ` [PATCH] net/tipc: Check null mem pointer Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211224074646.1588903-1-jiasheng@iscas.ac.cn \
    --to=jiasheng@iscas.ac.cn \
    --cc=davem@davemloft.net \
    --cc=jmaloy@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.