Commit e2bc1237 authored by Ignacy Gawędzki's avatar Ignacy Gawędzki Committed by Luis Henriques

gen_stats.c: Duplicate xstats buffer for later use

commit 1c4cff0c upstream.

The gnet_stats_copy_app() function gets called, more often than not, with its
second argument a pointer to an automatic variable in the caller's stack.
Therefore, to avoid copying garbage afterwards when calling
gnet_stats_finish_copy(), this data is better copied to a dynamically allocated
memory that gets freed after use.

[xiyou.wangcong@gmail.com: remove a useless kfree()]
Signed-off-by: default avatarIgnacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 4681bfc9
...@@ -32,6 +32,9 @@ gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size) ...@@ -32,6 +32,9 @@ gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size)
return 0; return 0;
nla_put_failure: nla_put_failure:
kfree(d->xstats);
d->xstats = NULL;
d->xstats_len = 0;
spin_unlock_bh(d->lock); spin_unlock_bh(d->lock);
return -1; return -1;
} }
...@@ -217,7 +220,9 @@ int ...@@ -217,7 +220,9 @@ int
gnet_stats_copy_app(struct gnet_dump *d, void *st, int len) gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
{ {
if (d->compat_xstats) { if (d->compat_xstats) {
d->xstats = st; d->xstats = kmemdup(st, len, GFP_ATOMIC);
if (!d->xstats)
goto err_out;
d->xstats_len = len; d->xstats_len = len;
} }
...@@ -225,6 +230,11 @@ gnet_stats_copy_app(struct gnet_dump *d, void *st, int len) ...@@ -225,6 +230,11 @@ gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
return gnet_stats_copy(d, TCA_STATS_APP, st, len); return gnet_stats_copy(d, TCA_STATS_APP, st, len);
return 0; return 0;
err_out:
d->xstats_len = 0;
spin_unlock_bh(d->lock);
return -1;
} }
EXPORT_SYMBOL(gnet_stats_copy_app); EXPORT_SYMBOL(gnet_stats_copy_app);
...@@ -257,6 +267,9 @@ gnet_stats_finish_copy(struct gnet_dump *d) ...@@ -257,6 +267,9 @@ gnet_stats_finish_copy(struct gnet_dump *d)
return -1; return -1;
} }
kfree(d->xstats);
d->xstats = NULL;
d->xstats_len = 0;
spin_unlock_bh(d->lock); spin_unlock_bh(d->lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment