Skip to content

Commit f58ba88

Browse files
szmiswhiteho
authored andcommitted
[GFS2] don't call permission()
GFS2 calls permission() to verify permissions after locks on the files have been taken. For this it's sufficient to call gfs2_permission() instead. This results in the following changes: - IS_RDONLY() check is not performed - IS_IMMUTABLE() check is not performed - devcgroup_inode_permission() is not called - security_inode_permission() is not called IS_RDONLY() should be unnecessary anyway, as the per-mount read-only flag should provide protection against read-only remounts during operations. do_gfs2_set_flags() has been fixed to perform mnt_want_write()/mnt_drop_write() to protect against remounting read-only. IS_IMMUTABLE has been added to gfs2_permission() Repeating the security checks seems to be pointless, as they don't normally change, and if they do, it's independent of the filesystem state. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent f17172e commit f58ba88

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

‎fs/gfs2/inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
504504
}
505505

506506
if (!is_root) {
507-
error = permission(dir, MAY_EXEC, NULL);
507+
error = gfs2_permission(dir, MAY_EXEC);
508508
if (error)
509509
goto out;
510510
}
@@ -667,7 +667,7 @@ static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
667667
{
668668
int error;
669669

670-
error = permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL);
670+
error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
671671
if (error)
672672
return error;
673673

@@ -1134,7 +1134,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
11341134
if (IS_APPEND(&dip->i_inode))
11351135
return -EPERM;
11361136

1137-
error = permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, NULL);
1137+
error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
11381138
if (error)
11391139
return error;
11401140

‎fs/gfs2/inode.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
9191
struct gfs2_inode *ip);
9292
int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
9393
const struct gfs2_inode *ip);
94+
int gfs2_permission(struct inode *inode, int mask);
9495
int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to);
9596
int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len);
9697
int gfs2_glock_nq_atime(struct gfs2_holder *gh);

‎fs/gfs2/ops_file.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/uio.h>
1616
#include <linux/blkdev.h>
1717
#include <linux/mm.h>
18+
#include <linux/mount.h>
1819
#include <linux/fs.h>
1920
#include <linux/gfs2_ondisk.h>
2021
#include <linux/ext2_fs.h>
@@ -220,10 +221,14 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
220221
int error;
221222
u32 new_flags, flags;
222223

223-
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
224+
error = mnt_want_write(filp->f_path.mnt);
224225
if (error)
225226
return error;
226227

228+
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
229+
if (error)
230+
goto out_drop_write;
231+
227232
flags = ip->i_di.di_flags;
228233
new_flags = (flags & ~mask) | (reqflags & mask);
229234
if ((new_flags ^ flags) == 0)
@@ -242,7 +247,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
242247
!capable(CAP_LINUX_IMMUTABLE))
243248
goto out;
244249
if (!IS_IMMUTABLE(inode)) {
245-
error = permission(inode, MAY_WRITE, NULL);
250+
error = gfs2_permission(inode, MAY_WRITE);
246251
if (error)
247252
goto out;
248253
}
@@ -272,6 +277,8 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
272277
gfs2_trans_end(sdp);
273278
out:
274279
gfs2_glock_dq_uninit(&gh);
280+
out_drop_write:
281+
mnt_drop_write(filp->f_path.mnt);
275282
return error;
276283
}
277284

‎fs/gfs2/ops_inode.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
163163
if (error)
164164
goto out;
165165

166-
error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
166+
error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC);
167167
if (error)
168168
goto out_gunlock;
169169

@@ -669,7 +669,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
669669
}
670670
}
671671
} else {
672-
error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
672+
error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC);
673673
if (error)
674674
goto out_gunlock;
675675

@@ -704,7 +704,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
704704
/* Check out the dir to be renamed */
705705

706706
if (dir_rename) {
707-
error = permission(odentry->d_inode, MAY_WRITE, NULL);
707+
error = gfs2_permission(odentry->d_inode, MAY_WRITE);
708708
if (error)
709709
goto out_gunlock;
710710
}
@@ -891,7 +891,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
891891
* Returns: errno
892892
*/
893893

894-
static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
894+
int gfs2_permission(struct inode *inode, int mask)
895895
{
896896
struct gfs2_inode *ip = GFS2_I(inode);
897897
struct gfs2_holder i_gh;
@@ -905,13 +905,22 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
905905
unlock = 1;
906906
}
907907

908-
error = generic_permission(inode, mask, gfs2_check_acl);
908+
if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
909+
error = -EACCES;
910+
else
911+
error = generic_permission(inode, mask, gfs2_check_acl);
909912
if (unlock)
910913
gfs2_glock_dq_uninit(&i_gh);
911914

912915
return error;
913916
}
914917

918+
static int gfs2_iop_permission(struct inode *inode, int mask,
919+
struct nameidata *nd)
920+
{
921+
return gfs2_permission(inode, mask);
922+
}
923+
915924
static int setattr_size(struct inode *inode, struct iattr *attr)
916925
{
917926
struct gfs2_inode *ip = GFS2_I(inode);
@@ -1141,7 +1150,7 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name)
11411150
}
11421151

11431152
const struct inode_operations gfs2_file_iops = {
1144-
.permission = gfs2_permission,
1153+
.permission = gfs2_iop_permission,
11451154
.setattr = gfs2_setattr,
11461155
.getattr = gfs2_getattr,
11471156
.setxattr = gfs2_setxattr,
@@ -1160,7 +1169,7 @@ const struct inode_operations gfs2_dir_iops = {
11601169
.rmdir = gfs2_rmdir,
11611170
.mknod = gfs2_mknod,
11621171
.rename = gfs2_rename,
1163-
.permission = gfs2_permission,
1172+
.permission = gfs2_iop_permission,
11641173
.setattr = gfs2_setattr,
11651174
.getattr = gfs2_getattr,
11661175
.setxattr = gfs2_setxattr,
@@ -1172,7 +1181,7 @@ const struct inode_operations gfs2_dir_iops = {
11721181
const struct inode_operations gfs2_symlink_iops = {
11731182
.readlink = gfs2_readlink,
11741183
.follow_link = gfs2_follow_link,
1175-
.permission = gfs2_permission,
1184+
.permission = gfs2_iop_permission,
11761185
.setattr = gfs2_setattr,
11771186
.getattr = gfs2_getattr,
11781187
.setxattr = gfs2_setxattr,

0 commit comments

Comments
 (0)