Commit 425eb0df authored by Dominique Martinet's avatar Dominique Martinet Committed by Kleber Sacilotto de Souza

v9fs_dir_readdir: fix double-free on p9stat_read error

BugLink: https://bugs.launchpad.net/bugs/1810967

commit 81c99089 upstream.

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.orgSigned-off-by: default avatarDominique Martinet <dominique.martinet@cea.fr>
Reported-by: syzbot+d4252148d198410b864f@syzkaller.appspotmail.com
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 7a4f645f
...@@ -76,15 +76,6 @@ static inline int dt_type(struct p9_wstat *mistat) ...@@ -76,15 +76,6 @@ static inline int dt_type(struct p9_wstat *mistat)
return rettype; return rettype;
} }
static void p9stat_init(struct p9_wstat *stbuf)
{
stbuf->name = NULL;
stbuf->uid = NULL;
stbuf->gid = NULL;
stbuf->muid = NULL;
stbuf->extension = NULL;
}
/** /**
* v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
* @filp: opened file structure * @filp: opened file structure
...@@ -145,12 +136,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx) ...@@ -145,12 +136,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
rdir->tail = n; rdir->tail = n;
} }
while (rdir->head < rdir->tail) { while (rdir->head < rdir->tail) {
p9stat_init(&st);
err = p9stat_read(fid->clnt, rdir->buf + rdir->head, err = p9stat_read(fid->clnt, rdir->buf + rdir->head,
rdir->tail - rdir->head, &st); rdir->tail - rdir->head, &st);
if (err) { if (err) {
p9_debug(P9_DEBUG_VFS, "returned %d\n", err); p9_debug(P9_DEBUG_VFS, "returned %d\n", err);
p9stat_free(&st);
return -EIO; return -EIO;
} }
reclen = st.size+2; reclen = st.size+2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment