Skip to content

Commit

Permalink
9p: clear dangling pointers in p9stat_free
Browse files Browse the repository at this point in the history
p9stat_free is more of a cleanup function than a 'free' function as it
only frees the content of the struct; there are chances of use-after-free
if it is improperly used (e.g. p9stat_free called twice as it used to be
possible to)

Clearing dangling pointers makes the function idempotent and safer to use.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Dominique Martinet <[email protected]>
Reported-by: [email protected]
  • Loading branch information
Dominique Martinet committed Aug 29, 2018
1 parent 81c9908 commit 62e3941
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net/9p/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...);
void p9stat_free(struct p9_wstat *stbuf)
{
kfree(stbuf->name);
stbuf->name = NULL;
kfree(stbuf->uid);
stbuf->uid = NULL;
kfree(stbuf->gid);
stbuf->gid = NULL;
kfree(stbuf->muid);
stbuf->muid = NULL;
kfree(stbuf->extension);
stbuf->extension = NULL;
}
EXPORT_SYMBOL(p9stat_free);

Expand Down

0 comments on commit 62e3941

Please sign in to comment.