Skip to contentSkip to conversation

gtp: add missing gtp_encap_disable_sock() in gtp_encap_enable()

PATCH In review Taehee Yoo 1 participant 1 message Jul 2, 2019

Subsystems (3)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH 6/6 gtp: add missing gtp_encap_disable_sock() in gtp_encap_enable()

If an invalid role is sent from user space, gtp_encap_enable() will fail. Then, it should call gtp_encap_disable_sock() but current code doesn't. It makes memory leak.

Fixes 91ed81f9abc7 ("gtp: support SGSN-side tunnels")
---
 drivers/net/gtp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/gtp.c +6 -1
index b3ccac54e204..ecfe26215935 100644
@@ -857,8 +857,13 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
 
 	if (data[IFLA_GTP_ROLE]) {
 		role = nla_get_u32(data[IFLA_GTP_ROLE]);
-		if (role > GTP_ROLE_SGSN)
+		if (role > GTP_ROLE_SGSN) {
+			if (sk0)
+				gtp_encap_disable_sock(sk0);
+			if (sk1u)
+				gtp_encap_disable_sock(sk1u);
 			return -EINVAL;
+		}
 	}
 
 	gtp->sk0 = sk0;
Signature · 1 line
2.17.1