tipc: fix infinite loop when dumping link monitor summary
authorTung Nguyen <tung.q.nguyen@dektech.com.au>
Tue, 17 Apr 2018 19:58:27 +0000 (21:58 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Apr 2018 17:48:43 +0000 (13:48 -0400)
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>
net/tipc/monitor.c
net/tipc/node.c

index 32dc33a94bc714f762a066389a4907e558244cd7..5453e564da8276fc2e1b7510c2dee8589f1b1f89 100644 (file)
@@ -777,7 +777,7 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
 
        ret = tipc_bearer_get_name(net, bearer_name, bearer_id);
        if (ret || !mon)
-               return -EINVAL;
+               return 0;
 
        hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
                          NLM_F_MULTI, TIPC_NL_MON_GET);
index c77dd2f3c5898e5c9d05f3a9e5fa72e2dc729bd0..6f98b56dd48ece2cbedb19d6e44fd9c55488e7a9 100644 (file)
@@ -2232,8 +2232,8 @@ int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
        struct net *net = sock_net(skb->sk);
        u32 prev_bearer = cb->args[0];
        struct tipc_nl_msg msg;
+       int bearer_id;
        int err;
-       int i;
 
        if (prev_bearer == MAX_BEARERS)
                return 0;
@@ -2243,16 +2243,13 @@ int tipc_nl_node_dump_monitor(struct sk_buff *skb, struct netlink_callback *cb)
        msg.seq = cb->nlh->nlmsg_seq;
 
        rtnl_lock();
-       for (i = prev_bearer; i < MAX_BEARERS; i++) {
-               prev_bearer = i;
+       for (bearer_id = prev_bearer; bearer_id < MAX_BEARERS; bearer_id++) {
                err = __tipc_nl_add_monitor(net, &msg, prev_bearer);
                if (err)
-                       goto out;
+                       break;
        }
-
-out:
        rtnl_unlock();
-       cb->args[0] = prev_bearer;
+       cb->args[0] = bearer_id;
 
        return skb->len;
 }