aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorIgnacy Gawędzki <ignacy.gawedzki@green-communications.fr>2015-02-13 14:47:05 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-03-18 13:22:26 +0100
commit54c7f8978bfe00fdc80e44a0451a1f8f8b8de638 (patch)
treebf80cdbf31c18e47912b9623e92a20f1220d7ba4 /net
parent140b057ced8f43b93c4d934eb94661782155f683 (diff)
downloadlinux-linaro-stable-54c7f8978bfe00fdc80e44a0451a1f8f8b8de638.tar.gz
gen_stats.c: Duplicate xstats buffer for later use
[ Upstream commit 1c4cff0cf55011792125b6041bc4e9713e46240f ] 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: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net')
-rw-r--r--net/core/gen_stats.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
index ddedf211e588..b96437b6e82b 100644
--- a/net/core/gen_stats.c
+++ b/net/core/gen_stats.c
@@ -32,6 +32,9 @@ gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size)
return 0;
nla_put_failure:
+ kfree(d->xstats);
+ d->xstats = NULL;
+ d->xstats_len = 0;
spin_unlock_bh(d->lock);
return -1;
}
@@ -205,7 +208,9 @@ int
gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
{
if (d->compat_xstats) {
- d->xstats = st;
+ d->xstats = kmemdup(st, len, GFP_ATOMIC);
+ if (!d->xstats)
+ goto err_out;
d->xstats_len = len;
}
@@ -213,6 +218,11 @@ gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
return gnet_stats_copy(d, TCA_STATS_APP, st, len);
return 0;
+
+err_out:
+ d->xstats_len = 0;
+ spin_unlock_bh(d->lock);
+ return -1;
}
EXPORT_SYMBOL(gnet_stats_copy_app);
@@ -245,6 +255,9 @@ gnet_stats_finish_copy(struct gnet_dump *d)
return -1;
}
+ kfree(d->xstats);
+ d->xstats = NULL;
+ d->xstats_len = 0;
spin_unlock_bh(d->lock);
return 0;
}