Skip to contentSkip to conversation

autofs: Use autofs4_free_ino() to kfree dentry data

PATCH In review Tomohiro Kusumi 2 participants 4 messages Jul 2, 2016 – Jul 8, 2016 Kernel automounter

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 autofs: Use autofs4_free_ino() to kfree dentry data

kfree dentry data allocated by autofs4_new_ino() with autofs4_free_ino() instead of raw kfree. (since we have the interface to free autofs_info*)

---
 fs/autofs4/inode.c | 2 +-
 fs/autofs4/root.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/autofs4/inode.c +1 -1
index 8357544..ad0ee93 100644
@@ -339,7 +339,7 @@ fail_dput:
 	dput(root);
 	goto fail_free;
 fail_ino:
-	kfree(ino);
+	autofs4_free_ino(ino);
 fail_free:
 	put_pid(sbi->oz_pgrp);
 	kfree(sbi);
fs/autofs4/root.c +1 -1
index 3767f66..93d3232 100644
@@ -578,7 +578,7 @@ static int autofs4_dir_symlink(struct inode *dir,
 	if (!inode) {
 		kfree(cp);
 		if (!dentry->d_fsdata)
-			kfree(ino);
+			autofs4_free_ino(ino);
 		return -ENOMEM;
 	}
 	inode->i_private = cp;
Signature · 4 lines
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe autofs" in
#1 lore raw

PATCH 2/2 autofs: Fix conditional to kfree dentry data

if (!dentry->d_fsdata) should be testing d_fsdata or ino without !.

---
 fs/autofs4/root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/autofs4/root.c +1 -1
index 93d3232..5a877bf 100644
@@ -577,7 +577,7 @@ static int autofs4_dir_symlink(struct inode *dir,
 	inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555);
 	if (!inode) {
 		kfree(cp);
-		if (!dentry->d_fsdata)
+		if (ino)
 			autofs4_free_ino(ino);
 		return -ENOMEM;
 	}
Signature · 4 lines
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe autofs" in
maintainer
#2 lore raw

Re: [PATCH 2/2] autofs: Fix conditional to kfree dentry data

Quoted 1 line · Tomohiro Kusumi

if (!dentry->d_fsdata) should be testing d_fsdata or ino without !.

I've added both of these to the list of kernel patches I have, hopefully I'll be able to get the needed testing done to send them to Andrew after the next merge window.

But I need to take a closer look at this one though.

There's another ENOMEM return just above this where ino is not freed.

So I'm wondering if it should be freed here at all.

It belongs to the dentry and would get freed using autofs4_dentry_release() on final dput() and that takes care of additional house keeping too (although a symlink dentry is a bit different and shouldn't need that extra cleanup).

What really worries me is that autofs4_free_ino() doesn't set d_fsdata to NULL so there's a chance of a double free when autofs4_dentry_release() is finally called.

Quoted 11 lines
---
 fs/autofs4/root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/autofs4/root.c +0 -0
index 93d3232..5a877bf 100644

fs/autofs4/root.c static int autofs4_dir_symlink(struct inode *dir, · line 583

Quoted 8 lines
fs/autofs4/root.c +1 -1
@@ -577,7 +577,7 @@ static int autofs4_dir_symlink(struct inode *dir,
 	inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555);
 	if (!inode) {
 		kfree(cp);
-		if (!dentry->d_fsdata)
+		if (ino)
 			autofs4_free_ino(ino);
 		return -ENOMEM;
 	}

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

maintainer
#3 lore raw

Re: [PATCH 2/2] autofs: Fix conditional to kfree dentry data

Quoted 15 lines · Ian Kent
Quoted 1 line · Tomohiro Kusumi

if (!dentry->d_fsdata) should be testing d_fsdata or ino without !.

I've added both of these to the list of kernel patches I have, hopefully I'll be
able to get the needed testing done to send them to Andrew after the next merge
window.

But I need to take a closer look at this one though.

There's another ENOMEM return just above this where ino is not freed.

So I'm wondering if it should be freed here at all.

Quoted 7 lines

It belongs to the dentry and would get freed using autofs4_dentry_release() on final dput() and that takes care of additional house keeping too (although a symlink dentry is a bit different and shouldn't need that extra cleanup).

What really worries me is that autofs4_free_ino() doesn't set d_fsdata to NULL so there's a chance of a double free when autofs4_dentry_release() is finally called.

I've removed the free from autofs4_dir_symlink(), it really should be done by d_release() on final dput.

Quoted 7 lines
Quoted 7 lines
---
 fs/autofs4/root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

fs/autofs4/root.c static int autofs4_dir_symlink(struct inode *dir, · line 583

Quoted 13 lines
fs/autofs4/root.c +1 -1
index 93d3232..5a877bf 100644
@@ -577,7 +577,7 @@ static int autofs4_dir_symlink(struct inode *dir,
 	inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555);
 	if (!inode) {
 		kfree(cp);
-		if (!dentry->d_fsdata)
+		if (ino)
 			autofs4_free_ino(ino);
 		return -ENOMEM;
 	}

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

--
To unsubscribe from this list: send the line "unsubscribe autofs" in