Skip to content

Commit 5715a50

Browse files
committed
Merge branch 'nfc-skb-leaks'
Shang XiaoJing says: ==================== nfc: Fix potential memory leak of skb There are 6 kinds of send functions can be called by nci_send_frame(): virtual_nci_send(), fdp_nci_send(), nxp_nci_send(), s3fwrn5_nci_send(), nfcmrvl_nci_send(), st_nci_send(); 1. virtual_nci_send() will memleak the skb, and has been fixed before. 2. fdp_nci_send() won't free the skb no matter whether write() succeed. 3-4. nxp_nci_send() and s3fwrn5_nci_send() will only free the skb when write() failed, however write() will not free the skb by itself for when succeeds. 5. nfcmrvl_nci_send() will call nfcmrvl_XXX_nci_send(), where some of them will free the skb, but nfcmrvl_i2c_nci_send() only free the skb when i2c_master_send() return >=0, and memleak will happen when i2c_master_send() failed in nfcmrvl_i2c_nci_send(). 6. st_nci_send() will queue the skb into other list and finally be freed. Fix the potential memory leak of skb. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a2c65a9 + 93d904a commit 5715a50

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

drivers/nfc/fdp/fdp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,19 @@ static int fdp_nci_close(struct nci_dev *ndev)
249249
static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
250250
{
251251
struct fdp_nci_info *info = nci_get_drvdata(ndev);
252+
int ret;
252253

253254
if (atomic_dec_and_test(&info->data_pkt_counter))
254255
info->data_pkt_counter_cb(ndev);
255256

256-
return info->phy_ops->write(info->phy, skb);
257+
ret = info->phy_ops->write(info->phy, skb);
258+
if (ret < 0) {
259+
kfree_skb(skb);
260+
return ret;
261+
}
262+
263+
consume_skb(skb);
264+
return 0;
257265
}
258266

259267
static int fdp_nci_request_firmware(struct nci_dev *ndev)

drivers/nfc/nfcmrvl/i2c.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,15 @@ static int nfcmrvl_i2c_nci_send(struct nfcmrvl_private *priv,
132132
ret = -EREMOTEIO;
133133
} else
134134
ret = 0;
135+
}
136+
137+
if (ret) {
135138
kfree_skb(skb);
139+
return ret;
136140
}
137141

138-
return ret;
142+
consume_skb(skb);
143+
return 0;
139144
}
140145

141146
static void nfcmrvl_i2c_nci_update_config(struct nfcmrvl_private *priv,

drivers/nfc/nxp-nci/core.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
8080
return -EINVAL;
8181

8282
r = info->phy_ops->write(info->phy_id, skb);
83-
if (r < 0)
83+
if (r < 0) {
8484
kfree_skb(skb);
85+
return r;
86+
}
8587

86-
return r;
88+
consume_skb(skb);
89+
return 0;
8790
}
8891

8992
static int nxp_nci_rf_pll_unlocked_ntf(struct nci_dev *ndev,

drivers/nfc/s3fwrn5/core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ static int s3fwrn5_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
110110
}
111111

112112
ret = s3fwrn5_write(info, skb);
113-
if (ret < 0)
113+
if (ret < 0) {
114114
kfree_skb(skb);
115+
mutex_unlock(&info->mutex);
116+
return ret;
117+
}
115118

119+
consume_skb(skb);
116120
mutex_unlock(&info->mutex);
117-
return ret;
121+
return 0;
118122
}
119123

120124
static int s3fwrn5_nci_post_setup(struct nci_dev *ndev)

0 commit comments

Comments
 (0)