Skip to contentSkip to conversation

devscgroup: check for device permissions at mount time

PATCH In review Pavel Emelyanov 2 participants 2 messages Jun 5, 2008 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 devscgroup: check for device permissions at mount time

Currently even if a task sits in an all-denied cgroup it can still mount any block device in any mode it wants.

Put a proper check in do_open for block device to prevent this.

---
 fs/block_dev.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
fs/block_dev.c +7 -1
index a0e9596..7e1c7a3 100644
@@ -24,6 +24,7 @@
 #include <linux/namei.h>
 #include <linux/log2.h>
 #include <linux/hardirq.h>
+#include <linux/device_cgroup.h>
 
 #include <asm/uaccess.h>
 #include "internal.h"
@@ -933,9 +934,14 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
 {
 	struct module *owner = NULL;
 	struct gendisk *disk;
-	int ret = -ENXIO;
+	int ret;
 	int part;
 
+	ret = devcgroup_inode_permission(bdev->bd_inode, file->f_mode);
+	if (ret != 0)
+		return ret;
+
+	ret = -ENXIO;
 	file->f_mapping = bdev->bd_inode->i_mapping;
 	lock_kernel();
 	disk = get_gendisk(bdev->bd_dev, &part);
Signature · 1 line
1.5.3.4
Acked-by Tested-by on v1 1/2
#1 lore raw
Quoted 6 lines · Pavel Emelyanov

Currently even if a task sits in an all-denied cgroup it can still mount any block device in any mode it wants.

Put a proper check in do_open for block device to prevent this.

Crud. Tested and confirmed, and this patches fixes it.

thanks,
-serge

Quoted 34 lines
---
 fs/block_dev.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
fs/block_dev.c +7 -1
index a0e9596..7e1c7a3 100644
@@ -24,6 +24,7 @@
 #include <linux/namei.h>
 #include <linux/log2.h>
 #include <linux/hardirq.h>
+#include <linux/device_cgroup.h>
 
 #include <asm/uaccess.h>
 #include "internal.h"
@@ -933,9 +934,14 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
 {
 	struct module *owner = NULL;
 	struct gendisk *disk;
-	int ret = -ENXIO;
+	int ret;
 	int part;
 
+	ret = devcgroup_inode_permission(bdev->bd_inode, file->f_mode);
+	if (ret != 0)
+		return ret;
+
+	ret = -ENXIO;
 	file->f_mapping = bdev->bd_inode->i_mapping;
 	lock_kernel();
 	disk = get_gendisk(bdev->bd_dev, &part);
Signature · 1 line
1.5.3.4