diff --git a/fs/sharefs/authentication.c b/fs/sharefs/authentication.c index bc6e825092fa5e029cd6990562bc635e8ba8f1d1..8986fcbcc894dd48f5312a6b77d2d6327b077089 100644 --- a/fs/sharefs/authentication.c +++ b/fs/sharefs/authentication.c @@ -75,8 +75,7 @@ void sharefs_root_inode_perm_init(struct inode *root_inode) hii->perm = SHAREFS_PERM_FIX; } -#ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE -const struct cred *sharefs_override_file_fsids(struct inode *dir, __u16 *_perm) +const struct cred *sharefs_override_file_fsids(struct inode *dir) { struct cred *cred = NULL; cred = prepare_creds(); @@ -95,4 +94,3 @@ void sharefs_revert_fsids(const struct cred *old_cred) revert_creds(old_cred); put_cred(cur_cred); } -#endif diff --git a/fs/sharefs/authentication.h b/fs/sharefs/authentication.h index e598fa883c0a47f52b4264314864ccad4d2884fb..0a096d1ee710413580719544ec81cf731bdb86de 100644 --- a/fs/sharefs/authentication.h +++ b/fs/sharefs/authentication.h @@ -40,11 +40,8 @@ extern void sharefs_exit_configfs(void); void sharefs_root_inode_perm_init(struct inode *root_inode); void fixup_perm_from_level(struct inode *dir, struct dentry *dentry); -#ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE -const struct cred *sharefs_override_file_fsids(struct inode *dir, - __u16 *_perm); +const struct cred *sharefs_override_file_fsids(struct inode *dir); void sharefs_revert_fsids(const struct cred *old_cred); -#endif static inline bool is_read_only_auth(__u16 perm) { diff --git a/fs/sharefs/dentry.c b/fs/sharefs/dentry.c index 99bebb4df2b1ad7a22ca4901e7e8770954183bcb..c1a4c30f30fe70596621bca66c882090b2c4c914 100644 --- a/fs/sharefs/dentry.c +++ b/fs/sharefs/dentry.c @@ -10,6 +10,7 @@ */ #include "sharefs.h" +#include "authentication.h" /* * returns: 0: tell VFS to invalidate dentry in share directory @@ -82,24 +83,34 @@ int sharefs_get_lower_path(struct dentry *d, struct path *lower_path, bool try_to_create) { int err = -ENOMEM; - char *path_buf = kmalloc(PATH_MAX, GFP_KERNEL); + char *path_buf; char *path_name = NULL; struct path lower_root_path; + const struct cred *saved_cred = NULL; + if (unlikely(!d)) + goto out; + + path_buf = kmalloc(PATH_MAX, GFP_KERNEL); if (unlikely(!path_buf)) goto out; - if (unlikely(!d)) - goto out_free; path_name = dentry_path_raw(d, path_buf, PATH_MAX); if (IS_ERR(path_name)) { err = PTR_ERR(path_name); goto out_free; } + sharefs_get_lower_root_path(d, &lower_root_path); + saved_cred = sharefs_override_file_fsids(d_inode(lower_root_path.dentry)); + if (!saved_cred) { + sharefs_put_lower_path(d, &lower_root_path); + goto out_free; + } spin_lock(&SHAREFS_D(d)->lock); err = vfs_path_lookup(lower_root_path.dentry, lower_root_path.mnt, path_name, LOOKUP_CREATE, lower_path); spin_unlock(&SHAREFS_D(d)->lock); + sharefs_revert_fsids(saved_cred); sharefs_put_lower_path(d, &lower_root_path); if (err != -ENOENT || !try_to_create) diff --git a/fs/sharefs/inode.c b/fs/sharefs/inode.c index 7313e34b84410b1c26b740ca897f8684ae5ddbf0..34215a709fc98bd83f27ef6a654d8ed6223760b7 100644 --- a/fs/sharefs/inode.c +++ b/fs/sharefs/inode.c @@ -141,9 +141,8 @@ static int sharefs_create(struct inode *dir, struct dentry *dentry, struct path lower_path; const struct cred *saved_cred = NULL; struct inode *lower_inode = NULL; - __u16 child_perm; - saved_cred = sharefs_override_file_fsids(dir, &child_perm); + saved_cred = sharefs_override_file_fsids(dir); if (!saved_cred) { err = -ENOMEM; return err; @@ -188,9 +187,8 @@ static int sharefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) struct path lower_path; const struct cred *saved_cred = NULL; struct inode *lower_inode = NULL; - __u16 child_perm; - saved_cred = sharefs_override_file_fsids(dir, &child_perm); + saved_cred = sharefs_override_file_fsids(dir); if (!saved_cred) { err = -ENOMEM; return err; diff --git a/fs/sharefs/lookup.c b/fs/sharefs/lookup.c index a7e019d74c0dae6fed20375f124a40166c0ea20f..9d5536c83161854d9e8a79ed337b5a5e6a74d977 100644 --- a/fs/sharefs/lookup.c +++ b/fs/sharefs/lookup.c @@ -295,7 +295,6 @@ struct dentry *sharefs_lookup(struct inode *dir, struct dentry *dentry, struct path lower_parent_path; #ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE const struct cred *saved_cred = NULL; - __u16 permission; #endif parent = dget_parent(dentry); err = sharefs_get_lower_path(parent, &lower_parent_path, 0); @@ -304,7 +303,7 @@ struct dentry *sharefs_lookup(struct inode *dir, struct dentry *dentry, return ERR_PTR(err); } #ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE - saved_cred = sharefs_override_file_fsids(dir, &permission); + saved_cred = sharefs_override_file_fsids(dir); if (!saved_cred) { ret = ERR_PTR(-ENOMEM); goto out_err;