Skip to contentSkip to conversation

netlink: Properly unbind in error conditions.

PATCH In review Hiroaki SHIMODA 3 participants 3 messages Nov 12, 2014

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

PATCH 1/1 netlink: Properly unbind in error conditions.

Even if netlink_kernel_cfg::unbind is implemented the unbind() method is not called, because cfg->unbind is omitted in __netlink_kernel_create(). And fix wrong argument of test_bit() and off by one problem.

At this point, no unbind() method is implemented, so there is no real issue.

Fixes 4f520900522f ("netlink: have netlink per-protocol bind function return an error code.")
Cc Richard Guy Briggs <[email protected]>
---
 net/netlink/af_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netlink/af_netlink.c +3 -2
index f1de72de273e..0007b8180397 100644
@@ -1440,7 +1440,7 @@ static void netlink_unbind(int group, long unsigned int groups,
 		return;
 
 	for (undo = 0; undo < group; undo++)
-		if (test_bit(group, &groups))
+		if (test_bit(undo, &groups))
 			nlk->netlink_unbind(undo);
 }
 
@@ -1492,7 +1492,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
 			netlink_insert(sk, net, nladdr->nl_pid) :
 			netlink_autobind(sock);
 		if (err) {
-			netlink_unbind(nlk->ngroups - 1, groups, nlk);
+			netlink_unbind(nlk->ngroups, groups, nlk);
 			return err;
 		}
 	}
@@ -2509,6 +2509,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
 		nl_table[unit].module = module;
 		if (cfg) {
 			nl_table[unit].bind = cfg->bind;
+			nl_table[unit].unbind = cfg->unbind;
 			nl_table[unit].flags = cfg->flags;
 			if (cfg->compare)
 				nl_table[unit].compare = cfg->compare;
Signature · 1 line
2.0.4
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Hiroaki SHIMODA

Even if netlink_kernel_cfg::unbind is implemented the unbind() method is not called, because cfg->unbind is omitted in __netlink_kernel_create(). And fix wrong argument of test_bit() and off by one problem.

At this point, no unbind() method is implemented, so there is no real issue.

Fixes 4f520900522f ("netlink: have netlink per-protocol bind function return an error code.")
Cc Richard Guy Briggs <[email protected]>
---
 net/netlink/af_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netlink/af_netlink.c +0 -0
index f1de72de273e..0007b8180397 100644

net/netlink/af_netlink.c static void netlink_unbind(int group, long unsigned int groups, · line 1443

Quoted 5 lines
net/netlink/af_netlink.c +1 -1
@@ -1440,7 +1440,7 @@ static void netlink_unbind(int group, long unsigned int groups,
 		return;
 
 	for (undo = 0; undo < group; undo++)
-		if (test_bit(group, &groups))
+		if (test_bit(undo, &groups))

Nice find! (Cut-and-waste from line 1480...)

net/netlink/af_netlink.c static int netlink_bind(struct socket *sock, struct sockaddr *addr, · line 1495

Quoted 9 lines
net/netlink/af_netlink.c +1 -1
 			nlk->netlink_unbind(undo);
 }
 
@@ -1492,7 +1492,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
 			netlink_insert(sk, net, nladdr->nl_pid) :
 			netlink_autobind(sock);
 		if (err) {
-			netlink_unbind(nlk->ngroups - 1, groups, nlk);
+			netlink_unbind(nlk->ngroups, groups, nlk);

Yup, agreed.

net/netlink/af_netlink.c __netlink_kernel_create(struct net *net, int unit, struct module *module, · line 2512

Quoted 8 lines
net/netlink/af_netlink.c +1 -0
 			return err;
 		}
 	}
@@ -2509,6 +2509,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
 		nl_table[unit].module = module;
 		if (cfg) {
 			nl_table[unit].bind = cfg->bind;
+			nl_table[unit].unbind = cfg->unbind;

Yup, thanks.

net/netlink/af_netlink.c __netlink_kernel_create(struct net *net, int unit, struct module *module, · line 2515

Quoted 3 lines
net/netlink/af_netlink.c +0 -0
 			nl_table[unit].flags = cfg->flags;
 			if (cfg->compare)
 				nl_table[unit].compare = cfg->compare;
Quoted 3 lines
Signature · 1 line
2.0.4

- RGB

--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545

maintainer
#2 lore raw
In reply to Hiroaki SHIMODA

From: Hiroaki SHIMODA <[email protected]>
Date: Thu, 13 Nov 2014 04:24:10 +0900

Quoted 9 lines

Even if netlink_kernel_cfg::unbind is implemented the unbind() method is not called, because cfg->unbind is omitted in __netlink_kernel_create(). And fix wrong argument of test_bit() and off by one problem.

At this point, no unbind() method is implemented, so there is no real issue.

Fixes 4f520900522f ("netlink: have netlink per-protocol bind function return an error code.")

Applied and queued up for -stable, thanks.