Collect "operation mode" arguments of do_last() into a structure
No point messing with passing shitloads of "operation mode" arguments to do_open() one by one, especially since they are not going to change during do_filp_open(). Collect them into a struct, fill it and pass to do_last() by reference. Make sure that lookup intent flags are correctly set and removed - we want them for do_last(), but they make no sense for __do_follow_link(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
57
fs/namei.c
57
fs/namei.c
@@ -2169,17 +2169,26 @@ exit:
|
|||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct open_flags {
|
||||||
|
int open_flag;
|
||||||
|
int mode;
|
||||||
|
int acc_mode;
|
||||||
|
int intent;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle O_CREAT case for do_filp_open
|
* Handle O_CREAT case for do_filp_open
|
||||||
*/
|
*/
|
||||||
static struct file *do_last(struct nameidata *nd, struct path *path,
|
static struct file *do_last(struct nameidata *nd, struct path *path,
|
||||||
int open_flag, int acc_mode,
|
const struct open_flags *op, const char *pathname)
|
||||||
int mode, const char *pathname)
|
|
||||||
{
|
{
|
||||||
struct dentry *dir = nd->path.dentry;
|
struct dentry *dir = nd->path.dentry;
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
nd->flags &= ~LOOKUP_PARENT;
|
||||||
|
nd->flags |= op->intent;
|
||||||
|
|
||||||
switch (nd->last_type) {
|
switch (nd->last_type) {
|
||||||
case LAST_DOTDOT:
|
case LAST_DOTDOT:
|
||||||
follow_dotdot(nd);
|
follow_dotdot(nd);
|
||||||
@@ -2233,7 +2242,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
|
|||||||
error = mnt_want_write(nd->path.mnt);
|
error = mnt_want_write(nd->path.mnt);
|
||||||
if (error)
|
if (error)
|
||||||
goto exit_mutex_unlock;
|
goto exit_mutex_unlock;
|
||||||
error = __open_namei_create(nd, path, open_flag, mode);
|
error = __open_namei_create(nd, path, op->open_flag, op->mode);
|
||||||
if (error) {
|
if (error) {
|
||||||
mnt_drop_write(nd->path.mnt);
|
mnt_drop_write(nd->path.mnt);
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -2242,7 +2251,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
|
|||||||
mnt_drop_write(nd->path.mnt);
|
mnt_drop_write(nd->path.mnt);
|
||||||
path_put(&nd->path);
|
path_put(&nd->path);
|
||||||
if (!IS_ERR(filp)) {
|
if (!IS_ERR(filp)) {
|
||||||
error = ima_file_check(filp, acc_mode);
|
error = ima_file_check(filp, op->acc_mode);
|
||||||
if (error) {
|
if (error) {
|
||||||
fput(filp);
|
fput(filp);
|
||||||
filp = ERR_PTR(error);
|
filp = ERR_PTR(error);
|
||||||
@@ -2258,7 +2267,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
|
|||||||
audit_inode(pathname, path->dentry);
|
audit_inode(pathname, path->dentry);
|
||||||
|
|
||||||
error = -EEXIST;
|
error = -EEXIST;
|
||||||
if (open_flag & O_EXCL)
|
if (op->open_flag & O_EXCL)
|
||||||
goto exit_dput;
|
goto exit_dput;
|
||||||
|
|
||||||
error = follow_managed(path, nd->flags);
|
error = follow_managed(path, nd->flags);
|
||||||
@@ -2278,7 +2287,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
|
|||||||
if (S_ISDIR(nd->inode->i_mode))
|
if (S_ISDIR(nd->inode->i_mode))
|
||||||
goto exit;
|
goto exit;
|
||||||
ok:
|
ok:
|
||||||
filp = finish_open(nd, open_flag, acc_mode);
|
filp = finish_open(nd, op->open_flag, op->acc_mode);
|
||||||
return filp;
|
return filp;
|
||||||
|
|
||||||
exit_mutex_unlock:
|
exit_mutex_unlock:
|
||||||
@@ -2304,7 +2313,8 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||||||
struct path path;
|
struct path path;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int flag = open_to_namei_flags(open_flag);
|
int flag = open_to_namei_flags(open_flag);
|
||||||
int flags;
|
int flags = 0;
|
||||||
|
struct open_flags op;
|
||||||
|
|
||||||
if (!(open_flag & O_CREAT))
|
if (!(open_flag & O_CREAT))
|
||||||
mode = 0;
|
mode = 0;
|
||||||
@@ -2321,6 +2331,8 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||||||
if (open_flag & __O_SYNC)
|
if (open_flag & __O_SYNC)
|
||||||
open_flag |= O_DSYNC;
|
open_flag |= O_DSYNC;
|
||||||
|
|
||||||
|
op.open_flag = open_flag;
|
||||||
|
|
||||||
if (!acc_mode)
|
if (!acc_mode)
|
||||||
acc_mode = MAY_OPEN | ACC_MODE(open_flag);
|
acc_mode = MAY_OPEN | ACC_MODE(open_flag);
|
||||||
|
|
||||||
@@ -2333,12 +2345,15 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||||||
if (open_flag & O_APPEND)
|
if (open_flag & O_APPEND)
|
||||||
acc_mode |= MAY_APPEND;
|
acc_mode |= MAY_APPEND;
|
||||||
|
|
||||||
flags = LOOKUP_OPEN;
|
op.acc_mode = acc_mode;
|
||||||
|
|
||||||
|
op.intent = LOOKUP_OPEN;
|
||||||
if (open_flag & O_CREAT) {
|
if (open_flag & O_CREAT) {
|
||||||
flags |= LOOKUP_CREATE;
|
op.intent |= LOOKUP_CREATE;
|
||||||
if (open_flag & O_EXCL)
|
if (open_flag & O_EXCL)
|
||||||
flags |= LOOKUP_EXCL;
|
op.intent |= LOOKUP_EXCL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open_flag & O_DIRECTORY)
|
if (open_flag & O_DIRECTORY)
|
||||||
flags |= LOOKUP_DIRECTORY;
|
flags |= LOOKUP_DIRECTORY;
|
||||||
if (!(open_flag & O_NOFOLLOW))
|
if (!(open_flag & O_NOFOLLOW))
|
||||||
@@ -2357,7 +2372,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
|
|||||||
goto creat;
|
goto creat;
|
||||||
|
|
||||||
/* !O_CREAT, simple open */
|
/* !O_CREAT, simple open */
|
||||||
error = do_path_lookup(dfd, pathname, flags, &nd);
|
error = do_path_lookup(dfd, pathname, flags | op.intent, &nd);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
goto out_filp2;
|
goto out_filp2;
|
||||||
error = -ELOOP;
|
error = -ELOOP;
|
||||||
@@ -2384,14 +2399,14 @@ out_filp2:
|
|||||||
|
|
||||||
creat:
|
creat:
|
||||||
/* OK, have to create the file. Find the parent. */
|
/* OK, have to create the file. Find the parent. */
|
||||||
error = path_lookupat(dfd, pathname, LOOKUP_PARENT | LOOKUP_RCU, &nd);
|
error = path_lookupat(dfd, pathname,
|
||||||
|
LOOKUP_PARENT | LOOKUP_RCU | flags, &nd);
|
||||||
if (unlikely(error == -ECHILD))
|
if (unlikely(error == -ECHILD))
|
||||||
error = path_lookupat(dfd, pathname, LOOKUP_PARENT, &nd);
|
error = path_lookupat(dfd, pathname, LOOKUP_PARENT | flags, &nd);
|
||||||
if (unlikely(error == -ESTALE)) {
|
if (unlikely(error == -ESTALE)) {
|
||||||
reval:
|
reval:
|
||||||
flags |= LOOKUP_REVAL;
|
flags |= LOOKUP_REVAL;
|
||||||
error = path_lookupat(dfd, pathname,
|
error = path_lookupat(dfd, pathname, LOOKUP_PARENT | flags, &nd);
|
||||||
LOOKUP_PARENT | LOOKUP_REVAL, &nd);
|
|
||||||
}
|
}
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
goto out_filp;
|
goto out_filp;
|
||||||
@@ -2401,8 +2416,7 @@ reval:
|
|||||||
/*
|
/*
|
||||||
* We have the parent and last component.
|
* We have the parent and last component.
|
||||||
*/
|
*/
|
||||||
nd.flags = (nd.flags & ~LOOKUP_PARENT) | flags;
|
filp = do_last(&nd, &path, &op, pathname);
|
||||||
filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
|
|
||||||
while (unlikely(!filp)) { /* trailing symlink */
|
while (unlikely(!filp)) { /* trailing symlink */
|
||||||
struct path link = path;
|
struct path link = path;
|
||||||
struct inode *linki = link.dentry->d_inode;
|
struct inode *linki = link.dentry->d_inode;
|
||||||
@@ -2424,13 +2438,12 @@ reval:
|
|||||||
* just set LAST_BIND.
|
* just set LAST_BIND.
|
||||||
*/
|
*/
|
||||||
nd.flags |= LOOKUP_PARENT;
|
nd.flags |= LOOKUP_PARENT;
|
||||||
|
nd.flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
|
||||||
error = __do_follow_link(&link, &nd, &cookie);
|
error = __do_follow_link(&link, &nd, &cookie);
|
||||||
if (unlikely(error)) {
|
if (unlikely(error))
|
||||||
filp = ERR_PTR(error);
|
filp = ERR_PTR(error);
|
||||||
} else {
|
else
|
||||||
nd.flags &= ~LOOKUP_PARENT;
|
filp = do_last(&nd, &path, &op, pathname);
|
||||||
filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
|
|
||||||
}
|
|
||||||
if (!IS_ERR(cookie) && linki->i_op->put_link)
|
if (!IS_ERR(cookie) && linki->i_op->put_link)
|
||||||
linki->i_op->put_link(link.dentry, &nd, cookie);
|
linki->i_op->put_link(link.dentry, &nd, cookie);
|
||||||
path_put(&link);
|
path_put(&link);
|
||||||
|
Reference in New Issue
Block a user