Skip to content

Commit 50647a1

Browse files
committed
Merge tag 'pull-f_path' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull file->f_path constification from Al Viro: "Only one thing was modifying ->f_path of an opened file - acct(2). Massaging that away and constifying a bunch of struct path * arguments in functions that might be given &file->f_path ends up with the situation where we can turn ->f_path into an anon union of const struct path f_path and struct path __f_path, the latter modified only in a few places in fs/{file_table,open,namei}.c, all for struct file instances that are yet to be opened" * tag 'pull-f_path' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (23 commits) Have cc(1) catch attempts to modify ->f_path kernel/acct.c: saner struct file treatment configfs:get_target() - release path as soon as we grab configfs_item reference apparmor/af_unix: constify struct path * arguments ovl_is_real_file: constify realpath argument ovl_sync_file(): constify path argument ovl_lower_dir(): constify path argument ovl_get_verity_digest(): constify path argument ovl_validate_verity(): constify {meta,data}path arguments ovl_ensure_verity_loaded(): constify datapath argument ksmbd_vfs_set_init_posix_acl(): constify path argument ksmbd_vfs_inherit_posix_acl(): constify path argument ksmbd_vfs_kern_path_unlock(): constify path argument ksmbd_vfs_path_lookup_locked(): root_share_path can be const struct path * check_export(): constify path argument export_operations->open(): constify path argument rqst_exp_get_by_name(): constify path argument nfs: constify path argument of __vfs_getattr() bpf...d_path(): constify path argument done_path_create(): constify path argument ...
2 parents 070a542 + 2f7d98f commit 50647a1

File tree

26 files changed

+109
-135
lines changed

26 files changed

+109
-135
lines changed

fs/bpf_fs_kfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __bpf_kfunc void bpf_put_file(struct file *file)
7979
* pathname in *buf*, including the NUL termination character. On error, a
8080
* negative integer is returned.
8181
*/
82-
__bpf_kfunc int bpf_path_d_path(struct path *path, char *buf, size_t buf__sz)
82+
__bpf_kfunc int bpf_path_d_path(const struct path *path, char *buf, size_t buf__sz)
8383
{
8484
int len;
8585
char *ret;

fs/configfs/symlink.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,28 @@ static int create_link(struct config_item *parent_item,
114114
}
115115

116116

117-
static int get_target(const char *symname, struct path *path,
118-
struct config_item **target, struct super_block *sb)
117+
static int get_target(const char *symname, struct config_item **target,
118+
struct super_block *sb)
119119
{
120+
struct path path __free(path_put) = {};
120121
int ret;
121122

122-
ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path);
123-
if (!ret) {
124-
if (path->dentry->d_sb == sb) {
125-
*target = configfs_get_config_item(path->dentry);
126-
if (!*target) {
127-
ret = -ENOENT;
128-
path_put(path);
129-
}
130-
} else {
131-
ret = -EPERM;
132-
path_put(path);
133-
}
134-
}
135-
136-
return ret;
123+
ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &path);
124+
if (ret)
125+
return ret;
126+
if (path.dentry->d_sb != sb)
127+
return -EPERM;
128+
*target = configfs_get_config_item(path.dentry);
129+
if (!*target)
130+
return -ENOENT;
131+
return 0;
137132
}
138133

139134

140135
int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
141136
struct dentry *dentry, const char *symname)
142137
{
143138
int ret;
144-
struct path path;
145139
struct configfs_dirent *sd;
146140
struct config_item *parent_item;
147141
struct config_item *target_item = NULL;
@@ -188,7 +182,7 @@ int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
188182
* AV, a thoroughly annoyed bastard.
189183
*/
190184
inode_unlock(dir);
191-
ret = get_target(symname, &path, &target_item, dentry->d_sb);
185+
ret = get_target(symname, &target_item, dentry->d_sb);
192186
inode_lock(dir);
193187
if (ret)
194188
goto out_put;
@@ -210,7 +204,6 @@ int configfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
210204
}
211205

212206
config_item_put(target_item);
213-
path_put(&path);
214207

215208
out_put:
216209
config_item_put(parent_item);

fs/file_table.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct backing_file {
5454

5555
#define backing_file(f) container_of(f, struct backing_file, file)
5656

57-
struct path *backing_file_user_path(const struct file *f)
57+
const struct path *backing_file_user_path(const struct file *f)
5858
{
5959
return &backing_file(f)->user_path;
6060
}
@@ -171,7 +171,7 @@ static int init_file(struct file *f, int flags, const struct cred *cred)
171171
* the respective member when opening the file.
172172
*/
173173
mutex_init(&f->f_pos_lock);
174-
memset(&f->f_path, 0, sizeof(f->f_path));
174+
memset(&f->__f_path, 0, sizeof(f->f_path));
175175
memset(&f->f_ra, 0, sizeof(f->f_ra));
176176

177177
f->f_flags = flags;
@@ -319,7 +319,7 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred)
319319
static void file_init_path(struct file *file, const struct path *path,
320320
const struct file_operations *fop)
321321
{
322-
file->f_path = *path;
322+
file->__f_path = *path;
323323
file->f_inode = path->dentry->d_inode;
324324
file->f_mapping = path->dentry->d_inode->i_mapping;
325325
file->f_wb_err = filemap_sample_wb_err(file->f_mapping);

fs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern int finish_clean_context(struct fs_context *fc);
5353
* namei.c
5454
*/
5555
extern int filename_lookup(int dfd, struct filename *name, unsigned flags,
56-
struct path *path, struct path *root);
56+
struct path *path, const struct path *root);
5757
int do_rmdir(int dfd, struct filename *name);
5858
int do_unlinkat(int dfd, struct filename *name);
5959
int may_linkat(struct mnt_idmap *idmap, const struct path *link);

fs/namei.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
26952695
}
26962696

26972697
int filename_lookup(int dfd, struct filename *name, unsigned flags,
2698-
struct path *path, struct path *root)
2698+
struct path *path, const struct path *root)
26992699
{
27002700
int retval;
27012701
struct nameidata nd;
@@ -3651,8 +3651,8 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry,
36513651
if (nd->flags & LOOKUP_DIRECTORY)
36523652
open_flag |= O_DIRECTORY;
36533653

3654-
file->f_path.dentry = DENTRY_NOT_SET;
3655-
file->f_path.mnt = nd->path.mnt;
3654+
file->__f_path.dentry = DENTRY_NOT_SET;
3655+
file->__f_path.mnt = nd->path.mnt;
36563656
error = dir->i_op->atomic_open(dir, dentry, file,
36573657
open_to_namei_flags(open_flag), mode);
36583658
d_lookup_done(dentry);
@@ -4020,8 +4020,8 @@ int vfs_tmpfile(struct mnt_idmap *idmap,
40204020
child = d_alloc(parentpath->dentry, &slash_name);
40214021
if (unlikely(!child))
40224022
return -ENOMEM;
4023-
file->f_path.mnt = parentpath->mnt;
4024-
file->f_path.dentry = child;
4023+
file->__f_path.mnt = parentpath->mnt;
4024+
file->__f_path.dentry = child;
40254025
mode = vfs_prepare_mode(idmap, dir, mode, mode, mode);
40264026
error = dir->i_op->tmpfile(idmap, dir, file, mode);
40274027
dput(child);
@@ -4256,7 +4256,7 @@ struct dentry *start_creating_path(int dfd, const char *pathname,
42564256
}
42574257
EXPORT_SYMBOL(start_creating_path);
42584258

4259-
void end_creating_path(struct path *path, struct dentry *dentry)
4259+
void end_creating_path(const struct path *path, struct dentry *dentry)
42604260
{
42614261
if (!IS_ERR(dentry))
42624262
dput(dentry);

fs/nfs/localio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ nfs_set_local_verifier(struct inode *inode,
676676
}
677677

678678
/* Factored out from fs/nfsd/vfs.h:fh_getattr() */
679-
static int __vfs_getattr(struct path *p, struct kstat *stat, int version)
679+
static int __vfs_getattr(const struct path *p, struct kstat *stat, int version)
680680
{
681681
u32 request_mask = STATX_BASIC_STATS;
682682

fs/nfsd/export.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static struct svc_export *svc_export_update(struct svc_export *new,
402402
struct svc_export *old);
403403
static struct svc_export *svc_export_lookup(struct svc_export *);
404404

405-
static int check_export(struct path *path, int *flags, unsigned char *uuid)
405+
static int check_export(const struct path *path, int *flags, unsigned char *uuid)
406406
{
407407
struct inode *inode = d_inode(path->dentry);
408408

@@ -1181,7 +1181,7 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp,
11811181
* use exp_get_by_name() or exp_find().
11821182
*/
11831183
struct svc_export *
1184-
rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
1184+
rqst_exp_get_by_name(struct svc_rqst *rqstp, const struct path *path)
11851185
{
11861186
struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
11871187
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);

fs/nfsd/export.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int nfsd_export_init(struct net *);
111111
void nfsd_export_shutdown(struct net *);
112112
void nfsd_export_flush(struct net *);
113113
struct svc_export * rqst_exp_get_by_name(struct svc_rqst *,
114-
struct path *);
114+
const struct path *);
115115
struct svc_export * rqst_exp_parent(struct svc_rqst *,
116116
struct path *);
117117
struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *);

fs/nsfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ static int nsfs_export_permission(struct handle_to_path_ctx *ctx,
571571
return 0;
572572
}
573573

574-
static struct file *nsfs_export_open(struct path *path, unsigned int oflags)
574+
static struct file *nsfs_export_open(const struct path *path, unsigned int oflags)
575575
{
576576
return file_open_root(path, "", oflags, 0);
577577
}

fs/open.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,8 @@ static int do_dentry_open(struct file *f,
10221022
put_file_access(f);
10231023
cleanup_file:
10241024
path_put(&f->f_path);
1025-
f->f_path.mnt = NULL;
1026-
f->f_path.dentry = NULL;
1025+
f->__f_path.mnt = NULL;
1026+
f->__f_path.dentry = NULL;
10271027
f->f_inode = NULL;
10281028
return error;
10291029
}
@@ -1050,7 +1050,7 @@ int finish_open(struct file *file, struct dentry *dentry,
10501050
{
10511051
BUG_ON(file->f_mode & FMODE_OPENED); /* once it's opened, it's opened */
10521052

1053-
file->f_path.dentry = dentry;
1053+
file->__f_path.dentry = dentry;
10541054
return do_dentry_open(file, open);
10551055
}
10561056
EXPORT_SYMBOL(finish_open);
@@ -1073,7 +1073,7 @@ int finish_no_open(struct file *file, struct dentry *dentry)
10731073
{
10741074
if (IS_ERR(dentry))
10751075
return PTR_ERR(dentry);
1076-
file->f_path.dentry = dentry;
1076+
file->__f_path.dentry = dentry;
10771077
return 0;
10781078
}
10791079
EXPORT_SYMBOL(finish_no_open);
@@ -1093,7 +1093,7 @@ int vfs_open(const struct path *path, struct file *file)
10931093
{
10941094
int ret;
10951095

1096-
file->f_path = *path;
1096+
file->__f_path = *path;
10971097
ret = do_dentry_open(file, NULL);
10981098
if (!ret) {
10991099
/*

0 commit comments

Comments
 (0)