Skip to content

Commit 8de7fb3

Browse files
congwanggregkh
authored andcommitted
tipc: fix a memory leak in tipc_nl_node_get_link()
[ Upstream commit 59b3661 ] When tipc_node_find_by_name() fails, the nlmsg is not freed. While on it, switch to a goto label to properly free it. Fixes: be9c086715c ("tipc: narrow down exposure of struct tipc_node") Reported-by: Dmitry Vyukov <dvyukov@google.com> Cc: Jon Maloy <jon.maloy@ericsson.com> Cc: Ying Xue <ying.xue@windriver.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a940c19 commit 8de7fb3

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎net/tipc/node.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,36 +1848,38 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
18481848

18491849
if (strcmp(name, tipc_bclink_name) == 0) {
18501850
err = tipc_nl_add_bc_link(net, &msg);
1851-
if (err) {
1852-
nlmsg_free(msg.skb);
1853-
return err;
1854-
}
1851+
if (err)
1852+
goto err_free;
18551853
} else {
18561854
int bearer_id;
18571855
struct tipc_node *node;
18581856
struct tipc_link *link;
18591857

18601858
node = tipc_node_find_by_name(net, name, &bearer_id);
1861-
if (!node)
1862-
return -EINVAL;
1859+
if (!node) {
1860+
err = -EINVAL;
1861+
goto err_free;
1862+
}
18631863

18641864
tipc_node_read_lock(node);
18651865
link = node->links[bearer_id].link;
18661866
if (!link) {
18671867
tipc_node_read_unlock(node);
1868-
nlmsg_free(msg.skb);
1869-
return -EINVAL;
1868+
err = -EINVAL;
1869+
goto err_free;
18701870
}
18711871

18721872
err = __tipc_nl_add_link(net, &msg, link, 0);
18731873
tipc_node_read_unlock(node);
1874-
if (err) {
1875-
nlmsg_free(msg.skb);
1876-
return err;
1877-
}
1874+
if (err)
1875+
goto err_free;
18781876
}
18791877

18801878
return genlmsg_reply(msg.skb, info);
1879+
1880+
err_free:
1881+
nlmsg_free(msg.skb);
1882+
return err;
18811883
}
18821884

18831885
int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)

0 commit comments

Comments
 (0)