|
35 | 35 | static struct vfsmount *debugfs_mount; |
36 | 36 | static int debugfs_mount_count; |
37 | 37 | static bool debugfs_registered; |
| 38 | +static unsigned int debugfs_allow = DEFAULT_DEBUGFS_ALLOW_BITS; |
38 | 39 |
|
39 | 40 | /* |
40 | 41 | * Don't allow access attributes to be changed whilst the kernel is locked down |
@@ -266,6 +267,9 @@ static struct dentry *debug_mount(struct file_system_type *fs_type, |
266 | 267 | int flags, const char *dev_name, |
267 | 268 | void *data) |
268 | 269 | { |
| 270 | + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) |
| 271 | + return ERR_PTR(-EPERM); |
| 272 | + |
269 | 273 | return mount_single(fs_type, flags, data, debug_fill_super); |
270 | 274 | } |
271 | 275 |
|
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) |
311 | 315 | struct dentry *dentry; |
312 | 316 | int error; |
313 | 317 |
|
| 318 | + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) |
| 319 | + return ERR_PTR(-EPERM); |
| 320 | + |
314 | 321 | pr_debug("creating file '%s'\n", name); |
315 | 322 |
|
316 | 323 | if (IS_ERR(parent)) |
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode, |
385 | 392 | if (IS_ERR(dentry)) |
386 | 393 | return dentry; |
387 | 394 |
|
| 395 | + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { |
| 396 | + failed_creating(dentry); |
| 397 | + return ERR_PTR(-EPERM); |
| 398 | + } |
| 399 | + |
388 | 400 | inode = debugfs_get_inode(dentry->d_sb); |
389 | 401 | if (unlikely(!inode)) { |
390 | 402 | pr_err("out of free dentries, can not create file '%s'\n", |
@@ -541,6 +553,11 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) |
541 | 553 | if (IS_ERR(dentry)) |
542 | 554 | return dentry; |
543 | 555 |
|
| 556 | + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { |
| 557 | + failed_creating(dentry); |
| 558 | + return ERR_PTR(-EPERM); |
| 559 | + } |
| 560 | + |
544 | 561 | inode = debugfs_get_inode(dentry->d_sb); |
545 | 562 | if (unlikely(!inode)) { |
546 | 563 | pr_err("out of free dentries, can not create directory '%s'\n", |
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name, |
583 | 600 | if (IS_ERR(dentry)) |
584 | 601 | return dentry; |
585 | 602 |
|
| 603 | + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) { |
| 604 | + failed_creating(dentry); |
| 605 | + return ERR_PTR(-EPERM); |
| 606 | + } |
| 607 | + |
586 | 608 | inode = debugfs_get_inode(dentry->d_sb); |
587 | 609 | if (unlikely(!inode)) { |
588 | 610 | pr_err("out of free dentries, can not create automount '%s'\n", |
@@ -786,10 +808,27 @@ bool debugfs_initialized(void) |
786 | 808 | } |
787 | 809 | EXPORT_SYMBOL_GPL(debugfs_initialized); |
788 | 810 |
|
| 811 | +static int __init debugfs_kernel(char *str) |
| 812 | +{ |
| 813 | + if (str) { |
| 814 | + if (!strcmp(str, "on")) |
| 815 | + debugfs_allow = DEBUGFS_ALLOW_API | DEBUGFS_ALLOW_MOUNT; |
| 816 | + else if (!strcmp(str, "no-mount")) |
| 817 | + debugfs_allow = DEBUGFS_ALLOW_API; |
| 818 | + else if (!strcmp(str, "off")) |
| 819 | + debugfs_allow = 0; |
| 820 | + } |
| 821 | + |
| 822 | + return 0; |
| 823 | +} |
| 824 | +early_param("debugfs", debugfs_kernel); |
789 | 825 | static int __init debugfs_init(void) |
790 | 826 | { |
791 | 827 | int retval; |
792 | 828 |
|
| 829 | + if (!(debugfs_allow & DEBUGFS_ALLOW_MOUNT)) |
| 830 | + return -EPERM; |
| 831 | + |
793 | 832 | retval = sysfs_create_mount_point(kernel_kobj, "debug"); |
794 | 833 | if (retval) |
795 | 834 | return retval; |
|
0 commit comments