Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 117486
b: refs/heads/master
c: f696a36
h: refs/heads/master
v: v3
  • Loading branch information
Miklos Szeredi authored and Al Viro committed Oct 23, 2008
1 parent 89e93a5 commit 0d5dcfb
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 45 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5cec56deb6d41b5b570306b17cd0b1590ebd0897
refs/heads/master: f696a3659fc4b3a3bf4bc83d9dbec5e5a2ffd929
9 changes: 6 additions & 3 deletions trunk/fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,12 @@ static int cifs_permission(struct inode *inode, int mask)

cifs_sb = CIFS_SB(inode->i_sb);

if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
return 0;
else /* file mode might have been restricted at mount time
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
if ((mask & MAY_EXEC) && !execute_ok(inode))
return -EACCES;
else
return 0;
} else /* file mode might have been restricted at mount time
on the client (above and beyond ACL on servers) for
servers which do not support setting and viewing mode bits,
so allowing client to check permissions is useful */
Expand Down
3 changes: 3 additions & 0 deletions trunk/fs/coda/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ int coda_permission(struct inode *inode, int mask)
if (!mask)
return 0;

if ((mask & MAY_EXEC) && !execute_ok(inode))
return -EACCES;

lock_kernel();

if (coda_cache_check(inode, mask))
Expand Down
2 changes: 1 addition & 1 deletion trunk/fs/coda/pioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const struct file_operations coda_ioctl_operations = {
/* the coda pioctl inode ops */
static int coda_ioctl_permission(struct inode *inode, int mask)
{
return 0;
return (mask & MAY_EXEC) ? -EACCES : 0;
}

static int coda_pioctl(struct inode * inode, struct file * filp,
Expand Down
8 changes: 0 additions & 8 deletions trunk/fs/hfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,6 @@ void hfs_clear_inode(struct inode *inode)
}
}

static int hfs_permission(struct inode *inode, int mask)
{
if (S_ISREG(inode->i_mode) && mask & MAY_EXEC)
return 0;
return generic_permission(inode, mask, NULL);
}

static int hfs_file_open(struct inode *inode, struct file *file)
{
if (HFS_IS_RSRC(inode))
Expand Down Expand Up @@ -616,7 +609,6 @@ static const struct inode_operations hfs_file_inode_operations = {
.lookup = hfs_file_lookup,
.truncate = hfs_file_truncate,
.setattr = hfs_inode_setattr,
.permission = hfs_permission,
.setxattr = hfs_setxattr,
.getxattr = hfs_getxattr,
.listxattr = hfs_listxattr,
Expand Down
13 changes: 0 additions & 13 deletions trunk/fs/hfsplus/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,6 @@ static void hfsplus_set_perms(struct inode *inode, struct hfsplus_perm *perms)
perms->dev = cpu_to_be32(HFSPLUS_I(inode).dev);
}

static int hfsplus_permission(struct inode *inode, int mask)
{
/* MAY_EXEC is also used for lookup, if no x bit is set allow lookup,
* open_exec has the same test, so it's still not executable, if a x bit
* is set fall back to standard permission check.
*/
if (S_ISREG(inode->i_mode) && mask & MAY_EXEC && !(inode->i_mode & 0111))
return 0;
return generic_permission(inode, mask, NULL);
}


static int hfsplus_file_open(struct inode *inode, struct file *file)
{
if (HFSPLUS_IS_RSRC(inode))
Expand Down Expand Up @@ -281,7 +269,6 @@ static int hfsplus_file_release(struct inode *inode, struct file *file)
static const struct inode_operations hfsplus_file_inode_operations = {
.lookup = hfsplus_file_lookup,
.truncate = hfsplus_file_truncate,
.permission = hfsplus_permission,
.setxattr = hfsplus_setxattr,
.getxattr = hfsplus_getxattr,
.listxattr = hfsplus_listxattr,
Expand Down
21 changes: 4 additions & 17 deletions trunk/fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ int generic_permission(struct inode *inode, int mask,
* Read/write DACs are always overridable.
* Executable DACs are overridable if at least one exec bit is set.
*/
if (!(mask & MAY_EXEC) ||
(inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
if (!(mask & MAY_EXEC) || execute_ok(inode))
if (capable(CAP_DAC_OVERRIDE))
return 0;

Expand Down Expand Up @@ -249,23 +248,11 @@ int inode_permission(struct inode *inode, int mask)
}

/* Ordinary permission routines do not understand MAY_APPEND. */
if (inode->i_op && inode->i_op->permission) {
if (inode->i_op && inode->i_op->permission)
retval = inode->i_op->permission(inode, mask);
if (!retval) {
/*
* Exec permission on a regular file is denied if none
* of the execute bits are set.
*
* This check should be done by the ->permission()
* method.
*/
if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode) &&
!(inode->i_mode & S_IXUGO))
return -EACCES;
}
} else {
else
retval = generic_permission(inode, mask, NULL);
}

if (retval)
return retval;

Expand Down
3 changes: 3 additions & 0 deletions trunk/fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,9 @@ int nfs_permission(struct inode *inode, int mask)
} else
res = PTR_ERR(cred);
out:
if (!res && (mask & MAY_EXEC) && !execute_ok(inode))
res = -EACCES;

dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n",
inode->i_sb->s_id, inode->i_ino, mask, res);
return res;
Expand Down
10 changes: 8 additions & 2 deletions trunk/fs/proc/proc_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,19 @@ static int proc_sys_permission(struct inode *inode, int mask)
* sysctl entries that are not writeable,
* are _NOT_ writeable, capabilities or not.
*/
struct ctl_table_header *head = grab_header(inode);
struct ctl_table *table = PROC_I(inode)->sysctl_entry;
struct ctl_table_header *head;
struct ctl_table *table;
int error;

/* Executable files are not allowed under /proc/sys/ */
if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))
return -EACCES;

head = grab_header(inode);
if (IS_ERR(head))
return PTR_ERR(head);

table = PROC_I(inode)->sysctl_entry;
if (!table) /* global root - r-xr-xr-x */
error = mask & MAY_WRITE ? -EACCES : 0;
else /* Use the permissions on the sysctl table entry */
Expand Down
5 changes: 5 additions & 0 deletions trunk/include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,11 @@ extern int inode_permission(struct inode *, int);
extern int generic_permission(struct inode *, int,
int (*check_acl)(struct inode *, int));

static inline bool execute_ok(struct inode *inode)
{
return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);
}

extern int get_write_access(struct inode *);
extern int deny_write_access(struct file *);
static inline void put_write_access(struct inode * inode)
Expand Down

0 comments on commit 0d5dcfb

Please sign in to comment.