Skip to content

Commit 406fad7

Browse files
Marc Dionnebrauner
authored andcommitted
cachefiles: Fix oops in vfs_mkdir from cachefiles_get_directory
Commit c54b386 ("VFS: Change vfs_mkdir() to return the dentry.") changed cachefiles_get_directory, replacing "subdir" with a ERR_PTR from the result of cachefiles_inject_write_error, which is either 0 or some error code. This causes an oops when the resulting pointer is passed to vfs_mkdir. Use a similar pattern to what is used earlier in the function; replace subdir with either the return value from vfs_mkdir, or the ERR_PTR of the cachefiles_inject_write_error() return value, but only if it is non zero. Fixes: c54b386 ("VFS: Change vfs_mkdir() to return the dentry.") cc: netfs@lists.linux.dev Signed-off-by: Marc Dionne <marc.dionne@auristor.com> Link: https://lore.kernel.org/r/20250325125905.395372-1-marc.dionne@auristor.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent af7bb0d commit 406fad7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/cachefiles/namei.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
128128
ret = security_path_mkdir(&path, subdir, 0700);
129129
if (ret < 0)
130130
goto mkdir_error;
131-
subdir = ERR_PTR(cachefiles_inject_write_error());
132-
if (!IS_ERR(subdir))
131+
ret = cachefiles_inject_write_error();
132+
if (ret == 0)
133133
subdir = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700);
134-
ret = PTR_ERR(subdir);
134+
else
135+
subdir = ERR_PTR(ret);
135136
if (IS_ERR(subdir)) {
136137
trace_cachefiles_vfs_error(NULL, d_inode(dir), ret,
137138
cachefiles_trace_mkdir_error);

0 commit comments

Comments
 (0)