Skip to contentSkip to conversation

atm: fix atm_dev refcnt leaks in atmtcp_remove_persistent

PATCH Applied Xin Xiong 2 participants 2 messages Jul 29, 2020 – Jul 31, 2020

Subsystems (3)
lore
Share & tools
lore

Xin Xiong

author
#0 lore raw

PATCH 1/1 atm: fix atm_dev refcnt leaks in atmtcp_remove_persistent

atmtcp_remove_persistent() invokes atm_dev_lookup(), which returns a reference of atm_dev with increased refcount or NULL if fails.

The refcount leaks issues occur in two error handling paths. If dev_data->persist is zero or PRIV(dev)->vcc isn't NULL, the function returns 0 without decreasing the refcount kept by a local variable, resulting in refcount leaks.

Fix the issue by adding atm_dev_put() before returning 0 both when dev_data->persist is zero or PRIV(dev)->vcc isn't NULL.

---
 drivers/atm/atmtcp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/atm/atmtcp.c +8 -2
index d9fd70280482..7f814da3c2d0 100644
@@ -433,9 +433,15 @@ static int atmtcp_remove_persistent(int itf)
 		return -EMEDIUMTYPE;
 	}
 	dev_data = PRIV(dev);
-	if (!dev_data->persist) return 0;
+	if (!dev_data->persist) {
+		atm_dev_put(dev);
+		return 0;
+	}
 	dev_data->persist = 0;
-	if (PRIV(dev)->vcc) return 0;
+	if (PRIV(dev)->vcc) {
+		atm_dev_put(dev);
+		return 0;
+	}
 	kfree(dev_data);
 	atm_dev_put(dev);
 	atm_dev_deregister(dev);
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw

From: Xin Xiong <[email protected]>
Date: Wed, 29 Jul 2020 21:06:59 +0800

Quoted 8 lines

atmtcp_remove_persistent() invokes atm_dev_lookup(), which returns a reference of atm_dev with increased refcount or NULL if fails.

The refcount leaks issues occur in two error handling paths. If dev_data->persist is zero or PRIV(dev)->vcc isn't NULL, the function returns 0 without decreasing the refcount kept by a local variable, resulting in refcount leaks.

Quoted 6 lines

Fix the issue by adding atm_dev_put() before returning 0 both when dev_data->persist is zero or PRIV(dev)->vcc isn't NULL.

Applied, thank you.