Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp316892ybh; Wed, 15 Jul 2020 02:46:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrNmCCuMVtvo0WFOEYKBz0HmIX1ULyek+kiDfyDD0Iy9A30qOXHtHnjw9UZ0vTn1IR52VS X-Received: by 2002:a05:6402:3d0:: with SMTP id t16mr8486371edw.287.1594806384920; Wed, 15 Jul 2020 02:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594806384; cv=none; d=google.com; s=arc-20160816; b=ovSmhhRH55OeuPJZdzHxnwcDP8Z2zkDnarOqiZrtvRkZWXVlqs/gHo3urOg0sCThuO yYmBZXphS/yGWe11NAUWgKe3UrZVygtknrnU0IyJwERRPZLqM/PQHmnbctsKFgjm+63K TbE4p0/Zaw5QztBp3dq8f7UYMUseUJ49vCzBAmWYcxpk5wVSf4Vtv8cPBEBe1MA3X+NH ixN/ssCQejGg38Y7Ouyfbk67RFl0m7bx8xwrzcr0KUIEDkXFzTAiAnBzWZaCL9Tqzjr2 uGij/ElGrHUrcGHCRdkqI7XPIQVAe5Lw1BBYcNKGGxxoX+zzvZyd1XGl2sdRHdbDsS+B VxoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=nECebxkpgb4nVnCGwgKoOnRncSdfrsx8Db58gmWIzAo=; b=SbHP8Al0zwwHsovcq4EMXwlVLd6Fm7q9oF8k91x2yg8nhdFAjKSdAZuZTg5BZ9iR4/ 9QTxYcnfqmJfTPA5YOmFNfnXbdsiv7jt9NyqdC+8DMh/R/LpOrs3IS0kArdtuVL2vjRX 1MJX2p1+0virW12JcB9nr6pb28fqw1q8rF06cKX3wL4P3dwKordh0VD/55kitZH5v5eQ S50IMhtkZOYw3XKNaK0PRZWB1QIXlfh2SbAPp2TktoGWqi9VH0mOUnKZ2Zdnqrk3wJaB cdGTF9JCCapnHsuEhAMjPnnAQNBgZV5CJbPfKQZRzB8rp3HUyh83VVwLS/tbvR6n3aFU 84Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BSWyRmCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v26si908706ejc.337.2020.07.15.02.46.01; Wed, 15 Jul 2020 02:46:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BSWyRmCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730624AbgGOJjN (ORCPT + 99 others); Wed, 15 Jul 2020 05:39:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:46250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728820AbgGOJjN (ORCPT ); Wed, 15 Jul 2020 05:39:13 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E05732064B; Wed, 15 Jul 2020 09:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594805951; bh=jqxRFumEMx36pqxL6hC+qKNLUHgdbTbRa20frl5wXUY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BSWyRmCKSX873871Wm4QwK/cJtNY4QCGLEriUJkJtpgl4Otvjv2XNY04/hui20vnw vFWxJSqDhKnQbNmYzQa3hzLhSLzq1+Ne+jYDD/SbERburjMSj2Uafnc65GufZrFYvN mvpXiB1s1LOxKb1Gunm8/s+QCOm90LhuNbkEZ3tQ= Date: Wed, 15 Jul 2020 11:39:07 +0200 From: Greg Kroah-Hartman To: Peter Enderborg Cc: linux-kernel@vger.kernel.org, "Rafael J . Wysocki" , Andrew Morton , Jonathan Corbet , linux-doc@vger.kernel.org, Randy Dunlap , Steven Rostedt , Ingo Molnar Subject: Re: [PATCH 2/2] debugfs: Add access restriction option Message-ID: <20200715093907.GC2759174@kroah.com> References: <20200617133738.6631-1-peter.enderborg@sony.com> <20200715084207.7639-1-peter.enderborg@sony.com> <20200715084207.7639-3-peter.enderborg@sony.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715084207.7639-3-peter.enderborg@sony.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > .../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? 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