diff options
-rw-r--r-- | fs/kernfs/file.c | 17 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 3 | ||||
-rw-r--r-- | include/linux/kernfs.h | 19 |
3 files changed, 30 insertions, 9 deletions
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index e01ea4a14a01..5e9a80cfc3d8 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c | |||
@@ -610,6 +610,7 @@ static void kernfs_put_open_node(struct kernfs_node *kn, | |||
610 | static int kernfs_fop_open(struct inode *inode, struct file *file) | 610 | static int kernfs_fop_open(struct inode *inode, struct file *file) |
611 | { | 611 | { |
612 | struct kernfs_node *kn = file->f_path.dentry->d_fsdata; | 612 | struct kernfs_node *kn = file->f_path.dentry->d_fsdata; |
613 | struct kernfs_root *root = kernfs_root(kn); | ||
613 | const struct kernfs_ops *ops; | 614 | const struct kernfs_ops *ops; |
614 | struct kernfs_open_file *of; | 615 | struct kernfs_open_file *of; |
615 | bool has_read, has_write, has_mmap; | 616 | bool has_read, has_write, has_mmap; |
@@ -624,14 +625,16 @@ static int kernfs_fop_open(struct inode *inode, struct file *file) | |||
624 | has_write = ops->write || ops->mmap; | 625 | has_write = ops->write || ops->mmap; |
625 | has_mmap = ops->mmap; | 626 | has_mmap = ops->mmap; |
626 | 627 | ||
627 | /* check perms and supported operations */ | 628 | /* see the flag definition for details */ |
628 | if ((file->f_mode & FMODE_WRITE) && | 629 | if (root->flags & KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK) { |
629 | (!(inode->i_mode & S_IWUGO) || !has_write)) | 630 | if ((file->f_mode & FMODE_WRITE) && |
630 | goto err_out; | 631 | (!(inode->i_mode & S_IWUGO) || !has_write)) |
632 | goto err_out; | ||
631 | 633 | ||
632 | if ((file->f_mode & FMODE_READ) && | 634 | if ((file->f_mode & FMODE_READ) && |
633 | (!(inode->i_mode & S_IRUGO) || !has_read)) | 635 | (!(inode->i_mode & S_IRUGO) || !has_read)) |
634 | goto err_out; | 636 | goto err_out; |
637 | } | ||
635 | 638 | ||
636 | /* allocate a kernfs_open_file for the file */ | 639 | /* allocate a kernfs_open_file for the file */ |
637 | error = -ENOMEM; | 640 | error = -ENOMEM; |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index a66ad6196f59..8794423f7efb 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -63,7 +63,8 @@ int __init sysfs_init(void) | |||
63 | { | 63 | { |
64 | int err; | 64 | int err; |
65 | 65 | ||
66 | sysfs_root = kernfs_create_root(NULL, 0, NULL); | 66 | sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK, |
67 | NULL); | ||
67 | if (IS_ERR(sysfs_root)) | 68 | if (IS_ERR(sysfs_root)) |
68 | return PTR_ERR(sysfs_root); | 69 | return PTR_ERR(sysfs_root); |
69 | 70 | ||
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index b0122dc6f96a..ca1be5c9136c 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h | |||
@@ -50,7 +50,24 @@ enum kernfs_node_flag { | |||
50 | 50 | ||
51 | /* @flags for kernfs_create_root() */ | 51 | /* @flags for kernfs_create_root() */ |
52 | enum kernfs_root_flag { | 52 | enum kernfs_root_flag { |
53 | KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001, | 53 | /* |
54 | * kernfs_nodes are created in the deactivated state and invisible. | ||
55 | * They require explicit kernfs_activate() to become visible. This | ||
56 | * can be used to make related nodes become visible atomically | ||
57 | * after all nodes are created successfully. | ||
58 | */ | ||
59 | KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001, | ||
60 | |||
61 | /* | ||
62 | * For regular flies, if the opener has CAP_DAC_OVERRIDE, open(2) | ||
63 | * succeeds regardless of the RW permissions. sysfs had an extra | ||
64 | * layer of enforcement where open(2) fails with -EACCES regardless | ||
65 | * of CAP_DAC_OVERRIDE if the permission doesn't have the | ||
66 | * respective read or write access at all (none of S_IRUGO or | ||
67 | * S_IWUGO) or the respective operation isn't implemented. The | ||
68 | * following flag enables that behavior. | ||
69 | */ | ||
70 | KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002, | ||
54 | }; | 71 | }; |
55 | 72 | ||
56 | /* type-specific structures for kernfs_node union members */ | 73 | /* type-specific structures for kernfs_node union members */ |