Blob Blame History Raw
From 7574fcdbdcb335763b6b322f6928dc0fd5730451 Mon Sep 17 00:00:00 2001
From: Xiaoming Ni <nixiaoming@huawei.com>
Date: Thu, 25 Mar 2021 11:51:12 +0800
Subject: [PATCH] nfc: fix memory leak in llcp_sock_connect()
Mime-version: 1.0
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 8bit
Git-commit: 7574fcdbdcb335763b6b322f6928dc0fd5730451
Patch-mainline: v5.12-rc7
References: CVE-2020-25672 bsc#1178181

[ backport note: adjusted to the old error path -- tiwai ]

In llcp_sock_connect(), use kmemdup to allocate memory for
 "llcp_sock->service_name". The memory is not released in the sock_unlink
label of the subsequent failure branch.
As a result, memory leakage occurs.

fix CVE-2020-25672

Fixes: d646960f7986 ("NFC: Initial LLCP support")
Reported-by: "kiyin(尹亮)" <kiyin@tencent.com>
Link: https://www.openwall.com/lists/oss-security/2020/11/01/1
Cc: <stable@vger.kernel.org> #v3.3
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 net/nfc/llcp_sock.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -757,6 +757,9 @@ sock_unlink:
 	nfc_llcp_put_ssap(local, llcp_sock->ssap);
 
 	nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
+	kfree(llcp_sock->service_name);
+	llcp_sock->service_name = NULL;
+
 	nfc_llcp_local_put(llcp_sock->local);
 
 put_dev: