Skip to contentSkip to conversation

backing_file: Fix error code swallow

PATCH In review Ethan Tidmore 2 participants 2 messages Mar 22 – Mar 23 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backing_file: Fix error code swallow

The macro WARN_ON() returns true if the condition inside is true. So if there is an error with vfs_open() 1 is returned.

Capture the return value of vfs_open() then run WARN_ON() on it.

Detected by Smatch:
fs/backing-file.c:52 backing_file_open() warn:
passing positive error code '1' to 'ERR_PTR'

fs/backing-file.c:77 backing_tmpfile_open() warn:
passing positive error code '1' to 'ERR_PTR'

Fixes 7ea30795d6b7d ("backing_file: store user_path_file")
---
 fs/file_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/file_table.c +5 -1
index e8b4eb2bbff8..0898b1816c14 100644
@@ -69,8 +69,12 @@ EXPORT_SYMBOL_GPL(backing_file_user_path_file);
 
 int backing_file_open_user_path(struct file *f, const struct path *path)
 {
+	int ret;
+
 	/* open an O_PATH file to reference the user path - should not fail */
-	return WARN_ON(vfs_open(path, &backing_file(f)->user_path_file));
+	ret = vfs_open(path, &backing_file(f)->user_path_file);
+	WARN_ON(ret);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(backing_file_open_user_path);
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 10 lines · Ethan Tidmore

The macro WARN_ON() returns true if the condition inside is true. So if there is an error with vfs_open() 1 is returned.

Capture the return value of vfs_open() then run WARN_ON() on it.

Detected by Smatch:
fs/backing-file.c:52 backing_file_open() warn:
passing positive error code '1' to 'ERR_PTR'

Quoted 8 lines

fs/backing-file.c:77 backing_tmpfile_open() warn:
passing positive error code '1' to 'ERR_PTR'

Fixes 7ea30795d6b7d ("backing_file: store user_path_file")
---
 fs/file_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Due to other discussions (see the related threads) I have removed the patch{set} this targets from lsm/{stable-7.0,next}.

Signature · 1 line
paul-moore.com