linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] fix two possible memory leak problems in NFC digital module
@ 2021-10-13  7:49 Ziyang Xuan
  2021-10-13  7:50 ` [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Ziyang Xuan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ziyang Xuan @ 2021-10-13  7:49 UTC (permalink / raw)
  To: krzysztof.kozlowski; +Cc: davem, kuba, netdev, linux-kernel

Fix two possible memory leak problems in NFC digital module.

Ziyang Xuan (2):
  NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
  NFC: digital: fix possible memory leak in digital_in_send_sdd_req()

 net/nfc/digital_core.c       | 9 +++++++--
 net/nfc/digital_technology.c | 8 ++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.25.1


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

* [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
  2021-10-13  7:49 [PATCH net 0/2] fix two possible memory leak problems in NFC digital module Ziyang Xuan
@ 2021-10-13  7:50 ` Ziyang Xuan
  2021-10-13  9:35   ` Krzysztof Kozlowski
  2021-10-13  7:50 ` [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req() Ziyang Xuan
  2021-10-14  0:50 ` [PATCH net 0/2] fix two possible memory leak problems in NFC digital module patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Ziyang Xuan @ 2021-10-13  7:50 UTC (permalink / raw)
  To: krzysztof.kozlowski; +Cc: davem, kuba, netdev, linux-kernel

'params' is allocated in digital_tg_listen_mdaa(), but not free when
digital_send_cmd() failed, which will cause memory leak. Fix it by
freeing 'params' if digital_send_cmd() return failed.

Fixes: 1c7a4c24fbfd ("NFC Digital: Add target NFC-DEP support")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 net/nfc/digital_core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index fefc03674f4f..d63d2e5dc60c 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -277,6 +277,7 @@ int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
 static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
 {
 	struct digital_tg_mdaa_params *params;
+	int rc;
 
 	params = kzalloc(sizeof(*params), GFP_KERNEL);
 	if (!params)
@@ -291,8 +292,12 @@ static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
 	get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2);
 	params->sc = DIGITAL_SENSF_FELICA_SC;
 
-	return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
-				500, digital_tg_recv_atr_req, NULL);
+	rc = digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
+			      500, digital_tg_recv_atr_req, NULL);
+	if (rc)
+		kfree(params);
+
+	return rc;
 }
 
 static int digital_tg_listen_md(struct nfc_digital_dev *ddev, u8 rf_tech)
-- 
2.25.1


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

* [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req()
  2021-10-13  7:49 [PATCH net 0/2] fix two possible memory leak problems in NFC digital module Ziyang Xuan
  2021-10-13  7:50 ` [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Ziyang Xuan
@ 2021-10-13  7:50 ` Ziyang Xuan
  2021-10-13  9:36   ` Krzysztof Kozlowski
  2021-10-14  0:50 ` [PATCH net 0/2] fix two possible memory leak problems in NFC digital module patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Ziyang Xuan @ 2021-10-13  7:50 UTC (permalink / raw)
  To: krzysztof.kozlowski; +Cc: davem, kuba, netdev, linux-kernel

'skb' is allocated in digital_in_send_sdd_req(), but not free when
digital_in_send_cmd() failed, which will cause memory leak. Fix it
by freeing 'skb' if digital_in_send_cmd() return failed.

Fixes: 2c66daecc409 ("NFC Digital: Add NFC-A technology support")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 net/nfc/digital_technology.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
index 84d2345c75a3..3adf4589852a 100644
--- a/net/nfc/digital_technology.c
+++ b/net/nfc/digital_technology.c
@@ -465,8 +465,12 @@ static int digital_in_send_sdd_req(struct nfc_digital_dev *ddev,
 	skb_put_u8(skb, sel_cmd);
 	skb_put_u8(skb, DIGITAL_SDD_REQ_SEL_PAR);
 
-	return digital_in_send_cmd(ddev, skb, 30, digital_in_recv_sdd_res,
-				   target);
+	rc = digital_in_send_cmd(ddev, skb, 30, digital_in_recv_sdd_res,
+				 target);
+	if (rc)
+		kfree_skb(skb);
+
+	return rc;
 }
 
 static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg,
-- 
2.25.1


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

* Re: [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
  2021-10-13  7:50 ` [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Ziyang Xuan
@ 2021-10-13  9:35   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-10-13  9:35 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: davem, kuba, netdev, linux-kernel

On 13/10/2021 09:50, Ziyang Xuan wrote:
> 'params' is allocated in digital_tg_listen_mdaa(), but not free when
> digital_send_cmd() failed, which will cause memory leak. Fix it by
> freeing 'params' if digital_send_cmd() return failed.
> 
> Fixes: 1c7a4c24fbfd ("NFC Digital: Add target NFC-DEP support")
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
> ---
>  net/nfc/digital_core.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 

Good catch. Leak is only theoretical as digital_send_cmd() will fail
only on memory allocation failure but your fix makes code correct.


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

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

* Re: [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req()
  2021-10-13  7:50 ` [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req() Ziyang Xuan
@ 2021-10-13  9:36   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-10-13  9:36 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: davem, kuba, netdev, linux-kernel

On 13/10/2021 09:50, Ziyang Xuan wrote:
> 'skb' is allocated in digital_in_send_sdd_req(), but not free when
> digital_in_send_cmd() failed, which will cause memory leak. Fix it
> by freeing 'skb' if digital_in_send_cmd() return failed.
> 
> Fixes: 2c66daecc409 ("NFC Digital: Add NFC-A technology support")
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
> ---
>  net/nfc/digital_technology.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

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

* Re: [PATCH net 0/2] fix two possible memory leak problems in NFC digital module
  2021-10-13  7:49 [PATCH net 0/2] fix two possible memory leak problems in NFC digital module Ziyang Xuan
  2021-10-13  7:50 ` [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Ziyang Xuan
  2021-10-13  7:50 ` [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req() Ziyang Xuan
@ 2021-10-14  0:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-14  0:50 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: krzysztof.kozlowski, davem, kuba, netdev, linux-kernel

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 13 Oct 2021 15:49:53 +0800 you wrote:
> Fix two possible memory leak problems in NFC digital module.
> 
> Ziyang Xuan (2):
>   NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
>   NFC: digital: fix possible memory leak in digital_in_send_sdd_req()
> 
>  net/nfc/digital_core.c       | 9 +++++++--
>  net/nfc/digital_technology.c | 8 ++++++--
>  2 files changed, 13 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [net,1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
    https://git.kernel.org/netdev/net/c/58e7dcc9ca29
  - [net,2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req()
    https://git.kernel.org/netdev/net/c/291c932fc369

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-10-14  0:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  7:49 [PATCH net 0/2] fix two possible memory leak problems in NFC digital module Ziyang Xuan
2021-10-13  7:50 ` [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Ziyang Xuan
2021-10-13  9:35   ` Krzysztof Kozlowski
2021-10-13  7:50 ` [PATCH net 2/2] NFC: digital: fix possible memory leak in digital_in_send_sdd_req() Ziyang Xuan
2021-10-13  9:36   ` Krzysztof Kozlowski
2021-10-14  0:50 ` [PATCH net 0/2] fix two possible memory leak problems in NFC digital module patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).