Skip to contentSkip to conversation

VFS: Change vfs_mkdir() to return the dentry.

bug report Dan Carpenter 2 participants 2 messages Mar 27, 2025 Filesystems netfs library

lore
Share & tools
lore
#0 lore raw

Hello NeilBrown,

Commit c54b386969a5 ("VFS: Change vfs_mkdir() to return the dentry.") from Feb 27, 2025 (linux-next), leads to the following Smatch static checker warning:

fs/cachefiles/namei.c:133 cachefiles_get_directory()
warn: 'subdir' can also be NULL

fs/cachefiles/namei.c

    124                 _debug("attempt mkdir");
    125 
    126                 path.mnt = cache->mnt;
    127                 path.dentry = dir;
    128                 ret = security_path_mkdir(&path, subdir, 0700);
    129                 if (ret < 0)
    130                         goto mkdir_error;
    131                 subdir = ERR_PTR(cachefiles_inject_write_error());

cachefiles_inject_write_error() either return an error pointer or NULL. Never a valid pointer.

132 if (!IS_ERR(subdir))

--> 133                         subdir = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700);
                                                                                 ^^^^^^

Passing a NULL dereference here will lead to a crash.

    134                 ret = PTR_ERR(subdir);
    135                 if (IS_ERR(subdir)) {
    136                         trace_cachefiles_vfs_error(NULL, d_inode(dir), ret,

regards,
dan carpenter

#1 lore raw
Quoted 8 lines · Dan Carpenter

Hello NeilBrown,

Commit c54b386969a5 ("VFS: Change vfs_mkdir() to return the dentry.") from Feb 27, 2025 (linux-next), leads to the following Smatch static checker warning:

fs/cachefiles/namei.c:133 cachefiles_get_directory()
warn: 'subdir' can also be NULL

Thanks Dan.
This has already be found and fixed:
[email protected]
so no further action needed.

Thanks,
NeilBrown

Quoted 27 lines

fs/cachefiles/namei.c

    124                 _debug("attempt mkdir");
    125 
    126                 path.mnt = cache->mnt;
    127                 path.dentry = dir;
    128                 ret = security_path_mkdir(&path, subdir, 0700);
    129                 if (ret < 0)
    130                         goto mkdir_error;
    131                 subdir = ERR_PTR(cachefiles_inject_write_error());

cachefiles_inject_write_error() either return an error pointer or NULL. Never a valid pointer.

132 if (!IS_ERR(subdir))

--> 133                         subdir = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700);
                                                                                 ^^^^^^

Passing a NULL dereference here will lead to a crash.

    134                 ret = PTR_ERR(subdir);
    135                 if (IS_ERR(subdir)) {
    136                         trace_cachefiles_vfs_error(NULL, d_inode(dir), ret,

regards,
dan carpenter