Skip to content

Commit

Permalink
Fix f_flags/f_mode in case of lookup_instantiate_filp() from open(pat…
Browse files Browse the repository at this point in the history
…hname, 3)

Just set f_flags when shoving struct file into nameidata; don't
postpone that until __dentry_open().  do_filp_open() has correct
value; lookup_instantiate_filp() doesn't - we lose the difference
between O_RDWR and 3 by that point.

We still set .intent.open.flags, so no fs code needs to be changed.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Dec 22, 2009
1 parent 628ff7c commit 482928d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
7 changes: 7 additions & 0 deletions fs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ extern struct file *get_empty_filp(void);
* super.c
*/
extern int do_remount_sb(struct super_block *, int, void *, int);

/*
* open.c
*/
struct nameidata;
extern struct file *nameidata_to_filp(struct nameidata *);
extern void release_open_intent(struct nameidata *);
6 changes: 4 additions & 2 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
if (filp == NULL)
return ERR_PTR(-ENFILE);
nd.intent.open.file = filp;
filp->f_flags = open_flag;
nd.intent.open.flags = flag;
nd.intent.open.create_mode = 0;
error = do_path_lookup(dfd, pathname,
Expand Down Expand Up @@ -1685,6 +1686,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
if (filp == NULL)
goto exit_parent;
nd.intent.open.file = filp;
filp->f_flags = open_flag;
nd.intent.open.flags = flag;
nd.intent.open.create_mode = mode;
dir = nd.path.dentry;
Expand Down Expand Up @@ -1725,7 +1727,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
mnt_drop_write(nd.path.mnt);
goto exit;
}
filp = nameidata_to_filp(&nd, open_flag);
filp = nameidata_to_filp(&nd);
mnt_drop_write(nd.path.mnt);
if (nd.root.mnt)
path_put(&nd.root);
Expand Down Expand Up @@ -1789,7 +1791,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
mnt_drop_write(nd.path.mnt);
goto exit;
}
filp = nameidata_to_filp(&nd, open_flag);
filp = nameidata_to_filp(&nd);
if (!IS_ERR(filp)) {
error = ima_path_check(&filp->f_path, filp->f_mode &
(MAY_READ | MAY_WRITE | MAY_EXEC));
Expand Down
13 changes: 6 additions & 7 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,15 +821,14 @@ static inline int __get_file_write_access(struct inode *inode,
}

static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
int flags, struct file *f,
struct file *f,
int (*open)(struct inode *, struct file *),
const struct cred *cred)
{
struct inode *inode;
int error;

f->f_flags = flags;
f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK |
f->f_mode = (__force fmode_t)((f->f_flags+1) & O_ACCMODE) | FMODE_LSEEK |
FMODE_PREAD | FMODE_PWRITE;
inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
Expand Down Expand Up @@ -930,7 +929,6 @@ struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry
if (IS_ERR(dentry))
goto out_err;
nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt),
nd->intent.open.flags - 1,
nd->intent.open.file,
open, cred);
out:
Expand All @@ -949,7 +947,7 @@ EXPORT_SYMBOL_GPL(lookup_instantiate_filp);
*
* Note that this function destroys the original nameidata
*/
struct file *nameidata_to_filp(struct nameidata *nd, int flags)
struct file *nameidata_to_filp(struct nameidata *nd)
{
const struct cred *cred = current_cred();
struct file *filp;
Expand All @@ -958,7 +956,7 @@ struct file *nameidata_to_filp(struct nameidata *nd, int flags)
filp = nd->intent.open.file;
/* Has the filesystem initialised the file for us? */
if (filp->f_path.dentry == NULL)
filp = __dentry_open(nd->path.dentry, nd->path.mnt, flags, filp,
filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp,
NULL, cred);
else
path_put(&nd->path);
Expand Down Expand Up @@ -997,7 +995,8 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
return ERR_PTR(error);
}

return __dentry_open(dentry, mnt, flags, f, NULL, cred);
f->f_flags = flags;
return __dentry_open(dentry, mnt, f, NULL, cred);
}
EXPORT_SYMBOL(dentry_open);

Expand Down
2 changes: 0 additions & 2 deletions include/linux/namei.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,

extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
int (*open)(struct inode *, struct file *));
extern struct file *nameidata_to_filp(struct nameidata *nd, int flags);
extern void release_open_intent(struct nameidata *);

extern struct dentry *lookup_one_len(const char *, struct dentry *, int);

Expand Down

0 comments on commit 482928d

Please sign in to comment.