Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cachefiles: Use lookup_one() rather than lookup_one_len()

cachefiles uses some VFS interfaces (such as vfs_mkdir) which take an
explicit mnt_idmap, and it passes &nop_mnt_idmap as cachefiles doesn't
yet support idmapped mounts.

It also uses the lookup_one_len() family of functions which implicitly
use &nop_mnt_idmap. This mixture of implicit and explicit could be
confusing. When we eventually update cachefiles to support idmap mounts it
would be best if all places which need an idmap determined from the
mount point were similar and easily found.

So this patch changes cachefiles to use lookup_one(), lookup_one_unlocked(),
and lookup_one_positive_unlocked(), passing &nop_mnt_idmap.

This has the benefit of removing the remaining user of the
lookup_one_len functions where permission checking is actually needed.
Other callers don't care about permission checking and using these
function only where permission checking is needed is a valuable
simplification.

This requires passing the name in a qstr. This is easily done with
QSTR() as the name is always nul terminated, and often strlen is used
anyway. ->d_name_len is removed as no longer useful.

Signed-off-by: NeilBrown <neilb@suse.de>
Link: https://lore.kernel.org/r/20250319031545.2999807-4-neil@brown.name
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

NeilBrown and committed by
Christian Brauner
2011067c 8ad92484

+7 -9
-1
fs/cachefiles/internal.h
··· 71 71 int debug_id; 72 72 spinlock_t lock; 73 73 refcount_t ref; 74 - u8 d_name_len; /* Length of filename */ 75 74 enum cachefiles_content content_info:8; /* Info about content presence */ 76 75 unsigned long flags; 77 76 #define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */
-1
fs/cachefiles/key.c
··· 132 132 success: 133 133 name[len] = 0; 134 134 object->d_name = name; 135 - object->d_name_len = len; 136 135 _leave(" = %s", object->d_name); 137 136 return true; 138 137 }
+7 -7
fs/cachefiles/namei.c
··· 98 98 retry: 99 99 ret = cachefiles_inject_read_error(); 100 100 if (ret == 0) 101 - subdir = lookup_one_len(dirname, dir, strlen(dirname)); 101 + subdir = lookup_one(&nop_mnt_idmap, &QSTR(dirname), dir); 102 102 else 103 103 subdir = ERR_PTR(ret); 104 104 trace_cachefiles_lookup(NULL, dir, subdir); ··· 338 338 return -EIO; 339 339 } 340 340 341 - grave = lookup_one_len(nbuffer, cache->graveyard, strlen(nbuffer)); 341 + grave = lookup_one(&nop_mnt_idmap, &QSTR(nbuffer), cache->graveyard); 342 342 if (IS_ERR(grave)) { 343 343 unlock_rename(cache->graveyard, dir); 344 344 trace_cachefiles_vfs_error(object, d_inode(cache->graveyard), ··· 630 630 /* Look up path "cache/vol/fanout/file". */ 631 631 ret = cachefiles_inject_read_error(); 632 632 if (ret == 0) 633 - dentry = lookup_positive_unlocked(object->d_name, fan, 634 - object->d_name_len); 633 + dentry = lookup_one_positive_unlocked(&nop_mnt_idmap, 634 + &QSTR(object->d_name), fan); 635 635 else 636 636 dentry = ERR_PTR(ret); 637 637 trace_cachefiles_lookup(object, fan, dentry); ··· 683 683 inode_lock_nested(d_inode(fan), I_MUTEX_PARENT); 684 684 ret = cachefiles_inject_read_error(); 685 685 if (ret == 0) 686 - dentry = lookup_one_len(object->d_name, fan, object->d_name_len); 686 + dentry = lookup_one(&nop_mnt_idmap, &QSTR(object->d_name), fan); 687 687 else 688 688 dentry = ERR_PTR(ret); 689 689 if (IS_ERR(dentry)) { ··· 702 702 dput(dentry); 703 703 ret = cachefiles_inject_read_error(); 704 704 if (ret == 0) 705 - dentry = lookup_one_len(object->d_name, fan, object->d_name_len); 705 + dentry = lookup_one(&nop_mnt_idmap, &QSTR(object->d_name), fan); 706 706 else 707 707 dentry = ERR_PTR(ret); 708 708 if (IS_ERR(dentry)) { ··· 751 751 752 752 inode_lock_nested(d_inode(dir), I_MUTEX_PARENT); 753 753 754 - victim = lookup_one_len(filename, dir, strlen(filename)); 754 + victim = lookup_one(&nop_mnt_idmap, &QSTR(filename), dir); 755 755 if (IS_ERR(victim)) 756 756 goto lookup_error; 757 757 if (d_is_negative(victim))