Skip to content

Commit

Permalink
Sanitize f_flags helpers
Browse files Browse the repository at this point in the history
* pull ACC_MODE to fs.h; we have several copies all over the place
* nightmarish expression calculating f_mode by f_flags deserves a helper
too (OPEN_FMODE(flags))

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Dec 22, 2009
1 parent 482928d commit 5300990
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 14 deletions.
10 changes: 1 addition & 9 deletions fs/anon_inodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ struct file *anon_inode_getfile(const char *name,
struct qstr this;
struct path path;
struct file *file;
fmode_t mode;
int error;

if (IS_ERR(anon_inode_inode))
return ERR_PTR(-ENODEV);

switch (flags & O_ACCMODE) {
case O_RDONLY: mode = FMODE_READ; break;
case O_WRONLY: mode = FMODE_WRITE; break;
case O_RDWR: mode = FMODE_READ | FMODE_WRITE; break;
default: return ERR_PTR(-EINVAL);
}

if (fops->owner && !try_module_get(fops->owner))
return ERR_PTR(-ENOENT);

Expand Down Expand Up @@ -129,7 +121,7 @@ struct file *anon_inode_getfile(const char *name,
d_instantiate(path.dentry, anon_inode_inode);

error = -ENFILE;
file = alloc_file(&path, mode, fops);
file = alloc_file(&path, OPEN_FMODE(flags), fops);
if (!file)
goto err_dput;
file->f_mapping = anon_inode_inode->i_mapping;
Expand Down
2 changes: 0 additions & 2 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

#include "internal.h"

#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])

/* [Feb-1997 T. Schoebel-Theuer]
* Fundamental changes in the pathname lookup mechanisms (namei)
* were necessary because of omirr. The reason is that omirr needs
Expand Down
2 changes: 1 addition & 1 deletion fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
struct inode *inode;
int error;

f->f_mode = (__force fmode_t)((f->f_flags+1) & O_ACCMODE) | FMODE_LSEEK |
f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
FMODE_PREAD | FMODE_PWRITE;
inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
Expand Down
3 changes: 3 additions & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2464,5 +2464,8 @@ int proc_nr_files(struct ctl_table *table, int write,

int __init get_filesystem_list(char *buf);

#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
#define OPEN_FMODE(flag) ((__force fmode_t)((flag + 1) & O_ACCMODE))

#endif /* __KERNEL__ */
#endif /* _LINUX_FS_H */
1 change: 0 additions & 1 deletion kernel/auditsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ struct audit_context {
#endif
};

#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
static inline int open_arg(int flags, int mask)
{
int n = ACC_MODE(flags);
Expand Down
1 change: 0 additions & 1 deletion security/tomoyo/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "common.h"
#include "tomoyo.h"
#include "realpath.h"
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])

/*
* tomoyo_globally_readable_file_entry is a structure which is used for holding
Expand Down

0 comments on commit 5300990

Please sign in to comment.