Skip to content

Commit

Permalink
gen_stats.c: Duplicate xstats buffer for later use
Browse files Browse the repository at this point in the history
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.

[[email protected]: remove a useless kfree()]

Signed-off-by: Ignacy Gawędzki <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
iazz authored and davem330 committed Feb 19, 2015
1 parent 5c27700 commit 1c4cff0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion net/core/gen_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -305,14 +308,21 @@ 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;
}

if (d->tail)
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);

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1c4cff0

Please sign in to comment.