linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Enderborg, Peter" <Peter.Enderborg@sony.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH 2/2] debugfs: Add access restriction option
Date: Tue, 21 Jul 2020 06:47:58 +0000	[thread overview]
Message-ID: <7b992dc0-0939-b45e-48c3-2e5eae2a1199@sony.com> (raw)
In-Reply-To: <20200715093907.GC2759174@kroah.com>

On 7/15/20 11:39 AM, Greg Kroah-Hartman wrote:
> On Wed, Jul 15, 2020 at 10:42:07AM +0200, Peter Enderborg wrote:
>> 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 <peter.enderborg@sony.com>
>> ---
>>  .../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(+)
>>
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index fb95fad81c79..805aa2e58491 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -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.
> 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.
> 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:
>
>
>> --- a/fs/debugfs/internal.h
>> +++ b/fs/debugfs/internal.h
>> @@ -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)
>
>> +#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_ */
>> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
>> index 9ad9210d70a1..b609ad7c1343 100644
>> --- a/lib/Kconfig.debug
>> +++ b/lib/Kconfig.debug
>> @@ -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
>
>> +	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
>
>> +       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
>
>> +       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


  parent reply	other threads:[~2020-07-21  6:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 13:37 [PATCH v3] debugfs: Add access restriction option Peter Enderborg
2020-06-17 14:15 ` Greg Kroah-Hartman
2020-06-17 14:39   ` Enderborg, Peter
2020-06-17 15:10 ` Randy Dunlap
2020-06-22  8:30 ` [PATCH v4 0/2] " Peter Enderborg
2020-06-22  8:30   ` [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks Peter Enderborg
2020-06-22  9:18     ` Greg Kroah-Hartman
2020-06-22 13:47     ` Steven Rostedt
2020-06-22  8:30   ` [PATCH 2/2] debugfs: Add access restriction option Peter Enderborg
2020-07-10 13:06     ` Greg Kroah-Hartman
2020-07-15  8:42 ` [PATCH v5 0/2] " Peter Enderborg
2020-07-15  8:42   ` [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks Peter Enderborg
2020-07-15  8:42   ` [PATCH 2/2] debugfs: Add access restriction option Peter Enderborg
2020-07-15  9:39     ` Greg Kroah-Hartman
2020-07-15 10:03       ` Enderborg, Peter
2020-07-15 10:35         ` Greg Kroah-Hartman
2020-07-15 10:59           ` Enderborg, Peter
2020-07-21  6:47       ` Enderborg, Peter [this message]
2020-07-15 15:25 ` [PATCH v6 0/2] " Peter Enderborg
2020-07-15 15:25   ` [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks Peter Enderborg
2020-07-15 15:25   ` [PATCH 2/2] debugfs: Add access restriction option Peter Enderborg
2020-07-16  3:30     ` Randy Dunlap
2020-07-16  4:54 ` [PATCH v7 0/2] " Peter Enderborg
2020-07-16  4:54   ` [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks Peter Enderborg
2020-07-16  4:54   ` [PATCH 2/2] debugfs: Add access restriction option Peter Enderborg
2020-07-16  5:12     ` Randy Dunlap
2020-07-16  7:15 ` [PATCH v8 0/2] " Peter Enderborg
2020-07-16  7:15   ` [PATCH 1/2] tracefs: Remove unnecessary debug_fs checks Peter Enderborg
2020-07-16  7:15   ` [PATCH 2/2] debugfs: Add access restriction option Peter Enderborg
2020-07-16 15:26     ` Randy Dunlap
2020-07-23 15:11   ` [PATCH v8 0/2] " Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7b992dc0-0939-b45e-48c3-2e5eae2a1199@sony.com \
    --to=peter.enderborg@sony.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).