Skip to content

Commit 6d5b940

Browse files
committed
Merge tag 'vfs-6.16-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs directory lookup updates from Christian Brauner: "This contains cleanups for the lookup_one*() family of helpers. We expose a set of functions with names containing "lookup_one_len" and others without the "_len". This difference has nothing to do with "len". It's rater a historical accident that can be confusing. The functions without "_len" take a "mnt_idmap" pointer. This is found in the "vfsmount" and that is an important question when choosing which to use: do you have a vfsmount, or are you "inside" the filesystem. A related question is "is permission checking relevant here?". nfsd and cachefiles *do* have a vfsmount but *don't* use the non-_len functions. They pass nop_mnt_idmap and refuse to work on filesystems which have any other idmap. This work changes nfsd and cachefile to use the lookup_one family of functions and to explictily pass &nop_mnt_idmap which is consistent with all other vfs interfaces used where &nop_mnt_idmap is explicitly passed. The remaining uses of the "_one" functions do not require permission checks so these are renamed to be "_noperm" and the permission checking is removed. This series also changes these lookup function to take a qstr instead of separate name and len. In many cases this simplifies the call" * tag 'vfs-6.16-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: VFS: change lookup_one_common and lookup_noperm_common to take a qstr Use try_lookup_noperm() instead of d_hash_and_lookup() outside of VFS VFS: rename lookup_one_len family to lookup_noperm and remove permission check cachefiles: Use lookup_one() rather than lookup_one_len() nfsd: Use lookup_one() rather than lookup_one_len() VFS: improve interface for lookup_one functions
2 parents 0ff41df + 4e5c53e commit 6d5b940

File tree

48 files changed

+254
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+254
-210
lines changed

Documentation/filesystems/porting.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,43 @@ should use d_drop();d_splice_alias() and return the result of the latter.
12031203
If a positive dentry cannot be returned for some reason, in-kernel
12041204
clients such as cachefiles, nfsd, smb/server may not perform ideally but
12051205
will fail-safe.
1206+
1207+
---
1208+
1209+
** mandatory**
1210+
1211+
lookup_one(), lookup_one_unlocked(), lookup_one_positive_unlocked() now
1212+
take a qstr instead of a name and len. These, not the "one_len"
1213+
versions, should be used whenever accessing a filesystem from outside
1214+
that filesysmtem, through a mount point - which will have a mnt_idmap.
1215+
1216+
---
1217+
1218+
** mandatory**
1219+
1220+
Functions try_lookup_one_len(), lookup_one_len(),
1221+
lookup_one_len_unlocked() and lookup_positive_unlocked() have been
1222+
renamed to try_lookup_noperm(), lookup_noperm(),
1223+
lookup_noperm_unlocked(), lookup_noperm_positive_unlocked(). They now
1224+
take a qstr instead of separate name and length. QSTR() can be used
1225+
when strlen() is needed for the length.
1226+
1227+
For try_lookup_noperm() a reference to the qstr is passed in case the
1228+
hash might subsequently be needed.
1229+
1230+
These function no longer do any permission checking - they previously
1231+
checked that the caller has 'X' permission on the parent. They must
1232+
ONLY be used internally by a filesystem on itself when it knows that
1233+
permissions are irrelevant or in a context where permission checks have
1234+
already been performed such as after vfs_path_parent_lookup()
1235+
1236+
---
1237+
1238+
** mandatory**
1239+
1240+
d_hash_and_lookup() is no longer exported or available outside the VFS.
1241+
Use try_lookup_noperm() instead. This adds name validation and takes
1242+
arguments in the opposite order but is otherwise identical.
1243+
1244+
Using try_lookup_noperm() will require linux/namei.h to be included.
1245+

arch/s390/hypfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
342342
struct inode *inode;
343343

344344
inode_lock(d_inode(parent));
345-
dentry = lookup_one_len(name, parent, strlen(name));
345+
dentry = lookup_noperm(&QSTR(name), parent);
346346
if (IS_ERR(dentry)) {
347347
dentry = ERR_PTR(-ENOMEM);
348348
goto fail;

drivers/android/binderfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
187187
inode_lock(d_inode(root));
188188

189189
/* look it up */
190-
dentry = lookup_one_len(name, root, name_len);
190+
dentry = lookup_noperm(&QSTR(name), root);
191191
if (IS_ERR(dentry)) {
192192
inode_unlock(d_inode(root));
193193
ret = PTR_ERR(dentry);
@@ -487,7 +487,7 @@ static struct dentry *binderfs_create_dentry(struct dentry *parent,
487487
{
488488
struct dentry *dentry;
489489

490-
dentry = lookup_one_len(name, parent, strlen(name));
490+
dentry = lookup_noperm(&QSTR(name), parent);
491491
if (IS_ERR(dentry))
492492
return dentry;
493493

drivers/infiniband/hw/qib/qib_fs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int create_file(const char *name, umode_t mode,
9090
int error;
9191

9292
inode_lock(d_inode(parent));
93-
*dentry = lookup_one_len(name, parent, strlen(name));
93+
*dentry = lookup_noperm(&QSTR(name), parent);
9494
if (!IS_ERR(*dentry))
9595
error = qibfs_mknod(d_inode(parent), *dentry,
9696
mode, fops, data);
@@ -433,7 +433,7 @@ static int remove_device_files(struct super_block *sb,
433433
char unit[10];
434434

435435
snprintf(unit, sizeof(unit), "%u", dd->unit);
436-
dir = lookup_one_len_unlocked(unit, sb->s_root, strlen(unit));
436+
dir = lookup_noperm_unlocked(&QSTR(unit), sb->s_root);
437437

438438
if (IS_ERR(dir)) {
439439
pr_err("Lookup of %s failed\n", unit);

fs/afs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
943943
}
944944

945945
strcpy(p, name);
946-
ret = lookup_one_len(buf, dentry->d_parent, len);
946+
ret = lookup_noperm(&QSTR(buf), dentry->d_parent);
947947
if (IS_ERR(ret) || d_is_positive(ret))
948948
goto out_s;
949949
dput(ret);

fs/afs/dir_silly.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,14 @@ int afs_sillyrename(struct afs_vnode *dvnode, struct afs_vnode *vnode,
113113

114114
sdentry = NULL;
115115
do {
116-
int slen;
117-
118116
dput(sdentry);
119117
sillycounter++;
120118

121119
/* Create a silly name. Note that the ".__afs" prefix is
122120
* understood by the salvager and must not be changed.
123121
*/
124-
slen = scnprintf(silly, sizeof(silly), ".__afs%04X", sillycounter);
125-
sdentry = lookup_one_len(silly, dentry->d_parent, slen);
122+
scnprintf(silly, sizeof(silly), ".__afs%04X", sillycounter);
123+
sdentry = lookup_noperm(&QSTR(silly), dentry->d_parent);
126124

127125
/* N.B. Better to return EBUSY here ... it could be dangerous
128126
* to delete the file while it's in use.

fs/autofs/dev-ioctl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ static int autofs_dev_ioctl_timeout(struct file *fp,
459459
"the parent autofs mount timeout which could "
460460
"prevent shutdown\n");
461461

462-
dentry = try_lookup_one_len(param->path, base, path_len);
462+
dentry = try_lookup_noperm(&QSTR_LEN(param->path, path_len),
463+
base);
463464
if (IS_ERR_OR_NULL(dentry))
464465
return dentry ? PTR_ERR(dentry) : -ENOENT;
465466
ino = autofs_dentry_ino(dentry);

fs/binfmt_misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
842842
}
843843

844844
inode_lock(d_inode(root));
845-
dentry = lookup_one_len(e->name, root, strlen(e->name));
845+
dentry = lookup_noperm(&QSTR(e->name), root);
846846
err = PTR_ERR(dentry);
847847
if (IS_ERR(dentry))
848848
goto out;

fs/btrfs/ioctl.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static noinline int btrfs_mksubvol(const struct path *parent,
909909
if (error == -EINTR)
910910
return error;
911911

912-
dentry = lookup_one(idmap, name, parent->dentry, namelen);
912+
dentry = lookup_one(idmap, &QSTR_LEN(name, namelen), parent->dentry);
913913
error = PTR_ERR(dentry);
914914
if (IS_ERR(dentry))
915915
goto out_unlock;
@@ -2288,7 +2288,6 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
22882288
struct btrfs_ioctl_vol_args_v2 *vol_args2 = NULL;
22892289
struct mnt_idmap *idmap = file_mnt_idmap(file);
22902290
char *subvol_name, *subvol_name_ptr = NULL;
2291-
int subvol_namelen;
22922291
int ret = 0;
22932292
bool destroy_parent = false;
22942293

@@ -2411,10 +2410,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
24112410
goto out;
24122411
}
24132412

2414-
subvol_namelen = strlen(subvol_name);
2415-
24162413
if (strchr(subvol_name, '/') ||
2417-
strncmp(subvol_name, "..", subvol_namelen) == 0) {
2414+
strcmp(subvol_name, "..") == 0) {
24182415
ret = -EINVAL;
24192416
goto free_subvol_name;
24202417
}
@@ -2427,7 +2424,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
24272424
ret = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT);
24282425
if (ret == -EINTR)
24292426
goto free_subvol_name;
2430-
dentry = lookup_one(idmap, subvol_name, parent, subvol_namelen);
2427+
dentry = lookup_one(idmap, &QSTR(subvol_name), parent);
24312428
if (IS_ERR(dentry)) {
24322429
ret = PTR_ERR(dentry);
24332430
goto out_unlock_dir;

fs/cachefiles/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ struct cachefiles_object {
7171
int debug_id;
7272
spinlock_t lock;
7373
refcount_t ref;
74-
u8 d_name_len; /* Length of filename */
7574
enum cachefiles_content content_info:8; /* Info about content presence */
7675
unsigned long flags;
7776
#define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */

0 commit comments

Comments
 (0)