Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: free the ECDH tfm when a sample fails
@ 2026-11-04  2:53 Wentao Liang
  2026-11-04  7:11 ` Krzysztof Kozlowski
  2026-11-04  8:43 ` bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-04  2:53 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz; +Cc: linux-bluetooth

test_ecdh() allocates a KPP transform, then runs three samples. If a
sample fails, the function jumps to the done label, which only fills the
debugfs buffer. The transform is freed only on the success path, so any
sample failure leaks it.

Add a label that frees the transform and use it from the three sample
failure paths.

Fixes: 47eb2ac80918 ("Bluetooth: move ecdh allocation outside of ecdh_helper")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 net/bluetooth/selftest.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c
index cdfc40e0016b..b91f7559d8fd 100644
--- a/net/bluetooth/selftest.c
+++ b/net/bluetooth/selftest.c
@@ -214,31 +214,32 @@ static int __init test_ecdh(void)
 			       dhkey_1);
 	if (err) {
 		BT_ERR("ECDH sample 1 failed");
-		goto done;
+		goto free_tfm;
 	}
 
 	err = test_ecdh_sample(tfm, priv_a_2, priv_b_2, pub_a_2, pub_b_2,
 			       dhkey_2);
 	if (err) {
 		BT_ERR("ECDH sample 2 failed");
-		goto done;
+		goto free_tfm;
 	}
 
 	err = test_ecdh_sample(tfm, priv_a_3, priv_a_3, pub_a_3, pub_a_3,
 			       dhkey_3);
 	if (err) {
 		BT_ERR("ECDH sample 3 failed");
-		goto done;
+		goto free_tfm;
 	}
 
-	crypto_free_kpp(tfm);
-
 	rettime = ktime_get();
 	delta = ktime_sub(rettime, calltime);
 	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
 
 	BT_INFO("ECDH test passed in %llu usecs", duration);
 
+free_tfm:
+	crypto_free_kpp(tfm);
+
 done:
 	if (!err)
 		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer),
-- 
2.34.1


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

end of thread, other threads:[~2026-11-04  8:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:53 [PATCH] Bluetooth: free the ECDH tfm when a sample fails Wentao Liang
2026-11-04  7:11 ` Krzysztof Kozlowski
2026-11-04  8:43 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox