diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2009-09-18 17:01:12 -0400 |
---|---|---|
committer | Live-CD User <linux@linux.site> | 2009-09-19 15:50:38 -0400 |
commit | e454cea20bdcff10ee698d11b8882662a0153a47 (patch) | |
tree | f44581fe57787aef0a4f4dc00993a90ea8e688f6 /drivers/char | |
parent | 78f28b7c555359c67c2a0d23f7436e915329421e (diff) |
Driver-Core: extend devnode callbacks to provide permissions
This allows subsytems to provide devtmpfs with non-default permissions
for the device node. Instead of the default mode of 0600, null, zero,
random, urandom, full, tty, ptmx now have a mode of 0666, which allows
non-privileged processes to access standard device nodes in case no
other userspace process applies the expected permissions.
This also fixes a wrong assignment in pktcdvd and a checkpatch.pl complain.
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/hw_random/core.c | 2 | ||||
-rw-r--r-- | drivers/char/mem.c | 29 | ||||
-rw-r--r-- | drivers/char/misc.c | 10 | ||||
-rw-r--r-- | drivers/char/raw.c | 4 | ||||
-rw-r--r-- | drivers/char/tty_io.c | 11 |
5 files changed, 39 insertions, 17 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index fc93e2fc7c71..1573aebd54b5 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
@@ -153,7 +153,7 @@ static const struct file_operations rng_chrdev_ops = { | |||
153 | static struct miscdevice rng_miscdev = { | 153 | static struct miscdevice rng_miscdev = { |
154 | .minor = RNG_MISCDEV_MINOR, | 154 | .minor = RNG_MISCDEV_MINOR, |
155 | .name = RNG_MODULE_NAME, | 155 | .name = RNG_MODULE_NAME, |
156 | .devnode = "hwrng", | 156 | .nodename = "hwrng", |
157 | .fops = &rng_chrdev_ops, | 157 | .fops = &rng_chrdev_ops, |
158 | }; | 158 | }; |
159 | 159 | ||
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 0491cdf63f2a..0aede1d6a9ea 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
@@ -866,24 +866,25 @@ static const struct file_operations kmsg_fops = { | |||
866 | 866 | ||
867 | static const struct memdev { | 867 | static const struct memdev { |
868 | const char *name; | 868 | const char *name; |
869 | mode_t mode; | ||
869 | const struct file_operations *fops; | 870 | const struct file_operations *fops; |
870 | struct backing_dev_info *dev_info; | 871 | struct backing_dev_info *dev_info; |
871 | } devlist[] = { | 872 | } devlist[] = { |
872 | [ 1] = { "mem", &mem_fops, &directly_mappable_cdev_bdi }, | 873 | [1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi }, |
873 | #ifdef CONFIG_DEVKMEM | 874 | #ifdef CONFIG_DEVKMEM |
874 | [ 2] = { "kmem", &kmem_fops, &directly_mappable_cdev_bdi }, | 875 | [2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi }, |
875 | #endif | 876 | #endif |
876 | [ 3] = {"null", &null_fops, NULL }, | 877 | [3] = { "null", 0666, &null_fops, NULL }, |
877 | #ifdef CONFIG_DEVPORT | 878 | #ifdef CONFIG_DEVPORT |
878 | [ 4] = { "port", &port_fops, NULL }, | 879 | [4] = { "port", 0, &port_fops, NULL }, |
879 | #endif | 880 | #endif |
880 | [ 5] = { "zero", &zero_fops, &zero_bdi }, | 881 | [5] = { "zero", 0666, &zero_fops, &zero_bdi }, |
881 | [ 7] = { "full", &full_fops, NULL }, | 882 | [7] = { "full", 0666, &full_fops, NULL }, |
882 | [ 8] = { "random", &random_fops, NULL }, | 883 | [8] = { "random", 0666, &random_fops, NULL }, |
883 | [ 9] = { "urandom", &urandom_fops, NULL }, | 884 | [9] = { "urandom", 0666, &urandom_fops, NULL }, |
884 | [11] = { "kmsg", &kmsg_fops, NULL }, | 885 | [11] = { "kmsg", 0, &kmsg_fops, NULL }, |
885 | #ifdef CONFIG_CRASH_DUMP | 886 | #ifdef CONFIG_CRASH_DUMP |
886 | [12] = { "oldmem", &oldmem_fops, NULL }, | 887 | [12] = { "oldmem", 0, &oldmem_fops, NULL }, |
887 | #endif | 888 | #endif |
888 | }; | 889 | }; |
889 | 890 | ||
@@ -920,6 +921,13 @@ static const struct file_operations memory_fops = { | |||
920 | .open = memory_open, | 921 | .open = memory_open, |
921 | }; | 922 | }; |
922 | 923 | ||
924 | static char *mem_devnode(struct device *dev, mode_t *mode) | ||
925 | { | ||
926 | if (mode && devlist[MINOR(dev->devt)].mode) | ||
927 | *mode = devlist[MINOR(dev->devt)].mode; | ||
928 | return NULL; | ||
929 | } | ||
930 | |||
923 | static struct class *mem_class; | 931 | static struct class *mem_class; |
924 | 932 | ||
925 | static int __init chr_dev_init(void) | 933 | static int __init chr_dev_init(void) |
@@ -935,6 +943,7 @@ static int __init chr_dev_init(void) | |||
935 | printk("unable to get major %d for memory devs\n", MEM_MAJOR); | 943 | printk("unable to get major %d for memory devs\n", MEM_MAJOR); |
936 | 944 | ||
937 | mem_class = class_create(THIS_MODULE, "mem"); | 945 | mem_class = class_create(THIS_MODULE, "mem"); |
946 | mem_class->devnode = mem_devnode; | ||
938 | for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { | 947 | for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { |
939 | if (!devlist[minor].name) | 948 | if (!devlist[minor].name) |
940 | continue; | 949 | continue; |
diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 62c99fa59e2b..1ee27cc23426 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c | |||
@@ -263,12 +263,14 @@ int misc_deregister(struct miscdevice *misc) | |||
263 | EXPORT_SYMBOL(misc_register); | 263 | EXPORT_SYMBOL(misc_register); |
264 | EXPORT_SYMBOL(misc_deregister); | 264 | EXPORT_SYMBOL(misc_deregister); |
265 | 265 | ||
266 | static char *misc_nodename(struct device *dev) | 266 | static char *misc_devnode(struct device *dev, mode_t *mode) |
267 | { | 267 | { |
268 | struct miscdevice *c = dev_get_drvdata(dev); | 268 | struct miscdevice *c = dev_get_drvdata(dev); |
269 | 269 | ||
270 | if (c->devnode) | 270 | if (mode && c->mode) |
271 | return kstrdup(c->devnode, GFP_KERNEL); | 271 | *mode = c->mode; |
272 | if (c->nodename) | ||
273 | return kstrdup(c->nodename, GFP_KERNEL); | ||
272 | return NULL; | 274 | return NULL; |
273 | } | 275 | } |
274 | 276 | ||
@@ -287,7 +289,7 @@ static int __init misc_init(void) | |||
287 | err = -EIO; | 289 | err = -EIO; |
288 | if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) | 290 | if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) |
289 | goto fail_printk; | 291 | goto fail_printk; |
290 | misc_class->nodename = misc_nodename; | 292 | misc_class->devnode = misc_devnode; |
291 | return 0; | 293 | return 0; |
292 | 294 | ||
293 | fail_printk: | 295 | fail_printk: |
diff --git a/drivers/char/raw.c b/drivers/char/raw.c index 40268db02e22..64acd05f71c8 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c | |||
@@ -261,7 +261,7 @@ static const struct file_operations raw_ctl_fops = { | |||
261 | 261 | ||
262 | static struct cdev raw_cdev; | 262 | static struct cdev raw_cdev; |
263 | 263 | ||
264 | static char *raw_nodename(struct device *dev) | 264 | static char *raw_devnode(struct device *dev, mode_t *mode) |
265 | { | 265 | { |
266 | return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev)); | 266 | return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev)); |
267 | } | 267 | } |
@@ -289,7 +289,7 @@ static int __init raw_init(void) | |||
289 | ret = PTR_ERR(raw_class); | 289 | ret = PTR_ERR(raw_class); |
290 | goto error_region; | 290 | goto error_region; |
291 | } | 291 | } |
292 | raw_class->nodename = raw_nodename; | 292 | raw_class->devnode = raw_devnode; |
293 | device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); | 293 | device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); |
294 | 294 | ||
295 | return 0; | 295 | return 0; |
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index a3afa0c387cd..c70d9dabefae 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -3056,11 +3056,22 @@ void __init console_init(void) | |||
3056 | } | 3056 | } |
3057 | } | 3057 | } |
3058 | 3058 | ||
3059 | static char *tty_devnode(struct device *dev, mode_t *mode) | ||
3060 | { | ||
3061 | if (!mode) | ||
3062 | return NULL; | ||
3063 | if (dev->devt == MKDEV(TTYAUX_MAJOR, 0) || | ||
3064 | dev->devt == MKDEV(TTYAUX_MAJOR, 2)) | ||
3065 | *mode = 0666; | ||
3066 | return NULL; | ||
3067 | } | ||
3068 | |||
3059 | static int __init tty_class_init(void) | 3069 | static int __init tty_class_init(void) |
3060 | { | 3070 | { |
3061 | tty_class = class_create(THIS_MODULE, "tty"); | 3071 | tty_class = class_create(THIS_MODULE, "tty"); |
3062 | if (IS_ERR(tty_class)) | 3072 | if (IS_ERR(tty_class)) |
3063 | return PTR_ERR(tty_class); | 3073 | return PTR_ERR(tty_class); |
3074 | tty_class->devnode = tty_devnode; | ||
3064 | return 0; | 3075 | return 0; |
3065 | } | 3076 | } |
3066 | 3077 | ||