aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <dominique.martinet@cea.fr>2018-08-27 02:12:05 -0400
committerDominique Martinet <dominique.martinet@cea.fr>2018-08-29 00:39:57 -0400
commit81c99089bce693b94b775b6eb888115d2d540086 (patch)
tree2ffc0b75de3cfdc02778b1a0b45c23b6cdef5496
parent2f9ad0ac947ccbe3ffe7c6229c9330f2a7755f64 (diff)
v9fs_dir_readdir: fix double-free on p9stat_read error
p9stat_read will call p9stat_free on error, we should only free the struct content on success. There also is no need to "p9stat_init" st as the read function will zero the whole struct for us anyway, so clean up the code a bit while we are here. Link: http://lkml.kernel.org/r/1535410108-20650-1-git-send-email-asmadeus@codewreck.org Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr> Reported-by: syzbot+d4252148d198410b864f@syzkaller.appspotmail.com
-rw-r--r--fs/9p/vfs_dir.c11
1 files changed, 0 insertions, 11 deletions
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index b0405d6aac85..48db9a9f13f9 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -76,15 +76,6 @@ static inline int dt_type(struct p9_wstat *mistat)
76 return rettype; 76 return rettype;
77} 77}
78 78
79static void p9stat_init(struct p9_wstat *stbuf)
80{
81 stbuf->name = NULL;
82 stbuf->uid = NULL;
83 stbuf->gid = NULL;
84 stbuf->muid = NULL;
85 stbuf->extension = NULL;
86}
87
88/** 79/**
89 * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir 80 * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
90 * @filp: opened file structure 81 * @filp: opened file structure
@@ -145,12 +136,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
145 rdir->tail = n; 136 rdir->tail = n;
146 } 137 }
147 while (rdir->head < rdir->tail) { 138 while (rdir->head < rdir->tail) {
148 p9stat_init(&st);
149 err = p9stat_read(fid->clnt, rdir->buf + rdir->head, 139 err = p9stat_read(fid->clnt, rdir->buf + rdir->head,
150 rdir->tail - rdir->head, &st); 140 rdir->tail - rdir->head, &st);
151 if (err) { 141 if (err) {
152 p9_debug(P9_DEBUG_VFS, "returned %d\n", err); 142 p9_debug(P9_DEBUG_VFS, "returned %d\n", err);
153 p9stat_free(&st);
154 return -EIO; 143 return -EIO;
155 } 144 }
156 reclen = st.size+2; 145 reclen = st.size+2;