linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lkdtm: no need to check return value of debugfs_create functions
@ 2019-06-11 18:32 Greg Kroah-Hartman
  2019-06-11 18:44 ` Kees Cook
  2019-06-11 20:43 ` Kees Cook
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-11 18:32 UTC (permalink / raw)
  To: Kees Cook; +Cc: Arnd Bergmann, linux-kernel

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Cc: Kees Cook <keescook@chromium.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/misc/lkdtm/core.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index 1972dad966f5..bae3b3763f3e 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)
 
 	/* Register debugfs interface */
 	lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
-	if (!lkdtm_debugfs_root) {
-		pr_err("creating root dir failed\n");
-		return -ENODEV;
-	}
 
 	/* Install debugfs trigger files. */
 	for (i = 0; i < ARRAY_SIZE(crashpoints); i++) {
 		struct crashpoint *cur = &crashpoints[i];
-		struct dentry *de;
 
-		de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
-					 cur, &cur->fops);
-		if (de == NULL) {
-			pr_err("could not create crashpoint %s\n", cur->name);
-			goto out_err;
-		}
+		debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, cur,
+				    &cur->fops);
 	}
 
 	/* Install crashpoint if one was selected. */
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] lkdtm: no need to check return value of debugfs_create functions
  2019-06-11 18:32 [PATCH] lkdtm: no need to check return value of debugfs_create functions Greg Kroah-Hartman
@ 2019-06-11 18:44 ` Kees Cook
  2019-06-11 18:56   ` Greg Kroah-Hartman
  2019-06-11 20:43 ` Kees Cook
  1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2019-06-11 18:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, linux-kernel

On Tue, Jun 11, 2019 at 08:32:13PM +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.

What is the user-visible feedback when, say, debugfs_create_file()
fails? And what happens when debugfs_create_file() passes in a NULL
root?

-Kees

> 
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/misc/lkdtm/core.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
> index 1972dad966f5..bae3b3763f3e 100644
> --- a/drivers/misc/lkdtm/core.c
> +++ b/drivers/misc/lkdtm/core.c
> @@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)
>  
>  	/* Register debugfs interface */
>  	lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
> -	if (!lkdtm_debugfs_root) {
> -		pr_err("creating root dir failed\n");
> -		return -ENODEV;
> -	}
>  
>  	/* Install debugfs trigger files. */
>  	for (i = 0; i < ARRAY_SIZE(crashpoints); i++) {
>  		struct crashpoint *cur = &crashpoints[i];
> -		struct dentry *de;
>  
> -		de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
> -					 cur, &cur->fops);
> -		if (de == NULL) {
> -			pr_err("could not create crashpoint %s\n", cur->name);
> -			goto out_err;
> -		}
> +		debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, cur,
> +				    &cur->fops);
>  	}
>  
>  	/* Install crashpoint if one was selected. */
> -- 
> 2.22.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lkdtm: no need to check return value of debugfs_create functions
  2019-06-11 18:44 ` Kees Cook
@ 2019-06-11 18:56   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-11 18:56 UTC (permalink / raw)
  To: Kees Cook; +Cc: Arnd Bergmann, linux-kernel

On Tue, Jun 11, 2019 at 11:44:53AM -0700, Kees Cook wrote:
> On Tue, Jun 11, 2019 at 08:32:13PM +0200, Greg Kroah-Hartman wrote:
> > When calling debugfs functions, there is no need to ever check the
> > return value.  The function can work or not, but the code logic should
> > never do something different based on this.
> 
> What is the user-visible feedback when, say, debugfs_create_file()
> fails?

All of the memory in your system is now gone and it would have long
locked up a while before this call ever happened :)

And no user functionality should ever change if a debugfs call fails, or
succeeds, this is debugging only.

> And what happens when debugfs_create_file() passes in a NULL root?

The file ends up in the root of debugfs.  But as this can only happen if
the system is dead, I wouldn't worry about it.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lkdtm: no need to check return value of debugfs_create functions
  2019-06-11 18:32 [PATCH] lkdtm: no need to check return value of debugfs_create functions Greg Kroah-Hartman
  2019-06-11 18:44 ` Kees Cook
@ 2019-06-11 20:43 ` Kees Cook
  2019-06-12 11:36   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2019-06-11 20:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, linux-kernel

On Tue, Jun 11, 2019 at 08:32:13PM +0200, Greg Kroah-Hartman wrote:
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  drivers/misc/lkdtm/core.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
> index 1972dad966f5..bae3b3763f3e 100644
> --- a/drivers/misc/lkdtm/core.c
> +++ b/drivers/misc/lkdtm/core.c
> @@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)
>  
>  	/* Register debugfs interface */
>  	lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
> -	if (!lkdtm_debugfs_root) {
> -		pr_err("creating root dir failed\n");
> -		return -ENODEV;
> -	}
>  
>  	/* Install debugfs trigger files. */
>  	for (i = 0; i < ARRAY_SIZE(crashpoints); i++) {
>  		struct crashpoint *cur = &crashpoints[i];
> -		struct dentry *de;
>  
> -		de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
> -					 cur, &cur->fops);
> -		if (de == NULL) {
> -			pr_err("could not create crashpoint %s\n", cur->name);
> -			goto out_err;
> -		}
> +		debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, cur,
> +				    &cur->fops);
>  	}
>  
>  	/* Install crashpoint if one was selected. */
> -- 
> 2.22.0
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] lkdtm: no need to check return value of debugfs_create functions
  2019-06-11 20:43 ` Kees Cook
@ 2019-06-12 11:36   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-12 11:36 UTC (permalink / raw)
  To: Kees Cook; +Cc: Arnd Bergmann, linux-kernel

On Tue, Jun 11, 2019 at 01:43:56PM -0700, Kees Cook wrote:
> On Tue, Jun 11, 2019 at 08:32:13PM +0200, Greg Kroah-Hartman wrote:
> > When calling debugfs functions, there is no need to ever check the
> > return value.  The function can work or not, but the code logic should
> > never do something different based on this.
> > 
> > Cc: Kees Cook <keescook@chromium.org>
> > Cc: Arnd Bergmann <arnd@arndb.de>
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Acked-by: Kees Cook <keescook@chromium.org>

Thanks for the review!

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-12 11:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11 18:32 [PATCH] lkdtm: no need to check return value of debugfs_create functions Greg Kroah-Hartman
2019-06-11 18:44 ` Kees Cook
2019-06-11 18:56   ` Greg Kroah-Hartman
2019-06-11 20:43 ` Kees Cook
2019-06-12 11:36   ` Greg Kroah-Hartman

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).