[lkml]   [2018]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [PATCH] netlink: fix memory leak of dump
<div dir="ltr">allocate memory in cb-&gt;start(), which means passing &#39;static&#39; variable through control-&gt;data, <div>then allocate memory in cb-&gt;start() according to cb-&gt;data (cb-&gt;data is equal to control-&gt;data now),</div><div>and set the memory back to cb-&gt;data which will be used in cb-&gt;dump(). </div><div>It&#39;s a bit complicated, please see nf_tables_getset.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-07-23 2:09 GMT+08:00 Florian Westphal <span dir="ltr">&lt;<a href="" target="_blank"></a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">David Miller &lt;<a href=""></a>&gt; wrote:<br>
&gt; From: Florian Westphal &lt;<a href=""></a>&gt;<br>
&gt; Date: Sun, 22 Jul 2018 18:39:25 +0200<br>
&gt; <br>
&gt; &gt; 3. change meaning of -&gt;done() so its always called once -&gt;start()<br>
&gt; &gt;    was invoked (and returned 0), this requires audit of all<br>
&gt; &gt;    places that provide .done to make sure they won&#39;t trip.<br>
&gt; &gt; <br>
&gt; &gt; 3) seems to be what Tom intended when he added .start, so probably<br>
&gt; &gt; best to investigate that first.<br>
&gt; <br>
&gt; Hmmm...<br>
&gt; <br>
&gt; Any time -&gt;start() succeeds, we set cb_running to true.<br>
<span class=""><br>
&gt; From that point forward, -&gt;done() will be called at some point at all<br>
&gt; of the locations that check if cb_running is true and set it to false.<br>
</span>Also right, thanks for pointing this out, I missed fact that netlink<br>
core restarts a dump after this.<br>
So 3) is already true which means we should try to see if we can move<br>
all dump-related extra magic into -&gt;start().<br>
Shaochun, can you see if this is possible?<br>
Something along these lines (totally untested), which makes this<br>
a netfilter fix:<br>
diff --git a/net/netfilter/nf_tables_api.<wbr>c b/net/netfilter/nf_tables_api.<wbr>c<br>
--- a/net/netfilter/nf_tables_api.<wbr>c<br>
+++ b/net/netfilter/nf_tables_api.<wbr>c<br>
@@ -5010,6 +5013,22 @@ nft_obj_filter_alloc(const struct nlattr * const nla[])<br>
        return filter;<br>
+static int nf_tables_dump_obj_start(<wbr>struct netlink_callback *cb)<br>
+       const struct nlattr * const *nla = cb-&gt;data;<br>
<span class="">+       struct nft_obj_filter *filter = NULL;<br>
+       if (nla[NFTA_OBJ_TABLE] ||<br>
+           nla[NFTA_OBJ_TYPE]) {<br>
+               filter = nft_obj_filter_alloc(nla);<br>
+               if (IS_ERR(filter))<br>
+                       return -ENOMEM;<br>
+       }<br>
+       cb-&gt;data = filter;<br>
+       return 0;<br>
 /* called with rcu_read_lock held */<br>
<span class=""> static int nf_tables_getobj(struct net *net, struct sock *nlsk,<br>
</span>                            struct sk_buff *skb, const struct nlmsghdr *nlh,<br>
@@ -5028,21 +5047,13 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,<br>
        if (nlh-&gt;nlmsg_flags &amp; NLM_F_DUMP) {<br>
                struct netlink_dump_control c = {<br>
+                       .start = nf_tables_dump_obj_start,<br>
                        .dump = nf_tables_dump_obj,<br>
<span class="">                        .done = nf_tables_dump_obj_done,<br>
                        .module = THIS_MODULE,<br>
</span>+                       .data = (void *)nla,<br>
-               if (nla[NFTA_OBJ_TABLE] ||<br>
-                   nla[NFTA_OBJ_TYPE]) {<br>
<span class="">-                       struct nft_obj_filter *filter;<br>
</span>-                       filter = nft_obj_filter_alloc(nla);<br>
-                       if (IS_ERR(filter))<br>
-                               return -ENOMEM;<br>
-              = filter;<br>
<div class="HOEnZb"><div class="h5">-               }<br>
                return nft_netlink_dump_start_rcu(<wbr>nlsk, skb, nlh, &amp;c);<br>
 \ /
  Last update: 2018-07-23 04:06    [W:0.114 / U:26.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site