9p: clear dangling pointers in p9stat_free
authorDominique Martinet <dominique.martinet@cea.fr>
Mon, 27 Aug 2018 22:32:35 +0000 (07:32 +0900)
committerDominique Martinet <dominique.martinet@cea.fr>
Wed, 29 Aug 2018 04:39:57 +0000 (13:39 +0900)
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/1535410108-20650-2-git-send-email-asmadeus@codewreck.org
Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
Reported-by: syzbot+d4252148d198410b864f@syzkaller.appspotmail.com
net/9p/protocol.c

index 4a1e1dd30b52fd04abef83272567a1975a840e0f..ee32bbf12675690848a60b3b6ca0a6f87e9e945e 100644 (file)
@@ -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);