Skip to contentSkip to conversation

several fixes from tree-in-dcache stuff

PATCH New Al Viro 2 participants 9 messages Mar 13, 2025

Subsystems (5)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

PATCH 1/1 several fixes from tree-in-dcache stuff

Several fixes for fairly old crap - qibfs leak, a couple of spufs ones and a spufs double-dput() memory corruptor.

This stuff sits in viro/vfs.git#fixes; individual patches in followups. Review would be very welcome.

author maintainer
#1 lore raw

PATCH 1/4 spufs: fix a leak on spufs_new_file() failure

It's called from spufs_fill_dir(), and caller of that will do spufs_rmdir() in case of failure. That does remove everything we'd managed to create, but... the problem dentry is still negative. IOW, it needs to be explicitly dropped.

Fixes 3f51dd91c807 "[PATCH] spufs: fix spufs_fill_dir error path"
---
 arch/powerpc/platforms/cell/spufs/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/platforms/cell/spufs/inode.c +3 -1
index 70236d1df3d3..793c005607cf 100644
@@ -192,8 +192,10 @@ static int spufs_fill_dir(struct dentry *dir,
 			return -ENOMEM;
 		ret = spufs_new_file(dir->d_sb, dentry, files->ops,
 					files->mode & mode, files->size, ctx);
-		if (ret)
+		if (ret) {
+			dput(dentry);
 			return ret;
+		}
 		files++;
 	}
 	return 0;
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] spufs: fix a leak on spufs_new_file() failure

Quoted 8 lines · Al Viro

It's called from spufs_fill_dir(), and caller of that will do spufs_rmdir() in case of failure. That does remove everything we'd managed to create, but... the problem dentry is still negative. IOW, it needs to be explicitly dropped.

Fixes 3f51dd91c807 "[PATCH] spufs: fix spufs_fill_dir error path"

---

author maintainer
#3 lore raw

PATCH 2/4 spufs: fix gang directory lifetimes

In reply to Al Viro

prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have a problem with gang lifetimes - creation of a gang returns opened gang directory, which normally gets removed when that gets closed, but if somebody has created a context belonging to that gang and kept it alive until the gang got closed, removal failed and we ended up with a leak.

Unfortunately, it had been fixed the wrong way. Dentry of gang directory was no longer pinned, and rmdir on close was gone. One problem was that failure of open kept calling simple_rmdir() as cleanup, which meant an unbalanced dput(). Another bug was in the success case - gang creation incremented link count on root directory, but that was no longer undone when gang got destroyed.

Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.

Fixes 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"
---
 arch/powerpc/platforms/cell/spufs/gang.c  |  1 +
 arch/powerpc/platforms/cell/spufs/inode.c | 54 +++++++++++++++++++----
 arch/powerpc/platforms/cell/spufs/spufs.h |  2 +
 3 files changed, 49 insertions(+), 8 deletions(-)
arch/powerpc/platforms/cell/spufs/gang.c +1 -0
index 827d338deaf4..2c2999de6bfa 100644
@@ -25,6 +25,7 @@ struct spu_gang *alloc_spu_gang(void)
 	mutex_init(&gang->aff_mutex);
 	INIT_LIST_HEAD(&gang->list);
 	INIT_LIST_HEAD(&gang->aff_list_head);
+	gang->alive = 1;
 
 out:
 	return gang;
arch/powerpc/platforms/cell/spufs/inode.c +46 -8

111 lines not on this page · raw message

arch/powerpc/platforms/cell/spufs/spufs.h +2 -0
index 84958487f696..d33787c57c39 100644
@@ -151,6 +151,8 @@ struct spu_gang {
 	int aff_flags;
 	struct spu *aff_ref_spu;
 	atomic_t aff_sched_count;
+
+	int alive;
 };
 
 /* Flag bits for spu_gang aff_flags */
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] spufs: fix gang directory lifetimes

Quoted 25 lines · Al Viro

prior to "[POWERPC] spufs: Fix gang destroy leaks" we used to have a problem with gang lifetimes - creation of a gang returns opened gang directory, which normally gets removed when that gets closed, but if somebody has created a context belonging to that gang and kept it alive until the gang got closed, removal failed and we ended up with a leak.

Unfortunately, it had been fixed the wrong way. Dentry of gang directory was no longer pinned, and rmdir on close was gone. One problem was that failure of open kept calling simple_rmdir() as cleanup, which meant an unbalanced dput(). Another bug was in the success case - gang creation incremented link count on root directory, but that was no longer undone when gang got destroyed.

Fix consists of
* reverting the commit in question
* adding a counter to gang, protected by ->i_rwsem
of gang directory inode.
* having it set to 1 at creation time, dropped
in both spufs_dir_close() and spufs_gang_close() and bumped in spufs_create_context(), provided that it's not 0.
* using simple_recursive_removal() to take the gang
directory out when counter reaches zero.

Quoted 3 lines
Fixes 877907d37da9 "[POWERPC] spufs: Fix gang destroy leaks"

---

author maintainer
#5 lore raw

PATCH 3/4 spufs: fix a leak in spufs_create_context()

In reply to Al Viro

Leak fixes back in 2008 missed one case - if we are trying to set affinity and spufs_mkdir() fails, we need to drop the reference to neighbor.

Fixes 58119068cb27 "[POWERPC] spufs: Fix memory leak on SPU affinity"
---
 arch/powerpc/platforms/cell/spufs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/cell/spufs/inode.c +4 -1
index c566e7997f2c..9f9e4b871627 100644
@@ -460,8 +460,11 @@ spufs_create_context(struct inode *inode, struct dentry *dentry,
 	}
 
 	ret = spufs_mkdir(inode, dentry, flags, mode & 0777);
-	if (ret)
+	if (ret) {
+		if (neighbor)
+			put_spu_context(neighbor);
 		goto out_aff_unlock;
+	}
 
 	if (affinity) {
 		spufs_set_affinity(flags, SPUFS_I(d_inode(dentry))->i_ctx,
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] spufs: fix a leak in spufs_create_context()

Quoted 6 lines · Al Viro

Leak fixes back in 2008 missed one case - if we are trying to set affinity and spufs_mkdir() fails, we need to drop the reference to neighbor.

Fixes 58119068cb27 "[POWERPC] spufs: Fix memory leak on SPU affinity"

---

author maintainer
#7 lore raw

PATCH 4/4 qibfs: fix _another_ leak

In reply to Al Viro

failure to allocate inode => leaked dentry...

this one had been there since the initial merge; to be fair, if we are that far OOM, the odds of failing at that particular allocation are low...

---
 drivers/infiniband/hw/qib/qib_fs.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/hw/qib/qib_fs.c +1 -0
index b27791029fa9..b9f4a2937c3a 100644
@@ -55,6 +55,7 @@ static int qibfs_mknod(struct inode *dir, struct dentry *dentry,
 	struct inode *inode = new_inode(dir->i_sb);
 
 	if (!inode) {
+		dput(dentry);
 		error = -EPERM;
 		goto bail;
 	}
Signature · 1 line
2.39.5