public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] module: return error when mod_sysfs_init() failed
@ 2007-09-29 10:06 Akinobu Mita
  2007-09-29 13:51 ` Rusty Russell
  2007-09-29 14:56 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Akinobu Mita @ 2007-09-29 10:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Rusty Russell

load_module() returns zero when mod_sysfs_init() fails,
then the module loading will succeed accidentally.

This patch makes load_module() return error correctly in that case.

Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

---
 kernel/module.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: 2.6-git/kernel/module.c
===================================================================
--- 2.6-git.orig/kernel/module.c
+++ 2.6-git/kernel/module.c
@@ -1782,7 +1782,8 @@ static struct module *load_module(void _
 	module_unload_init(mod);
 
 	/* Initialize kobject, so we can reference it. */
-	if (mod_sysfs_init(mod) != 0)
+	err = mod_sysfs_init(mod);
+	if (err)
 		goto cleanup;
 
 	/* Set up license info based on the info section */

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

* Re: [PATCH] module: return error when mod_sysfs_init() failed
  2007-09-29 10:06 [PATCH] module: return error when mod_sysfs_init() failed Akinobu Mita
@ 2007-09-29 13:51 ` Rusty Russell
  2007-09-29 14:56 ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Rusty Russell @ 2007-09-29 13:51 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, Greg Kroah-Hartman

On Sat, 2007-09-29 at 19:06 +0900, Akinobu Mita wrote:
> load_module() returns zero when mod_sysfs_init() fails,
> then the module loading will succeed accidentally.
> 
> This patch makes load_module() return error correctly in that case.

Thanks, applied.

Cheers,
Rusty.



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

* Re: [PATCH] module: return error when mod_sysfs_init() failed
  2007-09-29 10:06 [PATCH] module: return error when mod_sysfs_init() failed Akinobu Mita
  2007-09-29 13:51 ` Rusty Russell
@ 2007-09-29 14:56 ` Greg KH
  2007-09-29 15:37   ` Akinobu Mita
  1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2007-09-29 14:56 UTC (permalink / raw)
  To: Akinobu Mita, linux-kernel, Rusty Russell

On Sat, Sep 29, 2007 at 07:06:53PM +0900, Akinobu Mita wrote:
> load_module() returns zero when mod_sysfs_init() fails,
> then the module loading will succeed accidentally.
> 
> This patch makes load_module() return error correctly in that case.
> 
> Cc: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Rusty Russell <rusty@rustcorp.com.au>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> 
> ---
>  kernel/module.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> Index: 2.6-git/kernel/module.c
> ===================================================================
> --- 2.6-git.orig/kernel/module.c
> +++ 2.6-git/kernel/module.c
> @@ -1782,7 +1782,8 @@ static struct module *load_module(void _
>  	module_unload_init(mod);
>  
>  	/* Initialize kobject, so we can reference it. */
> -	if (mod_sysfs_init(mod) != 0)
> +	err = mod_sysfs_init(mod);
> +	if (err)
>  		goto cleanup;

I must be still asleep this morning, but I think this patch does the
exact same thing as the original code does, right?  Otherwise, this
code would always be failing.

Or do I just need to go get my morning coffee to wake up and see the
problem here?

thanks,

greg k-h

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

* Re: [PATCH] module: return error when mod_sysfs_init() failed
  2007-09-29 14:56 ` Greg KH
@ 2007-09-29 15:37   ` Akinobu Mita
  2007-09-29 17:17     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Akinobu Mita @ 2007-09-29 15:37 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, Rusty Russell

2007/9/29, Greg KH <gregkh@suse.de>:
> > Index: 2.6-git/kernel/module.c
> > ===================================================================
> > --- 2.6-git.orig/kernel/module.c
> > +++ 2.6-git/kernel/module.c
> > @@ -1782,7 +1782,8 @@ static struct module *load_module(void _
> >       module_unload_init(mod);
> >
> >       /* Initialize kobject, so we can reference it. */
> > -     if (mod_sysfs_init(mod) != 0)
> > +     err = mod_sysfs_init(mod);
> > +     if (err)
> >               goto cleanup;
>
> I must be still asleep this morning, but I think this patch does the
> exact same thing as the original code does, right?  Otherwise, this
> code would always be failing.
>
> Or do I just need to go get my morning coffee to wake up and see the
> problem here?

Hello,

In the original code, the "err" is zero before goto cleanup.
This "err" will be the return value of load_module().

load_module() is the function which returns error as pointer
and the expression IS_ERR(NULL) is false. So the caller of load_module()
cannot catch that error.

I found this problem when I was running the fault injection test
script in Documentation/fault-injection/fault-injection.txt with
random module.

#!/bin/bash

FAILTYPE=failslab
echo Y > /debug/$FAILTYPE/task-filter
echo 10 > /debug/$FAILTYPE/probability
echo 100 > /debug/$FAILTYPE/interval
echo -1 > /debug/$FAILTYPE/times
echo 0 > /debug/$FAILTYPE/space
echo 2 > /debug/$FAILTYPE/verbose
echo 0 > /debug/$FAILTYPE/ignore-gfp-wait

faulty_system()
{
        bash -c "echo 1 > /proc/self/make-it-fail && exec $*"
}

if [ $# -eq 0 ]
then
        echo "Usage: $0 modulename [ modulename ... ]"
        exit 1
fi

for m in $*
do
        echo inserting $m...
        faulty_system modprobe $m

        echo removing $m...
        faulty_system modprobe -r $m
done

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

* Re: [PATCH] module: return error when mod_sysfs_init() failed
  2007-09-29 15:37   ` Akinobu Mita
@ 2007-09-29 17:17     ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2007-09-29 17:17 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, Rusty Russell

On Sun, Sep 30, 2007 at 12:37:10AM +0900, Akinobu Mita wrote:
> 2007/9/29, Greg KH <gregkh@suse.de>:
> > > Index: 2.6-git/kernel/module.c
> > > ===================================================================
> > > --- 2.6-git.orig/kernel/module.c
> > > +++ 2.6-git/kernel/module.c
> > > @@ -1782,7 +1782,8 @@ static struct module *load_module(void _
> > >       module_unload_init(mod);
> > >
> > >       /* Initialize kobject, so we can reference it. */
> > > -     if (mod_sysfs_init(mod) != 0)
> > > +     err = mod_sysfs_init(mod);
> > > +     if (err)
> > >               goto cleanup;
> >
> > I must be still asleep this morning, but I think this patch does the
> > exact same thing as the original code does, right?  Otherwise, this
> > code would always be failing.
> >
> > Or do I just need to go get my morning coffee to wake up and see the
> > problem here?
> 
> Hello,
> 
> In the original code, the "err" is zero before goto cleanup.
> This "err" will be the return value of load_module().

Ah, ok, that makes sense now, thanks.  It was the error not getting
returned, it was not the fact that we were incorrectly checking the
return value of mod_sysfs_init.

thanks for clearing this up.

greg k-h

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

end of thread, other threads:[~2007-09-29 17:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-29 10:06 [PATCH] module: return error when mod_sysfs_init() failed Akinobu Mita
2007-09-29 13:51 ` Rusty Russell
2007-09-29 14:56 ` Greg KH
2007-09-29 15:37   ` Akinobu Mita
2007-09-29 17:17     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox