Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -next] cxgb4/chcr: Fix error return code in chcr_ktls_dev_add()
@ 2020-05-09  8:05 Wei Yongjun
  2020-05-12  8:04 ` [PATCH] cxgb4/chcr: Fix a leak " Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2020-05-09  8:05 UTC (permalink / raw)
  To: Ayush Sawal, Vinay Kumar Yadav, Rohit Maheshwari, Herbert Xu
  Cc: Wei Yongjun, linux-crypto, kernel-janitors, Hulk Robot

Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Fixes: 34aba2c45024 ("cxgb4/chcr : Register to tls add and del callback")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/crypto/chelsio/chcr_ktls.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/crypto/chelsio/chcr_ktls.c b/drivers/crypto/chelsio/chcr_ktls.c
index 43d9e2420110..baaea8ce4080 100644
--- a/drivers/crypto/chelsio/chcr_ktls.c
+++ b/drivers/crypto/chelsio/chcr_ktls.c
@@ -501,12 +501,14 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 	dst = sk_dst_get(sk);
 	if (!dst) {
 		pr_err("DST entry not found\n");
+		ret = -ENOENT;
 		goto out2;
 	}
 	n = dst_neigh_lookup(dst, daaddr);
 	if (!n || !n->dev) {
 		pr_err("neighbour not found\n");
 		dst_release(dst);
+		ret = -ENOENT;
 		goto out2;
 	}
 	tx_info->l2te  = cxgb4_l2t_get(adap->l2t, n, n->dev, 0);
@@ -516,6 +518,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 
 	if (!tx_info->l2te) {
 		pr_err("l2t entry not found\n");
+		ret = -ENOENT;
 		goto out2;
 	}




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

* [PATCH] cxgb4/chcr: Fix a leak in chcr_ktls_dev_add()
  2020-05-09  8:05 [PATCH -next] cxgb4/chcr: Fix error return code in chcr_ktls_dev_add() Wei Yongjun
@ 2020-05-12  8:04 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2020-05-12  8:04 UTC (permalink / raw)
  To: Wei Yongjun, Rohit Maheshwari
  Cc: Ayush Sawal, Vinay Kumar Yadav, Herbert Xu, Wei Yongjun,
	linux-crypto, kernel-janitors, Hulk Robot

We need to free "tx_info->l2te" if chcr_setup_connection() fails.  My
other concern was that if we free "tx_info" then "tx_ctx->chcr_info"
points to a freed variable.  I don't think this causes a problem but
it's cleaner to reset it back to NULL.  Also I renamed the labels to
say what the gotos do instead of using numbered labels.

Fixes: 34aba2c45024 ("cxgb4/chcr : Register to tls add and del callback")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Applies on top of Wei Yongjun's patch.

 drivers/crypto/chelsio/chcr_ktls.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_ktls.c b/drivers/crypto/chelsio/chcr_ktls.c
index baaea8ce40806..3173ac3099bc6 100644
--- a/drivers/crypto/chelsio/chcr_ktls.c
+++ b/drivers/crypto/chelsio/chcr_ktls.c
@@ -478,7 +478,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 
 	tx_info->rx_qid = chcr_get_first_rx_qid(adap);
 	if (unlikely(tx_info->rx_qid < 0))
-		goto out2;
+		goto free_tx_info;
 
 	tx_info->prev_seq = start_offload_tcp_sn;
 	tx_info->tcp_start_seq_number = start_offload_tcp_sn;
@@ -486,7 +486,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 	/* save crypto keys */
 	ret = chcr_ktls_save_keys(tx_info, crypto_info, direction);
 	if (ret < 0)
-		goto out2;
+		goto free_tx_info;
 
 	/* get peer ip */
 	if (sk->sk_family == AF_INET ||
@@ -502,14 +502,14 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 	if (!dst) {
 		pr_err("DST entry not found\n");
 		ret = -ENOENT;
-		goto out2;
+		goto free_tx_info;
 	}
 	n = dst_neigh_lookup(dst, daaddr);
 	if (!n || !n->dev) {
 		pr_err("neighbour not found\n");
 		dst_release(dst);
 		ret = -ENOENT;
-		goto out2;
+		goto free_tx_info;
 	}
 	tx_info->l2te  = cxgb4_l2t_get(adap->l2t, n, n->dev, 0);
 
@@ -519,7 +519,7 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 	if (!tx_info->l2te) {
 		pr_err("l2t entry not found\n");
 		ret = -ENOENT;
-		goto out2;
+		goto free_tx_info;
 	}
 
 	tx_ctx->chcr_info = tx_info;
@@ -529,12 +529,16 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
 	 */
 	ret = chcr_setup_connection(sk, tx_info);
 	if (ret)
-		goto out2;
+		goto free_l2te;
 
 	atomic64_inc(&adap->chcr_stats.ktls_tx_connection_open);
 	return 0;
-out2:
+
+free_l2te:
+	cxgb4_l2t_release(tx_info->l2te);
+free_tx_info:
 	kvfree(tx_info);
+	tx_ctx->chcr_info = NULL;
 out:
 	atomic64_inc(&adap->chcr_stats.ktls_tx_connection_fail);
 	return ret;
-- 
2.26.2


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  8:05 [PATCH -next] cxgb4/chcr: Fix error return code in chcr_ktls_dev_add() Wei Yongjun
2020-05-12  8:04 ` [PATCH] cxgb4/chcr: Fix a leak " Dan Carpenter

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git