Skip to contentSkip to conversation

fs: autofs: fix memory leak in autofs_fill_super()

PATCH Applied Jeffin Philip 3 participants 3 messages Sep 3 – Sep 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: autofs: fix memory leak in autofs_fill_super()

In autofs_fill_super(), we create a new inode using autofs_new_ino(), however, if we fail to create root_inode, (that is, root_inode failure path), we return -ENOMEM without freeing the new inode(ino) that we created causing a memory leak. Fix this by adding autofs_free_ino() to free the inode we created in root_inode failure path before returning ENOMEM.

Reported-by [email protected]
Fixes 66917f85db60 ("autofs: add: new_inode check in autofs_fill_super()")
---
 fs/autofs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs/inode.c +3 -1
index c1e210cec436..6b15a3717ba7 100644
@@ -323,8 +323,10 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
 		return -ENOMEM;
 
 	root_inode = autofs_get_inode(s, S_IFDIR | 0755);
-	if (!root_inode)
+	if (!root_inode) {
+		autofs_free_ino(ino);
 		return -ENOMEM;
+	}
 
 	root_inode->i_uid = ctx->uid;
 	root_inode->i_gid = ctx->gid;
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 22 lines · Jeffin Philip

In autofs_fill_super(), we create a new inode using autofs_new_ino(), however, if we fail to create root_inode, (that is, root_inode failure path), we return -ENOMEM without freeing the new inode(ino) that we created causing a memory leak. Fix this by adding autofs_free_ino() to free the inode we created in root_inode failure path before returning ENOMEM.

Reported-by [email protected]
Fixes 66917f85db60 ("autofs: add: new_inode check in autofs_fill_super()")
---
  fs/autofs/inode.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/autofs/inode.c +0 -0
index c1e210cec436..6b15a3717ba7 100644
@@ -323,8 +323,10 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
  		return -ENOMEM;

fs/autofs/inode.c static int autofs_fill_super(struct super_block *s, struct fs_context *fc) · line 332

Quoted 10 lines
fs/autofs/inode.c +3 -1
 
  	root_inode = autofs_get_inode(s, S_IFDIR | 0755);
-	if (!root_inode)
+	if (!root_inode) {
+		autofs_free_ino(ino);
  		return -ENOMEM;
+	}
 
  	root_inode->i_uid = ctx->uid;
  	root_inode->i_gid = ctx->gid;

Thanks Jeffin, this looks better.

Christian, can you take this one please, ;)

#2 lore raw
In reply to Jeffin Philip
Quoted 8 lines · Jeffin Philip

In autofs_fill_super(), we create a new inode using autofs_new_ino(), however, if we fail to create root_inode, (that is, root_inode failure path), we return -ENOMEM without freeing the new inode(ino) that we created causing a memory leak. Fix this by adding autofs_free_ino() to free the inode we created in root_inode failure path before returning ENOMEM.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs: autofs: fix memory leak in autofs_fill_super()

      https://git.kernel.org/vfs/vfs/c/5ab54837fce0