* [Patch] gen_stats.c: Duplicate xstats buffer for later use
@ 2015-02-13 22:47 Cong Wang
2015-02-19 20:47 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2015-02-13 22:47 UTC (permalink / raw)
To: netdev; +Cc: davem, ignacy.gawedzki, David.Laight, Cong Wang
From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
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>
---
net/core/gen_stats.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
index 0c08062..1e2f46a 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;
}
@@ -305,7 +308,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;
}
@@ -313,6 +318,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);
@@ -345,6 +355,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;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [Patch] gen_stats.c: Duplicate xstats buffer for later use
2015-02-13 22:47 [Patch] gen_stats.c: Duplicate xstats buffer for later use Cong Wang
@ 2015-02-19 20:47 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2015-02-19 20:47 UTC (permalink / raw)
To: xiyou.wangcong; +Cc: netdev, ignacy.gawedzki, David.Laight
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Fri, 13 Feb 2015 14:47:05 -0800
> From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
>
> 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>
Ugh, that's an ugly bug.
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-19 20:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-13 22:47 [Patch] gen_stats.c: Duplicate xstats buffer for later use Cong Wang
2015-02-19 20:47 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox