debugfs: Add access restriction option
Subsystems (4)
PATCH v3 1/1 debugfs: Add access 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
When enabled it is needed a kernel command line parameter to be activated.
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
---
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions.
.../admin-guide/kernel-parameters.txt | 11 +++++ fs/debugfs/inode.c | 47 +++++++++++++++++++ lib/Kconfig.debug | 10 ++++ 3 files changed, 68 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +11 -0
@@ -827,6 +827,17 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] When CONFIG_DEBUG_FS_RESTRICTED is set, this parameter + enables what is exposed to userspace. + Format: { on, no_fs, off } + on: All functions are enabled. + no_fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + it's content. There its nothing to mount. + off: (default) Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +47 -0
91 lines not on this page · raw message
lib/Kconfig.debug +10 -0
@@ -477,6 +477,16 @@ config DEBUG_FS If unsure, say N. +config DEBUG_FS_RESTRICTED + bool "Debug Filesystem 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.17.1
Greg Kroah-Hartman
maintainerQuoted 54 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
When enabled it is needed a kernel command line parameter to be activated.
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>---
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions..../admin-guide/kernel-parameters.txt | 11 +++++ fs/debugfs/inode.c | 47 +++++++++++++++++++ lib/Kconfig.debug | 10 ++++ 3 files changed, 68 insertions(+)Documentation/admin-guide/kernel-parameters.txt +11
-0@@ -827,6 +827,17 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] When CONFIG_DEBUG_FS_RESTRICTED is set, this parameter + enables what is exposed to userspace. + Format: { on, no_fs, off } + on: All functions are enabled. + no_fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + it's content. There its nothing to mount. + off: (default) Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]fs/debugfs/inode.c +0
-0
fs/debugfs/inode.c line 36
Quoted 6 lines
fs/debugfs/inode.c +3
-0@@ -31,10 +31,17 @@#include "internal.h" #define DEBUGFS_DEFAULT_MODE 0700 +#ifdef CONFIG_DEBUG_FS_RESTRICTED +#define DEBUGFS_ALLOW_API 0x2 +#define DEBUGFS_ALLOW_FS 0x1
BIT()?
And a tab?
And why a #ifdef?
fs/debugfs/inode.c line 44
Quoted 8 lines
fs/debugfs/inode.c +4
-0+#endif static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +static unsigned int debugfs_allow; +#endif
Why #ifdef?
fs/debugfs/inode.c static struct dentry *debug_mount(struct file_system_type *fs_type, · line 279
Quoted 11 lines
fs/debugfs/inode.c +4
-0/* * Don't allow access attributes to be changed whilst the kernel is locked down @@ -266,6 +273,10 @@ static struct dentry *debug_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { +#ifdef CONFIG_DEBUG_FS_RESTRICTED + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +#endif
Ick, all of this #ifdef is a mess, and can be totally avoided if you do the logic right here. Please make it so that the functions and almost all of the .c code does not have #ifdef CONFIG_DEBUG_FS_RESTRICTED at all.
Quoted 45 lines
fs/debugfs/inode.c +18
-0return mount_single (fs_type, flags, data, debug_fill_super); }@@ -385,6 +396,12 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create file '%s'\n",@@ -541,6 +558,12 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",@@ -583,6 +606,12 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",@@ -786,10 +815,28 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized);
fs/debugfs/inode.c bool debugfs_initialized(void) · line 826
Quoted 10 lines
fs/debugfs/inode.c +9
-0+static int __init debugfs_kernel (char *str) +{ +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_FS ; +if (str && !strcmp (str,"no-fs" )) + debugfs_allow |=DEBUGFS_ALLOW_API ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ;
It's set to 0 by default, no need to set it again, right?
fs/debugfs/inode.c bool debugfs_initialized(void) · line 831
Quoted 5 lines
fs/debugfs/inode.c +5
-0+#endif +return 0 ; + +} +early_param ("debugfs" , debugfs_kernel);
Why is this a valid parm even if the option is not enabled? Do you mean to do that? Why?
thanks,
greg k-h
Quoted 63 lines · Greg Kroah-Hartman
Quoted 54 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
When enabled it is needed a kernel command line parameter to be activated.
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>---
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions..../admin-guide/kernel-parameters.txt | 11 +++++ fs/debugfs/inode.c | 47 +++++++++++++++++++ lib/Kconfig.debug | 10 ++++ 3 files changed, 68 insertions(+)Documentation/admin-guide/kernel-parameters.txt +11
-0@@ -827,6 +827,17 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] When CONFIG_DEBUG_FS_RESTRICTED is set, this parameter + enables what is exposed to userspace. + Format: { on, no_fs, off } + on: All functions are enabled. + no_fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + it's content. There its nothing to mount. + off: (default) Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]fs/debugfs/inode.c +0
-0fs/debugfs/inode.c line 36
Quoted 6 lines
fs/debugfs/inode.c +3
-0@@ -31,10 +31,17 @@#include "internal.h" #define DEBUGFS_DEFAULT_MODE 0700 +#ifdef CONFIG_DEBUG_FS_RESTRICTED +#define DEBUGFS_ALLOW_API 0x2 +#define DEBUGFS_ALLOW_FS 0x1
BIT()?
Quoted 3 lines
And a tab?
And why a #ifdef?
To get it as least intrusive as possible. A solid Opt-In.
Quoted 12 lines
fs/debugfs/inode.c line 44
Quoted 9 lines
fs/debugfs/inode.c +4
-0+#endif static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +static unsigned int debugfs_allow; +#endif Why #ifdef?
Quoted 1 line
Quoted 15 lines
fs/debugfs/inode.c static struct dentry *debug_mount(struct file_system_type *fs_type, · line 279
Quoted 10 lines
/*
* Don't allow access attributes to be changed whilst the kernel is locked downfs/debugfs/inode.c +4
-0@@ -266,6 +273,10 @@ static struct dentry *debug_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { +#ifdef CONFIG_DEBUG_FS_RESTRICTED + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +#endif Ick, all of this #ifdef is a mess, and can be totally avoided if you do the logic right here. Please make it so that the functions and almost all of the .c code does not have #ifdef
CONFIG_DEBUG_FS_RESTRICTEDat all.
Is it ok to remove the #ifdefs and let code always be there and let the config set the default value?
Quoted 46 lines
Quoted 46 lines
fs/debugfs/inode.c +18
-0return mount_single (fs_type, flags, data, debug_fill_super); }@@ -385,6 +396,12 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create file '%s'\n",@@ -541,6 +558,12 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",@@ -583,6 +606,12 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } +#endif inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",@@ -786,10 +815,28 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized);
Quoted 10 lines
fs/debugfs/inode.c bool debugfs_initialized(void) · line 826
Quoted 9 lines
fs/debugfs/inode.c +9
-0+static int __init debugfs_kernel (char *str) +{ +#ifdef CONFIG_DEBUG_FS_RESTRICTED +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_FS ; +if (str && !strcmp (str,"no-fs" )) + debugfs_allow |=DEBUGFS_ALLOW_API ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ;It's set to 0 by default, no need to set it again, right?
I think there have been some issues with the same parameter more than once.
Quoted 8 lines
fs/debugfs/inode.c bool debugfs_initialized(void) · line 831
Quoted 6 lines
fs/debugfs/inode.c +5
-0+#endif +return 0 ; + +} +early_param ("debugfs" , debugfs_kernel);Why is this a valid parm even if the option is not enabled? Do you mean to do that? Why?
I did not find any good usage where it was config dependent, when it is there; it is "reserve" the name.
It will always be there if we remove the #ifdefs.
Quoted 3 lines
thanks,
greg k-h
Randy Dunlap
reviewerQuoted 5 lines · Peter Enderborg
Documentation/admin-guide/kernel-parameters.txt +0
-0
Documentation/admin-guide/kernel-parameters.txt line 836
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +7
-0@@ -827,6 +827,17 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] When CONFIG_DEBUG_FS_RESTRICTED is set, this parameter + enables what is exposed to userspace. + Format: { on, no_fs, off } + on: All functions are enabled. + no_fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + it's content. There its nothing to mount.
its content. There is nothing to mount.
Quoted 7 lines
Documentation/admin-guide/kernel-parameters.txt +4
-0+ off: (default) Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
Signature · 1 line
~Randy
v4 cover debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs from inode.c and using internal.h for configuration
and now using BIT() for that. Function is now always on, and are instead selected by a built in default or command line parameter. Added preparation patch that removes check debugfs is initialised.
PATCH v4 1/2 tracefs: Remove unnecessary debug_fs checks.
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -8946,9 +8946,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
Signature · 1 line
2.26.2
Re: [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks.
Quoted 9 lines · Peter Enderborg
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
I'm sorry, but I can't parse this changelog text at all. Why exactly are you doing this?
Quoted 12 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Peter Enderborg <[email protected]>--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)kernel/trace/trace.c +0
-0
kernel/trace/trace.c struct dentry *tracing_init_dentry(void) · line 8951
Quoted 9 lines
kernel/trace/trace.c +1
-3@@ -8946,9 +8946,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );
This change makes sense to me anyway, so:
Re: [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks.
In reply to Peter EnderborgQuoted 10 lines · On Mon, 22 Jun 2020 10:30:18 +0200 Peter Enderborg <[email protected]>…
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Peter Enderborg <[email protected]>
-- Steve
Quoted 19 lines
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)kernel/trace/trace.c +1
-3@@ -8946,9 +8946,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
PATCH v4 2/2 debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
--- .../admin-guide/kernel-parameters.txt | 12 ++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 95 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -827,6 +827,18 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +37 -0
@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ACCESS_BITS ;/* * 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, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API_BIT)) + return ERR_CAST(ERR_PTR(-EPERM)); +return mount_single (fs_type, flags, data, debug_fill_super); }
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) +return ERR_PTR (-EPERM ); +pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",
@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API_BIT |DEBUGFS_ALLOW_FS_BIT ; +if (str && !strcmp (str,"no-fs" )) + debugfs_allow =DEBUGFS_ALLOW_API_BIT ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_FS_BIT )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
fs/debugfs/internal.h +14 -0
@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API_BIT BIT(0) +#define DEBUGFS_ALLOW_FS_BIT BIT(1) + +#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS_BIT|DEBUGFS_ALLOW_API_BIT) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API_BIT) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */
lib/Kconfig.debug +32 -0
@@ -477,6 +477,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALL + help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALL + bool "Access all" + help + No restrictions applies. Both API and filesystem registration + is on. + +config DEBUG_FS_ACCESS_NO_FS + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ACCESS_NONE + bool "No access" + help + Access is off. Clients get EPERM when trying to create nodes in + debugfs tree and debugfs is not registred as an filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.26.2
Greg Kroah-Hartman
maintainerQuoted 33 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 12 ++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 95 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -827,6 +827,18 @@ useful to also enable the page_owner functionality. on: enable the feature
Documentation/admin-guide/kernel-parameters.txt line 839
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10
-0+ debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs.
Can you add "This is equilivant of the runtime functionality if debugfs was not enabled in the kernel at all." to the "off" option?
Quoted 18 lines
Documentation/admin-guide/kernel-parameters.txt +2
-0+ Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]fs/debugfs/inode.c +1
-0@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ACCESS_BITS ;/* * Don't allow access attributes to be changed whilst the kernel is locked down
fs/debugfs/inode.c static struct dentry *debug_mount(struct file_system_type *fs_type, · line 271
Quoted 5 lines
fs/debugfs/inode.c +2
-0@@ -266,6 +267,9 @@ static struct dentry *debug_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API_BIT)) + return ERR_CAST(ERR_PTR(-EPERM));
Shouldn't ERR_PTR() be all that is needed here? I don't see any ERR_CAST() usages in this format in the kernel today.
fs/debugfs/inode.c static struct dentry *start_creating(const char *name, struct dentry *parent) · line 319
Quoted 10 lines
fs/debugfs/inode.c +3
-0+return mount_single (fs_type, flags, data, debug_fill_super); }@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) +return ERR_PTR (-EPERM );
See, you don't use it here :)
Quoted 71 lines
fs/debugfs/inode.c +31
-0+pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API_BIT )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API_BIT |DEBUGFS_ALLOW_FS_BIT ; +if (str && !strcmp (str,"no-fs" )) + debugfs_allow =DEBUGFS_ALLOW_API_BIT ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_FS_BIT )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;fs/debugfs/internal.h +0
-0
fs/debugfs/internal.h struct debugfs_fsdata { · line 34
Quoted 6 lines
fs/debugfs/internal.h +3
-0@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API_BIT BIT(0) +#define DEBUGFS_ALLOW_FS_BIT BIT(1)
tabs please.
And no need for _BIT in the string, right?
fs/debugfs/internal.h struct debugfs_fsdata { · line 37
Quoted 3 lines
fs/debugfs/internal.h +3
-0+ +#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS_BIT|DEBUGFS_ALLOW_API_BIT)
' ' is your friend :)
Quoted 19 lines
fs/debugfs/internal.h +8
-0+#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API_BIT) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */ lib/Kconfig.debug +2
-0@@ -477,6 +477,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access"
lib/Kconfig.debug config DEBUG_FS · line 491
Quoted 10 lines
lib/Kconfig.debug +10
-0+ depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALL + help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALL + bool "Access all"
"Normal access" as this is what we have today, "Access all" doesn't really explain what this is.
lib/Kconfig.debug config DEBUG_FS · line 494
Quoted 3 lines
lib/Kconfig.debug +3
-0+ help + No restrictions applies. Both API and filesystem registration + is on.
Add:
"This is the normal default operation"
Or something like that?
And you mix tabs and spaces a bunch in this patch for this file, did checkpatch not complain?
thanks,
greg k-h
v5 cover debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs from inode.c and using internal.h for configuration
and now using BIT() for that. Function is now always on, and are instead selected by a built in default or command line parameter. Changed return value on debug_mount
Im not sure about that it is right
v5 Added notes to config help suggested by GregKH.
Removed _BIT from names, white-space and tab. (checkpatch did not complain).
PATCH v5 1/2 tracefs: Remove unnecessary debug_fs checks.
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -8945,9 +8945,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
Signature · 1 line
2.17.1
PATCH v5 2/2 debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +14 -0
@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +37 -0
@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ACCESS_BITS ;/* * 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, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +return mount_single (fs_type, flags, data, debug_fill_super); }
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) +return ERR_PTR (-EPERM ); +pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",
@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_FS ; +if (str && !strcmp (str,"no-fs" )) + debugfs_allow =DEBUGFS_ALLOW_API ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_FS )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
fs/debugfs/internal.h +14 -0
@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_FS BIT(1) + +#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */
lib/Kconfig.debug +32 -0
@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALL + help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALL + bool "Access normal" + help + No restrictions applies. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_ACCESS_NO_FS + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ACCESS_NONE + bool "No access" + help + Access is off. Clients get EPERM when trying to create nodes in + debugfs tree and debugfs is not registred as an filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerQuoted 36 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)Documentation/admin-guide/kernel-parameters.txt +3
-0@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off }
Documentation/admin-guide/kernel-parameters.txt line 842
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10
-0+ on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration.
Naming is hard. In looking at this, should "no-fs" be called "no-mount"? That's a better description of what it does, right?
Then we can rename the bits to match the documentation so we aren't constantly thinking of different things and trying to match them up:
fs/debugfs/internal.h struct debugfs_fsdata { · line 34
Quoted 9 lines
fs/debugfs/internal.h +3
-0@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_FS BIT(1)
#define DEBUGFS_ALLOW_API BIT(0)
#define DEBUGFS_ALLOW_MOUNT BIT(1)
Quoted 16 lines
fs/debugfs/internal.h +10
-0+#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */ lib/Kconfig.debug +0
-0
lib/Kconfig.debug config DEBUG_FS · line 482
Quoted 7 lines
lib/Kconfig.debug +4
-0@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALL
default DEBUGFS_FS_ALLOW_ALL
lib/Kconfig.debug config DEBUG_FS · line 489
Quoted 7 lines
lib/Kconfig.debug +7
-0+ help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALL
config DEBUG_FS_ALLOW_ALL
lib/Kconfig.debug config DEBUG_FS · line 495
Quoted 6 lines
lib/Kconfig.debug +6
-0+ bool "Access normal" + help + No restrictions applies. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_ACCESS_NO_FS
config DEBUG_FS_DISALLOW_MOUNT
lib/Kconfig.debug config DEBUG_FS · line 502
Quoted 7 lines
lib/Kconfig.debug +7
-0+ bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ACCESS_NONE
config DEBUG_FS_ALLOW_NONE
Does that sound better?
I'm not trying to be a pain, just trying to name this all correctly as it's messy with different config options and bits and mapping that to checks in the code without everything called the same.
thanks,
greg k-h
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the feature
Quoted 15 lines
Documentation/admin-guide/kernel-parameters.txt line 842
Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +13
-0+ debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration.Naming is hard. In looking at this, should "no-fs" be called "no-mount"? That's a better description of what it does, right?
I think no-fs cover it better since it does not register a filesystem but provides the interfaces. Mounting is then indirectly stopped.
The idea start with a check for mounting but it is much more definitely stopped by prevention of register of the filesystem. I can imagine to have a forth "mode" where it register a fs but not allowing mounting. Such mode maybe useful for some runtime configuration. But this patch is about boot time configuration.
Quoted 76 lines
Then we can rename the bits to match the documentation so we aren't constantly thinking of different things and trying to match them up:
fs/debugfs/internal.h struct debugfs_fsdata { · line 34
Quoted 9 lines
fs/debugfs/internal.h +3
-0@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_FS BIT(1)#define
DEBUGFS_ALLOW_APIBIT(0)
#defineDEBUGFS_ALLOW_MOUNTBIT(1)Quoted 16 lines
fs/debugfs/internal.h +10
-0+#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */ lib/Kconfig.debug +0
-0lib/Kconfig.debug config DEBUG_FS · line 482
Quoted 7 lines
lib/Kconfig.debug +4
-0@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALLdefault
DEBUGFS_FS_ALLOW_ALLlib/Kconfig.debug config DEBUG_FS · line 489
Quoted 7 lines
lib/Kconfig.debug +7
-0+ help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALLconfig
DEBUG_FS_ALLOW_ALLlib/Kconfig.debug config DEBUG_FS · line 495
Quoted 6 lines
lib/Kconfig.debug +6
-0+ bool "Access normal" + help + No restrictions applies. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_ACCESS_NO_FSconfig
DEBUG_FS_DISALLOW_MOUNTlib/Kconfig.debug config DEBUG_FS · line 502
Quoted 7 lines
lib/Kconfig.debug +7
-0+ bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ACCESS_NONEconfig
DEBUG_FS_ALLOW_NONEDoes that sound better?
I'm not trying to be a pain, just trying to name this all correctly as it's messy with different config options and bits and mapping that to checks in the code without everything called the same.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 51 lines · Peter
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the featureQuoted 15 lines
Documentation/admin-guide/kernel-parameters.txt line 842
Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +13
-0+ debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration.Naming is hard. In looking at this, should "no-fs" be called "no-mount"? That's a better description of what it does, right?
Quoted 2 lines
I think no-fs cover it better since it does not register a filesystem but provides the interfaces. Mounting is then indirectly stopped.
But "mounting" is the common term we all know. "no-fs" doesn't really describe what is happening here, right? Everything works internally just fine, but we just are forbidding the filesystem to be mounted.
Quoted 5 lines
The idea start with a check for mounting but it is much more definitely stopped by prevention of register of the filesystem. I can imagine to have a forth "mode" where it register a fs but not allowing mounting. Such mode maybe useful for some runtime configuration. But this patch is about boot time configuration.
Preventing the registering of the filesystem does cut out the ability to mount the thing quite well :)
We could change it to just prevent the superblock from mounting if you want, as maybe we do need the fs to remain in the list of filesystems in the kernel at that point in time? Otherwise we are lying to userspace.
thanks,
greg k-h
Quoted 51 lines · Greg Kroah-Hartman
Quoted 50 lines · Peter
Quoted 49 lines · Greg Kroah-Hartman
Quoted 36 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)Documentation/admin-guide/kernel-parameters.txt +3
-0@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off }Documentation/admin-guide/kernel-parameters.txt line 842
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10
-0+ on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration.Naming is hard. In looking at this, should "no-fs" be called "no-mount"? That's a better description of what it does, right?
Quoted 6 lines
Quoted 2 lines
I think no-fs cover it better since it does not register a filesystem but provides the interfaces. Mounting is then indirectly stopped.
But "mounting" is the common term we all know. "no-fs" doesn't really describe what is happening here, right? Everything works internally just fine, but we just are forbidding the filesystem to be mounted.
I have no objection but now you know the background. So no-mount then.
I will do a new patch-set.
Quoted 11 lines
Quoted 5 lines
The idea start with a check for mounting but it is much more definitely stopped by prevention of register of the filesystem. I can imagine to have a forth "mode" where it register a fs but not allowing mounting. Such mode maybe useful for some runtime configuration. But this patch is about boot time configuration.
Preventing the registering of the filesystem does cut out the ability to mount the thing quite well :)
We could change it to just prevent the superblock from mounting if you want, as maybe we do need the fs to remain in the list of filesystems in the kernel at that point in time? Otherwise we are lying to userspace.
It is all about hide it away for userspace.
Quoted 3 lines
thanks,
greg k-h
Quoted 34 lines · Greg Kroah-Hartman
Quoted 33 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-fs mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 14 +++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 97 insertions(+)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -827,6 +827,20 @@ useful to also enable the page_owner functionality. on: enable the feature
Quoted 15 lines
Documentation/admin-guide/kernel-parameters.txt line 842
Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +13
-0+ debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-fs, off } + on: All functions are enabled. + no-fs: Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration.Naming is hard. In looking at this, should "no-fs" be called "no-mount"? That's a better description of what it does, right?
One name that had in mind was Stealth. It is more of what it is intended to do than how.
Quoted 76 lines
Then we can rename the bits to match the documentation so we aren't constantly thinking of different things and trying to match them up:
fs/debugfs/internal.h struct debugfs_fsdata { · line 34
Quoted 9 lines
fs/debugfs/internal.h +3
-0@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_FS BIT(1)#define
DEBUGFS_ALLOW_APIBIT(0)
#defineDEBUGFS_ALLOW_MOUNTBIT(1)Quoted 16 lines
fs/debugfs/internal.h +10
-0+#ifdef CONFIG_DEBUG_FS_ACCESS_ALL +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_FS | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NO_FS +#define DEFAULT_DEBUGFS_ACCESS_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ACCESS_NONE +#define DEFAULT_DEBUGFS_ACCESS_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */ lib/Kconfig.debug +0
-0lib/Kconfig.debug config DEBUG_FS · line 482
Quoted 7 lines
lib/Kconfig.debug +4
-0@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ACCESS_ALLdefault
DEBUGFS_FS_ALLOW_ALLlib/Kconfig.debug config DEBUG_FS · line 489
Quoted 7 lines
lib/Kconfig.debug +7
-0+ help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-fs,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ACCESS_ALLconfig
DEBUG_FS_ALLOW_ALLlib/Kconfig.debug config DEBUG_FS · line 495
Quoted 6 lines
lib/Kconfig.debug +6
-0+ bool "Access normal" + help + No restrictions applies. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_ACCESS_NO_FSconfig
DEBUG_FS_DISALLOW_MOUNTlib/Kconfig.debug config DEBUG_FS · line 502
Quoted 7 lines
lib/Kconfig.debug +7
-0+ bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ACCESS_NONEconfig
DEBUG_FS_ALLOW_NONEDoes that sound better?
I'm not trying to be a pain, just trying to name this all correctly as it's messy with different config options and bits and mapping that to checks in the code without everything called the same.
thanks,
greg k-h
v6 cover debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs from inode.c and using internal.h for configuration
and now using BIT() for that. Function is now always on, and are instead selected by a built in default or command line parameter. Changed return value on debug_mount
Im not sure about that it is right
v5 Added notes to config help suggested by GregKH.
Removed _BIT from names, white-space and tab. (checkpatch did not complain).
v6 Using ALLOW instead of ACCESS as name on BIT's. Change the fs to
mount to make it clear and easy to understand.
PATCH v6 1/2 tracefs: Remove unnecessary debug_fs checks.
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -8945,9 +8945,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
Signature · 1 line
2.17.1
PATCH v6 2/2 debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-mount mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
--- .../admin-guide/kernel-parameters.txt | 15 ++++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 98 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -827,6 +827,21 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-mount, off } + on: All functions are enabled. + no-mount: + Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +37 -0
@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ALLOW_BITS ;/* * 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, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +return mount_single (fs_type, flags, data, debug_fill_super); }
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) +return ERR_PTR (-EPERM ); +pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",
@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_MOUNT ; +if (str && !strcmp (str,"no-mount" )) + debugfs_allow =DEBUGFS_ALLOW_API ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_MOUNT )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
fs/debugfs/internal.h +14 -0
@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_MOUNT BIT(1) + +#ifdef CONFIG_DEBUG_FS_ALLOW_ALL +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ALLOW_NONE +#define DEFAULT_DEBUGFS_ALLOW_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */
lib/Kconfig.debug +32 -0
@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ALLOW_ALL + help + This select the default access restricions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-mount,off] The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ALLOW_ALL + bool "Access normal" + help + No restrictions applies. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_DISALLOW_MOUNT + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need + debugfs filesystem. + +config DEBUG_FS_ALLOW_NONE + bool "No access" + help + Access is off. Clients get EPERM when trying to create nodes in + debugfs tree and debugfs is not registred as an filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.17.1
Randy Dunlap
reviewerHi,
Quoted 5 lines · Peter Enderborg
lib/Kconfig.debug +0
-0
lib/Kconfig.debug config DEBUG_FS · line 484
Quoted 9 lines
lib/Kconfig.debug +6
-0@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ALLOW_ALL + help + This select the default access restricions for debugfs.
selects restrictions
lib/Kconfig.debug config DEBUG_FS · line 486
Quoted 2 lines
lib/Kconfig.debug +2
-0+ It can be overridden with kernel command line option + debugfs=[on,no-mount,off] The restrictions apply for API access
,off]. The
lib/Kconfig.debug config DEBUG_FS · line 492
Quoted 6 lines
lib/Kconfig.debug +6
-0+ and filesystem registration. . + +config DEBUG_FS_ALLOW_ALL + bool "Access normal" + help + No restrictions applies. Both API and filesystem registration
apply.
lib/Kconfig.debug config DEBUG_FS · line 499
Quoted 7 lines
lib/Kconfig.debug +7
-0+ is on. This is the normal default operation. + +config DEBUG_FS_DISALLOW_MOUNT + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and readed with debug tools that does not need
and read that do not need
lib/Kconfig.debug config DEBUG_FS · line 505
Quoted 6 lines
lib/Kconfig.debug +6
-0+ debugfs filesystem. + +config DEBUG_FS_ALLOW_NONE + bool "No access" + help + Access is off. Clients get EPERM when trying to create nodes in
-EPERM
lib/Kconfig.debug config DEBUG_FS · line 506
Quoted 1 line
lib/Kconfig.debug +1
-0+ debugfs tree and debugfs is not registred as an filesystem.
registered as a filesystem.
lib/Kconfig.debug config DEBUG_FS · line 509
Quoted 3 lines
lib/Kconfig.debug +3
-0+ Client can then back-off or continue without debugfs access. + +endchoice
Also, in many places in this Kconfig file, the indentation needs to be fixed. Some lines use spaces instead of one tab for indentation. Help text (under "help") should be indented with one tab + 2 spaces.
Signature · 1 line
~Randy
v7 cover debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs from inode.c and using internal.h for configuration
and now using BIT() for that. Function is now always on, and are instead selected by a built in default or command line parameter. Changed return value on debug_mount
Im not sure about that it is right
v5 Added notes to config help suggested by GregKH.
Removed _BIT from names, white-space and tab. (checkpatch did not complain).
v6 Using ALLOW instead of ACCESS as name on BIT's. Change the fs to
mount to make it clear and easy to understand.
v7 Updated Kconfig.debug with Randy Dunlap corrections.
PATCH v7 1/2 tracefs: Remove unnecessary debug_fs checks.
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -8945,9 +8945,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
Signature · 1 line
2.17.1
PATCH v7 2/2 debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-mount mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
--- .../admin-guide/kernel-parameters.txt | 15 ++++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 98 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -827,6 +827,21 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-mount, off } + on: All functions are enabled. + no-mount: + Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +37 -0
@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ALLOW_BITS ;/* * 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, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +return mount_single (fs_type, flags, data, debug_fill_super); }
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) +return ERR_PTR (-EPERM ); +pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",
@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_MOUNT ; +if (str && !strcmp (str,"no-mount" )) + debugfs_allow =DEBUGFS_ALLOW_API ; +if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_MOUNT )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
fs/debugfs/internal.h +14 -0
@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_MOUNT BIT(1) + +#ifdef CONFIG_DEBUG_FS_ALLOW_ALL +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ALLOW_NONE +#define DEFAULT_DEBUGFS_ALLOW_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */
lib/Kconfig.debug +32 -0
@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ALLOW_ALL + help + This selects the default access restrictions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-mount,off]. The restrictions apply for API access + and filesystem registration. . + +config DEBUG_FS_ALLOW_ALL + bool "Access normal" + help + No restrictions apply. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_DISALLOW_MOUNT + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do + their work and read with debug tools that do not need + debugfs filesystem. + +config DEBUG_FS_ALLOW_NONE + bool "No access" + help + Access is off. Clients get -PERM when trying to create nodes in + debugfs tree and debugfs is not registered as a filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.17.1
Randy Dunlap
reviewerHi Peter,
Here are a few more comments/corrections.
Quoted 35 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-mount mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
Signed-off-by Peter Enderborg <[email protected]>--- .../admin-guide/kernel-parameters.txt | 15 ++++++++ fs/debugfs/inode.c | 37 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 ++++++++++++++++ 4 files changed, 98 insertions(+)Documentation/admin-guide/kernel-parameters.txt +2
-0@@ -827,6 +827,21 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients.
Documentation/admin-guide/kernel-parameters.txt line 841
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10
-0+ Format: { on, no-mount, off } + on: All functions are enabled. + no-mount: + Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equilivant of the runtime functionality if
equivalent
Quoted 12 lines
Documentation/admin-guide/kernel-parameters.txt +3
-0+ debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]fs/debugfs/inode.c +0
-0
fs/debugfs/inode.c bool debugfs_initialized(void) · line 810
Quoted 3 lines
fs/debugfs/inode.c +0
-0@@ -786,10 +808,25 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized);
I would add some "else"s here:
fs/debugfs/inode.c bool debugfs_initialized(void) · line 814
Quoted 4 lines
fs/debugfs/inode.c +4
-0+static int __init debugfs_kernel (char *str) +{ +if (str && !strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_MOUNT ;
else if ...
fs/debugfs/inode.c bool debugfs_initialized(void) · line 816
Quoted 2 lines
fs/debugfs/inode.c +2
-0+if (str && !strcmp (str,"no-mount" )) + debugfs_allow =DEBUGFS_ALLOW_API ;
else if ...
Quoted 14 lines
fs/debugfs/inode.c +6
-0+if (str && !strcmp (str,"off" )) + debugfs_allow =0 ; + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);lib/Kconfig.debug +0
-0@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N.
lib/Kconfig.debug config DEBUG_FS · line 487
Quoted 10 lines
lib/Kconfig.debug +9
-0+choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ALLOW_ALL + help + This selects the default access restrictions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-mount,off]. The restrictions apply for API access + and filesystem registration. .
stray '.' there.
lib/Kconfig.debug config DEBUG_FS · line 498
Quoted 11 lines
lib/Kconfig.debug +11
-0+ +config DEBUG_FS_ALLOW_ALL + bool "Access normal" + help + No restrictions apply. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_DISALLOW_MOUNT + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem not loaded. Client can still do
but filesystem is not loaded. Clients can still do
Quoted 6 lines
lib/Kconfig.debug +5
-0+ their work and read with debug tools that do not need + debugfs filesystem. + +config DEBUG_FS_ALLOW_NONE + bool "No access"
lib/Kconfig.debug config DEBUG_FS · line 513
Quoted 10 lines
lib/Kconfig.debug +7
-0+ help + Access is off. Clients get -PERM when trying to create nodes in + debugfs tree and debugfs is not registered as a filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
thanks.
Signature · 1 line
~Randy
v8 cover debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs from inode.c and using internal.h for configuration
and now using BIT() for that. Function is now always on, and are instead selected by a built in default or command line parameter. Changed return value on debug_mount
Im not sure about that it is right
v5 Added notes to config help suggested by GregKH.
Removed _BIT from names, white-space and tab. (checkpatch did not complain).
v6 Using ALLOW instead of ACCESS as name on BIT's. Change the fs to
mount to make it clear and easy to understand.
v7 Updated Kconfig.debug with Randy Dunlap corrections. v8 Spell fixes from Randy and using else-if for command argument
parser.
PATCH v8 1/2 tracefs: Remove unnecessary debug_fs checks.
This is a preparation for debugfs restricted mode.
We don't need debugfs to trace, the removed check stop tracefs to work if debugfs is not initialised. We instead tries to automount within debugfs and relay on it's handling. The code path is to create a backward compatibility from when tracefs was part of debugfs, it is now standalone and does not need debugfs. When debugfs is in restricted it is compiled in but not active and return EPERM to clients and tracefs wont work if it assumes it is active it is compiled in kernel.
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -8945,9 +8945,7 @@ struct dentry *tracing_init_dentry(void)if (tr->dir)return NULL ; -if (WARN_ON (!tracefs_initialized ()) || - (IS_ENABLED (CONFIG_DEBUG_FS ) && -WARN_ON (!debugfs_initialized ()))) +if (WARN_ON (!tracefs_initialized ()))return ERR_PTR (-ENODEV );/*
Signature · 1 line
2.17.1
PATCH v8 2/2 debugfs: Add access restriction option
In reply to Peter EnderborgSince 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
It is controlled by a configurable default value that can be override with a kernel command line parameter. (debugfs=)
It can be on or off, but also internally on but not seen from user-space. This no-mount mode do not register a debugfs as filesystem, but client can register their parts in the internal structures. This data can be readed with a debugger or saved with a crashkernel. When it is off clients get EPERM error when accessing the functions for registering their components.
--- .../admin-guide/kernel-parameters.txt | 15 +++++++ fs/debugfs/inode.c | 39 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 +++++++++++++++ 4 files changed, 100 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -827,6 +827,21 @@ useful to also enable the page_owner functionality. on: enable the feature + debugfs= [KNL] This parameter enables what is exposed to userspace + and debugfs internal clients. + Format: { on, no-mount, off } + on: All functions are enabled. + no-mount: + Filesystem is not registered but kernel clients can + access APIs and a crashkernel can be used to read + its content. There is nothing to mount. + off: Filesystem is not registered and clients + get a -EPERM as result when trying to register files + or directories within debugfs. + This is equivalent of the runtime functionality if + debugfs was not enabled in the kernel at all. + Default value is set in build-time with a kernel configuration. + debugpat [X86] Enable PAT debugging decnet.addr= [HW,NET]
fs/debugfs/inode.c +39 -0
@@ -35,6 +35,7 @@static struct vfsmount *debugfs_mount;static int debugfs_mount_count;static bool debugfs_registered; +static unsigned int debugfs_allow =DEFAULT_DEBUGFS_ALLOW_BITS ;/* * 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, int flags, const char *dev_name, void *data) { + if (!(debugfs_allow & DEBUGFS_ALLOW_API)) + return ERR_PTR(-EPERM); +return mount_single (fs_type, flags, data, debug_fill_super); }
@@ -311,6 +315,9 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)struct dentry *dentry;int error; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) +return ERR_PTR (-EPERM ); +pr_debug ("creating file '%s'\n" , name);if (IS_ERR (parent))
@@ -385,6 +392,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { 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)if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create directory '%s'\n",
@@ -583,6 +600,11 @@ struct dentry *debugfs_create_automount(const char *name,if (IS_ERR (dentry))return dentry; +if (!(debugfs_allow &DEBUGFS_ALLOW_API )) { +failed_creating (dentry); +return ERR_PTR (-EPERM ); + } + inode =debugfs_get_inode (dentry->d_sb);if (unlikely (!inode)) { pr_err("out of free dentries, can not create automount '%s'\n",
@@ -786,10 +808,27 @@ bool debugfs_initialized(void) }EXPORT_SYMBOL_GPL (debugfs_initialized); +static int __init debugfs_kernel (char *str) +{ +if (str) { +if (!strcmp (str,"on" )) + debugfs_allow =DEBUGFS_ALLOW_API |DEBUGFS_ALLOW_MOUNT ; +else if (!strcmp (str,"no-mount" )) + debugfs_allow =DEBUGFS_ALLOW_API ; +else if (!strcmp (str,"off" )) + debugfs_allow =0 ; + } + +return 0 ; +} +early_param ("debugfs" , debugfs_kernel);static int __init debugfs_init (void ) {int retval; +if (!(debugfs_allow &DEBUGFS_ALLOW_MOUNT )) +return -EPERM ; + retval =sysfs_create_mount_point (kernel_kobj,"debug" );if (retval)return retval;
fs/debugfs/internal.h +14 -0
@@ -29,4 +29,18 @@ struct debugfs_fsdata {*/ #define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0) +/* Access BITS */ +#define DEBUGFS_ALLOW_API BIT(0) +#define DEBUGFS_ALLOW_MOUNT BIT(1) + +#ifdef CONFIG_DEBUG_FS_ALLOW_ALL +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT +#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API) +#endif +#ifdef CONFIG_DEBUG_FS_ALLOW_NONE +#define DEFAULT_DEBUGFS_ALLOW_BITS (0) +#endif +#endif /* _DEBUGFS_INTERNAL_H_ */
lib/Kconfig.debug +32 -0
@@ -476,6 +476,38 @@ config DEBUG_FS If unsure, say N. +choice + prompt "Debugfs default access" + depends on DEBUG_FS + default DEBUG_FS_ALLOW_ALL + help + This selects the default access restrictions for debugfs. + It can be overridden with kernel command line option + debugfs=[on,no-mount,off]. The restrictions apply for API access + and filesystem registration. + +config DEBUG_FS_ALLOW_ALL + bool "Access normal" + help + No restrictions apply. Both API and filesystem registration + is on. This is the normal default operation. + +config DEBUG_FS_DISALLOW_MOUNT + bool "Do not register debugfs as filesystem" + help + The API is open but filesystem is not loaded. Clients can still do + their work and read with debug tools that do not need + debugfs filesystem. + +config DEBUG_FS_ALLOW_NONE + bool "No access" + help + Access is off. Clients get -PERM when trying to create nodes in + debugfs tree and debugfs is not registered as a filesystem. + Client can then back-off or continue without debugfs access. + +endchoice + source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan"
Signature · 1 line
2.17.1
Randy Dunlap
reviewerQuoted 7 lines · Peter Enderborg
--- .../admin-guide/kernel-parameters.txt | 15 +++++++ fs/debugfs/inode.c | 39 +++++++++++++++++++ fs/debugfs/internal.h | 14 +++++++ lib/Kconfig.debug | 32 +++++++++++++++ 4 files changed, 100 insertions(+)
Hi Peter,
The changes look good. Thanks.
Signature · 1 line
~Randy
Greg Kroah-Hartman
maintainerQuoted 15 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. This gives a extra protection for exposure on systems where user-space services with system access are attacked.
v2. Removed MOUNT as part of restrictions. Added API's restrictions as
separate restriction.
v3 Updated Documentation after Randy Dunlap reviews and suggestions. v4 Removed #ifdefs frominode.cand usinginternal.hfor configuration
and now usingBIT()for that. Function is now always on, and are instead selected by a built in default or command line parameter. Changed return value ondebug_mountReported-by kernel test robot <[email protected]>
Quoted 11 lines
Im not sure about that it is right
v5 Added notes to config help suggested by GregKH.
Removed_BITfrom names, white-space and tab. (checkpatch did not complain).
v6 Using ALLOW instead of ACCESS as name on BIT's. Change the fs to
mount to make it clear and easy to understand.
v7 UpdatedKconfig.debugwith Randy Dunlap corrections. v8 Spell fixes from Randy and using else-if for command argument
parser.
Thanks for sticking with this, now queued up!
greg k-h