Skip to contentSkip to conversation

nfc: Fix potential memory leak of skb

PATCH Applied Shang XiaoJing 3 participants 6 messages Nov 17, 2022 – Nov 23, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover nfc: Fix potential memory leak of skb

There are still somewhere maybe leak the skb, fix the memleaks by adding fail path.

Shang XiaoJing (3):
nfc: nfcmrvl: Fix potential memory leak in nfcmrvl_i2c_nci_send()
nfc: nxp-nci: Fix potential memory leak in nxp_nci_send()
nfc: s3fwrn5: Fix potential memory leak in s3fwrn5_nci_send()

 drivers/nfc/nfcmrvl/i2c.c  | 4 +++-
 drivers/nfc/nxp-nci/core.c | 8 ++++++--
 drivers/nfc/s3fwrn5/core.c | 1 +
 3 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 nfc: nfcmrvl: Fix potential memory leak in nfcmrvl_i2c_nci_send()

nfcmrvl_i2c_nci_send() will be called by nfcmrvl_nci_send(), and skb should be freed in nfcmrvl_i2c_nci_send(). However, nfcmrvl_nci_send() won't free the skb when it failed for the test_bit(). Free the skb when test_bit() failed.

Fixes b5b3e23e4cac ("NFC: nfcmrvl: add i2c driver")
---
 drivers/nfc/nfcmrvl/i2c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nfc/nfcmrvl/i2c.c +3 -1
index 24436c9e54c9..97600826af69 100644
@@ -112,8 +112,10 @@ static int nfcmrvl_i2c_nci_send(struct nfcmrvl_private *priv,
 	struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data;
 	int ret;
 
-	if (test_bit(NFCMRVL_PHY_ERROR, &priv->flags))
+	if (test_bit(NFCMRVL_PHY_ERROR, &priv->flags)) {
+		kfree_skb(skb);
 		return -EREMOTEIO;
+	}
 
 	ret = i2c_master_send(drv_data->i2c, skb->data, skb->len);
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/3 nfc: nxp-nci: Fix potential memory leak in nxp_nci_send()

In reply to Shang XiaoJing

nxp_nci_send() won't free the skb when it failed for the check before write(). As the result, the skb will memleak. Free the skb when the check failed.

Fixes dece45855a8b ("NFC: nxp-nci: Add support for NXP NCI chips")
---
 drivers/nfc/nxp-nci/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nfc/nxp-nci/core.c +6 -2
index 580cb6ecffee..66b198663387 100644
@@ -73,11 +73,15 @@ static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
 	struct nxp_nci_info *info = nci_get_drvdata(ndev);
 	int r;
 
-	if (!info->phy_ops->write)
+	if (!info->phy_ops->write) {
+		kfree_skb(skb);
 		return -EOPNOTSUPP;
+	}
 
-	if (info->mode != NXP_NCI_MODE_NCI)
+	if (info->mode != NXP_NCI_MODE_NCI) {
+		kfree_skb(skb);
 		return -EINVAL;
+	}
 
 	r = info->phy_ops->write(info->phy_id, skb);
 	if (r < 0) {
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/3 nfc: s3fwrn5: Fix potential memory leak in s3fwrn5_nci_send()

In reply to Shang XiaoJing

s3fwrn5_nci_send() won't free the skb when it failed for the check before s3fwrn5_write(). As the result, the skb will memleak. Free the skb when the check failed.

Fixes c04c674fadeb ("nfc: s3fwrn5: Add driver for Samsung S3FWRN5 NFC Chip")
---
 drivers/nfc/s3fwrn5/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nfc/s3fwrn5/core.c +1 -0
index 0270e05b68df..aec356880adf 100644
@@ -105,6 +105,7 @@ static int s3fwrn5_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
 	mutex_lock(&info->mutex);
 
 	if (s3fwrn5_get_mode(info) != S3FWRN5_MODE_NCI) {
+		kfree_skb(skb);
 		mutex_unlock(&info->mutex);
 		return -EINVAL;
 	}
Signature · 1 line
2.17.1
#4 lore raw
In reply to Shang XiaoJing
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Thu, 17 Nov 2022 19:37:11 +0800 you wrote:

There are still somewhere maybe leak the skb, fix the memleaks by adding fail path.

Shang XiaoJing (3):
nfc: nfcmrvl: Fix potential memory leak in nfcmrvl_i2c_nci_send()
nfc: nxp-nci: Fix potential memory leak in nxp_nci_send()
nfc: s3fwrn5: Fix potential memory leak in s3fwrn5_nci_send()

[...]

Here is the summary with links:
- [1/3] nfc: nfcmrvl: Fix potential memory leak in nfcmrvl_i2c_nci_send()

    https://git.kernel.org/netdev/net/c/e204ead35401
  - [2/3] nfc: nxp-nci: Fix potential memory leak in nxp_nci_send()
    https://git.kernel.org/netdev/net/c/614761e1119c
  - [3/3] nfc: s3fwrn5: Fix potential memory leak in s3fwrn5_nci_send()
    https://git.kernel.org/netdev/net/c/60dcb5ff55e5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Reviewed-by on the v1 series
#5 lore raw
In reply to Shang XiaoJing

Hi!

Quoted 2 lines

There are still somewhere maybe leak the skb, fix the memleaks by adding fail path.

Thank you!

Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany