debugfs: Add mount restriction option
Subsystems (2)
PATCH 1/1 debugfs: Add mount restriction option
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)
fs/debugfs/inode.c +16 -1
@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +} +early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
lib/Kconfig.debug +10 -0
@@ -443,6 +443,16 @@ config DEBUG_FS If unsure, say N. +config DEBUG_FS_MOUNT_RESTRICTED + bool "Debug Filesystem mount restricted" + depends on DEBUG_FS + help + This is an additional restriction for mounting debugfs. It allows + the kernel to have debugfs compiled, but requires that kernel command + line has a debugfs parameter to register as a filesystem. + + If unsure, say N. + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.26.2
Greg Kroah-Hartman
maintainerQuoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 6 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)
No documentation update? That's not good :(
Quoted 18 lines
fs/debugfs/inode.c +10
-0@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +}
fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 10 lines
fs/debugfs/inode.c +6
-1+early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif
But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to simple_pin_fs() in start_creating() in fs/debugfs/inode.c?
Quoted 10 lines
fs/debugfs/inode.c +0
-0retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;lib/Kconfig.debug +0
-0@@ -443,6 +443,16 @@ config DEBUG_FS If unsure, say N.
lib/Kconfig.debug config DEBUG_FS · line 454
Quoted 10 lines
lib/Kconfig.debug +9
-0+config DEBUG_FS_MOUNT_RESTRICTED + bool "Debug Filesystem mount restricted" + depends on DEBUG_FS + help + This is an additional restriction for mounting debugfs. It allows + the kernel to have debugfs compiled, but requires that kernel command + line has a debugfs parameter to register as a filesystem. + + If unsure, say N.
No hint as to what the command line option is? And again, it's not a restriction for mounting it, you are preventing it from initializing entirely.
Which, as I have found out over time, can had side affects for codepaths that try to check the return value of debugfs calls, and if they fail to succeed, abort the whole driver/subsystem/whatever initializaion path, which is not what I think you want to do here at all.
thanks,
greg k-h
Quoted 46 lines · Greg Kroah-Hartman
Quoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 5 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)No documentation update? That's not good :(
Quoted 24 lines
fs/debugfs/inode.c +12
-1@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +} +early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; -
Quoted 9 lines
fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 4 lines
fs/debugfs/inode.c +4
-0+#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to
simple_pin_fs()instart_creating()infs/debugfs/inode.c?
If it does, the lines below is also cause the same problem.
Quoted 33 lines
Quoted 11 lines
fs/debugfs/inode.c +0
-0retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;lib/Kconfig.debug +0
-0@@ -443,6 +443,16 @@ config DEBUG_FS If unsure, say N.lib/Kconfig.debug config DEBUG_FS · line 454
Quoted 10 lines
lib/Kconfig.debug +9
-0+config DEBUG_FS_MOUNT_RESTRICTED + bool "Debug Filesystem mount restricted" + depends on DEBUG_FS + help + This is an additional restriction for mounting debugfs. It allows + the kernel to have debugfs compiled, but requires that kernel command + line has a debugfs parameter to register as a filesystem. + + If unsure, say N.No hint as to what the command line option is? And again, it's not a restriction for mounting it, you are preventing it from initializing entirely.
Which, as I have found out over time, can had side affects for codepaths that try to check the return value of debugfs calls, and if they fail to succeed, abort the whole driver/subsystem/whatever initializaion path, which is not what I think you want to do here at all.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 56 lines · Peter
Quoted 46 lines · Greg Kroah-Hartman
Quoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 5 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)No documentation update? That's not good :(
Quoted 24 lines
fs/debugfs/inode.c +12
-1@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +} +early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; -Quoted 9 lines
fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 4 lines
fs/debugfs/inode.c +4
-0+#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to
simple_pin_fs()instart_creating()infs/debugfs/inode.c?
Quoted 1 line
If it does, the lines below is also cause the same problem.
In a working system, errors in the lines below will never happen :)
thanks,
greg k-h
Quoted 57 lines · Greg Kroah-Hartman
Quoted 56 lines · Peter
Quoted 55 lines · Greg Kroah-Hartman
Quoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 5 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)No documentation update? That's not good :(
Quoted 18 lines
fs/debugfs/inode.c +10
-0@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +}fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 10 lines
fs/debugfs/inode.c +6
-1+early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to
simple_pin_fs()instart_creating()infs/debugfs/inode.c?
Quoted 2 lines
Quoted 1 line
If it does, the lines below is also cause the same problem.
In a working system, errors in the lines below will never happen :)
I think it is not unreasonable to expect that debug functionality are robust enough to handle system where not everything is working smoothly.
Quoted 3 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 58 lines · Peter
Quoted 57 lines · Greg Kroah-Hartman
Quoted 56 lines · Peter
Quoted 55 lines · Greg Kroah-Hartman
Quoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 5 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)No documentation update? That's not good :(
Quoted 18 lines
fs/debugfs/inode.c +10
-0@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +}fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 10 lines
fs/debugfs/inode.c +6
-1+early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to
simple_pin_fs()instart_creating()infs/debugfs/inode.c?
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
If it does, the lines below is also cause the same problem.
In a working system, errors in the lines below will never happen :)
I think it is not unreasonable to expect that debug functionality are robust enough to handle system where not everything is working smoothly.
I do not disagree, but have you tested this to ensure that your kernel still works when you disable debugfs in this manner?
If so, great! Just trying to point out a potential problem...
thanks,
greg k-h
Quoted 59 lines · Greg Kroah-Hartman
Quoted 58 lines · Peter
Quoted 57 lines · Greg Kroah-Hartman
Quoted 56 lines · Peter
Quoted 55 lines · Greg Kroah-Hartman
Quoted 5 lines · Peter Enderborg
Since debugfs include sensitive information it need to be treated carefully. But it also has many very useful debug functions for userspace. With this option we can have same configuration for system with need of debugfs and a way to turn it off. It is needed new kernel command line parameter to be activated.
By "configuration" do you mean "kernel configuration"? What is wrong with relying on the build option like we do today?
You might want to reword all of this to make more sense about the "problem" you are trying to solve here, as I don't really understand it, sorry.
Quoted 5 lines
Signed-off-by Peter Enderborg <[email protected]>--- fs/debugfs/inode.c | 17 ++++++++++++++++- lib/Kconfig.debug | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)No documentation update? That's not good :(
Quoted 18 lines
fs/debugfs/inode.c +10
-0@@ -786,10 +786,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int allow_debugfs; + +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"true" )) + allow_debugfs = true; + +return 0 ; + +}fs/debugfs/inode.c bool debugfs_initialized(void) · line 807
Quoted 10 lines
fs/debugfs/inode.c +6
-1+early_param ("debugfs" , debugfs_kernel); +static int __init debugfs_init (void ) {int retval; - +#ifdef CONFIG_DEBUG_FS_MOUNT_RESTRICTED +if (!allow_debugfs) +return -EPERM ; +#endif But you are not restricting the ability to mount it here, you are removing the ability for it to even start up at all. What does this break for code that thinks the filesystem is registered (i.e. the call to
simple_pin_fs()instart_creating()infs/debugfs/inode.c?
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
If it does, the lines below is also cause the same problem.
In a working system, errors in the lines below will never happen :)
I think it is not unreasonable to expect that debug functionality are robust enough to handle system where not everything is working smoothly.
I do not disagree, but have you tested this to ensure that your kernel still works when you disable debugfs in this manner?
So far only tested on fedora f32 (x86_64) and older arm64 systems.
So far only zswap that prints out that "debugfs initialization failed" and it still works fine.
Quoted 1 line
If so, great! Just trying to point out a potential problem...
Will do new patchset, im waiting a bit longer to see if there some other comments first.
Quoted 3 lines
thanks,
greg k-h