aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTung Nguyen <tung.q.nguyen@dektech.com.au>2018-04-17 15:58:27 -0400
committerDavid S. Miller <davem@davemloft.net>2018-04-18 13:48:43 -0400
commit36a50a989ee8267588de520b8704b85f045a3220 (patch)
tree4814069cc75b778297fe5ff5f16e53f39c167e90
parentbe47e41d77fba5bc17e9fb5f1c99217bb6691989 (diff)
tipc: fix infinite loop when dumping link monitor summary
When configuring the number of used bearers to MAX_BEARER and issuing command "tipc link monitor summary", the command enters infinite loop in user space. This issue happens because function tipc_nl_node_dump_monitor() returns the wrong 'prev_bearer' value when all potential monitors have been scanned. The correct behavior is to always try to scan all monitors until either the netlink message is full, in which case we return the bearer identity of the affected monitor, or we continue through the whole bearer array until we can return MAX_BEARERS. This solution also caters for the case where there may be gaps in the bearer array. Signed-off-by: Tung Nguyen <tung.q.nguyen@dektech.com.au> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/tipc/monitor.c2
-rw-r--r--net/tipc/node.c11
2 files changed, 5 insertions, 8 deletions
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index 32dc33a94bc7..5453e564da82 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -777,7 +777,7 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
777 777
778 ret = tipc_bearer_get_name(net, bearer_name, bearer_id); 778 ret = tipc_bearer_get_name(net, bearer_name, bearer_id);
779 if (ret || !mon) 779 if (ret || !mon)
780 return -EINVAL; 780 return 0;
781 781
782 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 782 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
783 NLM_F_MULTI, TIPC_NL_MON_GET); 783 NLM_F_MULTI, TIPC_NL_MON_GET);
diff --git a/net/tipc/node.c b/net/tipc/node.c
index c77dd2f3c589..6f98b56dd48e 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -2232,8 +2232,8 @@ int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
2232 struct net *net = sock_net(skb->sk); 2232 struct net *net = sock_net(skb->sk);
2233 u32 prev_bearer = cb->args[0]; 2233 u32 prev_bearer = cb->args[0];
2234 struct tipc_nl_msg msg; 2234 struct tipc_nl_msg msg;
2235 int bearer_id;
2235 int err; 2236 int err;
2236 int i;
2237 2237
2238 if (prev_bearer == MAX_BEARERS) 2238 if (prev_bearer == MAX_BEARERS)
2239 return 0; 2239 return 0;
@@ -2243,16 +2243,13 @@ int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
2243 msg.seq = cb->nlh->nlmsg_seq; 2243 msg.seq = cb->nlh->nlmsg_seq;
2244 2244
2245 rtnl_lock(); 2245 rtnl_lock();
2246 for (i = prev_bearer; i < MAX_BEARERS; i++) { 2246 for (bearer_id = prev_bearer; bearer_id < MAX_BEARERS; bearer_id++) {
2247 prev_bearer = i;
2248 err = __tipc_nl_add_monitor(net, &msg, prev_bearer); 2247 err = __tipc_nl_add_monitor(net, &msg, prev_bearer);
2249 if (err) 2248 if (err)
2250 goto out; 2249 break;
2251 } 2250 }
2252
2253out:
2254 rtnl_unlock(); 2251 rtnl_unlock();
2255 cb->args[0] = prev_bearer; 2252 cb->args[0] = bearer_id;
2256 2253
2257 return skb->len; 2254 return skb->len;
2258} 2255}