Thread (134 messages) 134 messages, 4 authors, 2016-12-01
STALE3502d REVIEWED: 1 (1M)

[PATCH 3.12 008/127] UBIFS: Fix possible memory leak in ubifs_readdir()

From: Jiri Slaby <hidden>
Date: 2016-11-25 09:11:35
Also in: lkml
Subsystem: filesystems (vfs and infrastructure), the rest, ubi file system (ubifs) · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds, Richard Weinberger

From: Richard Weinberger <richard@nod.at>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit aeeb14f763917ccf639a602cfbeee6957fd944a2 upstream.

If ubifs_tnc_next_ent() returns something else than -ENOENT
we leak file->private_data.

Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: David Gstir <david@sigma-star.at>
Signed-off-by: Jiri Slaby <redacted>
---
 fs/ubifs/dir.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 6b4947f75af7..9bd17a857667 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -447,13 +447,14 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
 	}
 
 out:
+	kfree(file->private_data);
+	file->private_data = NULL;
+
 	if (err != -ENOENT) {
 		ubifs_err("cannot find next direntry, error %d", err);
 		return err;
 	}
 
-	kfree(file->private_data);
-	file->private_data = NULL;
 	/* 2 is a special value indicating that there are no more direntries */
 	ctx->pos = 2;
 	return 0;
-- 
2.10.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help