Skip to contentSkip to conversation

configfs: Fix config_item refcnt error in __configfs_open_file()

PATCH Superseded [email protected] 2 participants 3 messages Mar 11, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 configfs: Fix config_item refcnt error in __configfs_open_file()

From: Daniel Rosenberg <[email protected]>

__configfs_open_file() used to use configfs_get_config_item, but changed in commit b0841eefd969 ("configfs: provide exclusion between IO and removals") to just call to_item. The error path still tries to clean up the reference, incorrectly decrementing the ref count.

Fixes b0841eefd969 ("configfs: provide exclusion between IO and removals")
---
 fs/configfs/file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/configfs/file.c +2 -4
index 1f0270229d7b..8b7c8a8a09f3 100644
@@ -378,7 +378,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 
 	attr = to_attr(dentry);
 	if (!attr)
-		goto out_put_item;
+		goto out_put_module;
 
 	if (type & CONFIGFS_ITEM_BIN_ATTR) {
 		buffer->bin_attr = to_bin_attr(dentry);
@@ -391,7 +391,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 	/* Grab the module reference for this attribute if we have one */
 	error = -ENODEV;
 	if (!try_module_get(buffer->owner))
-		goto out_put_item;
+		goto out_put_module;
 
 	error = -EACCES;
 	if (!buffer->item->ci_type)
@@ -435,8 +435,6 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 
 out_put_module:
 	module_put(buffer->owner);
-out_put_item:
-	config_item_put(buffer->item);
 out_free_buffer:
 	up_read(&frag->frag_sem);
 	kfree(buffer);
Signature · 1 line
2.30.2
#1 lore raw

I've actually just queued up a similar patch from Daiyue Zhang.

Quoted 15 lines
fs/configfs/file.c +2 -2
-		goto out_put_item;
+		goto out_put_module;
 
 	if (type & CONFIGFS_ITEM_BIN_ATTR) {
 		buffer->bin_attr = to_bin_attr(dentry);
@@ -391,7 +391,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 	/* Grab the module reference for this attribute if we have one */
 	error = -ENODEV;
 	if (!try_module_get(buffer->owner))
-		goto out_put_item;
+		goto out_put_module;
 
 	error = -EACCES;
 	if (!buffer->item->ci_type)

fs/configfs/file.c static int __configfs_open_file(struct inode *inode, struct file *file, int type · line 438

Quoted 6 lines
fs/configfs/file.c +0 -2
@@ -435,8 +435,6 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 
 out_put_module:
 	module_put(buffer->owner);
-out_put_item:
-	config_item_put(buffer->item);
 out_free_buffer:

But the goto labe changes here look incorrect anyway, as they now introduce a double put on the module..

author maintainer
#2 lore raw
Quoted 18 lines · Christoph Hellwig

I've actually just queued up a similar patch from Daiyue Zhang.

Quoted 16 lines
fs/configfs/file.c +2 -2
-		goto out_put_item;
+		goto out_put_module;
 
 	if (type & CONFIGFS_ITEM_BIN_ATTR) {
 		buffer->bin_attr = to_bin_attr(dentry);
@@ -391,7 +391,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 	/* Grab the module reference for this attribute if we have one */
 	error = -ENODEV;
 	if (!try_module_get(buffer->owner))
-		goto out_put_item;
+		goto out_put_module;
 
 	error = -EACCES;
 	if (!buffer->item->ci_type)
@@ -435,8 +435,6 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
 
Quoted 8 lines

fs/configfs/file.c static int __configfs_open_file(struct inode *inode, struct file *file, int type · line 438

Quoted 5 lines
fs/configfs/file.c +0 -2
 out_put_module:
 	module_put(buffer->owner);
-out_put_item:
-	config_item_put(buffer->item);
 out_free_buffer:

But the goto labe changes here look incorrect anyway, as they now introduce a double put on the module..

Oops, should be one label lower. Daniel must not have checked this on a system with modules :)

Let me go fix this up...

thanks,

greg k-h