Linux Modules
 help / color / mirror / Atom feed
* [PATCH] libkmod: Avoid calling syscall() with -1
@ 2013-05-02 14:47 Jan Luebbe
  2013-05-02 16:21 ` Lucas De Marchi
  2013-05-11  4:01 ` Lucas De Marchi
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Luebbe @ 2013-05-02 14:47 UTC (permalink / raw)
  To: linux-modules; +Cc: Jan Luebbe

At least in qemu 1.4.1 for vexpress/arm-cortexa9, this resulted in an
illegal instruction error. Solve that by returning an error when
__NR_finit_module is -1.
---
 libkmod/missing.h |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libkmod/missing.h b/libkmod/missing.h
index edb88b9..ac24a35 100644
--- a/libkmod/missing.h
+++ b/libkmod/missing.h
@@ -20,8 +20,15 @@
 #endif
 
 #ifndef HAVE_FINIT_MODULE
+#include <errno.h>
+
 static inline int finit_module(int fd, const char *uargs, int flags)
 {
-	return syscall(__NR_finit_module, fd, uargs, flags);
+	if (__NR_finit_module == -1) {
+		errno = ENOSYS;
+		return -1;
+	} else {
+		return syscall(__NR_finit_module, fd, uargs, flags);
+	}
 }
 #endif

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

* Re: [PATCH] libkmod: Avoid calling syscall() with -1
  2013-05-02 14:47 [PATCH] libkmod: Avoid calling syscall() with -1 Jan Luebbe
@ 2013-05-02 16:21 ` Lucas De Marchi
  2013-05-02 19:41   ` Jan Luebbe
  2013-05-11  4:01 ` Lucas De Marchi
  1 sibling, 1 reply; 5+ messages in thread
From: Lucas De Marchi @ 2013-05-02 16:21 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: linux-modules

Hi Jan,

On Thu, May 2, 2013 at 11:47 AM, Jan Luebbe <jlu@pengutronix.de> wrote:
> At least in qemu 1.4.1 for vexpress/arm-cortexa9, this resulted in an
> illegal instruction error. Solve that by returning an error when
> __NR_finit_module is -1.
> ---
>  libkmod/missing.h |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/libkmod/missing.h b/libkmod/missing.h
> index edb88b9..ac24a35 100644
> --- a/libkmod/missing.h
> +++ b/libkmod/missing.h
> @@ -20,8 +20,15 @@
>  #endif
>
>  #ifndef HAVE_FINIT_MODULE
> +#include <errno.h>
> +
>  static inline int finit_module(int fd, const char *uargs, int flags)
>  {
> -       return syscall(__NR_finit_module, fd, uargs, flags);
> +       if (__NR_finit_module == -1) {
> +               errno = ENOSYS;
> +               return -1;
> +       } else {
> +               return syscall(__NR_finit_module, fd, uargs, flags);
> +       }
>  }
>  #endif
> --

Indeed. But I had already a patch for that, just waiting the bug
reporter to test it:

http://bugs.funtoo.org/browse/FL-534

And the patch:
http://bugs.funtoo.org/secure/attachment/11098/dont-call-libc.diff

I prefer doing it at compile time rather than runtime.

Lucas De Marchi

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

* Re: [PATCH] libkmod: Avoid calling syscall() with -1
  2013-05-02 16:21 ` Lucas De Marchi
@ 2013-05-02 19:41   ` Jan Luebbe
  2013-05-02 19:56     ` Lucas De Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Luebbe @ 2013-05-02 19:41 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-modules

On Thu, May 02, 2013 at 01:21:08PM -0300, Lucas De Marchi wrote:
> Indeed. But I had already a patch for that, just waiting the bug
> reporter to test it:
> 
> http://bugs.funtoo.org/browse/FL-534
> 
> And the patch:
> http://bugs.funtoo.org/secure/attachment/11098/dont-call-libc.diff

In that patch, the new #ifndef is never used, as __NR_finit_module is
defined a few lines up.

This one looks better, but failes to compile:
http://bugs.funtoo.org/secure/attachment/11099/0001-missing-Don-t-call-syscall-with-syscallno-1.patch
libkmod/missing.h:27:17: error: '__NR_finit_module' undeclared (first use in this function)

I've changed your patch a little (put the real call into the #else branch).
With this version, I don't see the problem any more.

----

From: Lucas De Marchi <lucas.de.marchi@gmail.com>
Date: Thu, 2 May 2013 13:22:57 -0300
Subject: [PATCH] missing: Don't call syscall() with syscallno == -1

Reported-by: Jean-Francis Roy <jeanfrancis@funtoo.org>
Reported-by: Jan Luebbe <jlu@pengutronix.de>
---
 libkmod/missing.h |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libkmod/missing.h b/libkmod/missing.h
index edb88b9..b31af84 100644
--- a/libkmod/missing.h
+++ b/libkmod/missing.h
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <errno.h>
 #include <unistd.h>
 #include <sys/syscall.h>
 
@@ -15,13 +16,14 @@
 # define MODULE_INIT_IGNORE_VERMAGIC 2
 #endif
 
-#ifndef __NR_finit_module
-# define __NR_finit_module -1
-#endif
-
 #ifndef HAVE_FINIT_MODULE
 static inline int finit_module(int fd, const char *uargs, int flags)
 {
+#ifndef __NR_finit_module
+	errno = ENOSYS;
+	return -1;
+#else
 	return syscall(__NR_finit_module, fd, uargs, flags);
+#endif
 }
 #endif

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH] libkmod: Avoid calling syscall() with -1
  2013-05-02 19:41   ` Jan Luebbe
@ 2013-05-02 19:56     ` Lucas De Marchi
  0 siblings, 0 replies; 5+ messages in thread
From: Lucas De Marchi @ 2013-05-02 19:56 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: linux-modules

Hi Jan,

On Thu, May 2, 2013 at 4:41 PM, Jan Luebbe <jlu@pengutronix.de> wrote:
> On Thu, May 02, 2013 at 01:21:08PM -0300, Lucas De Marchi wrote:
>> Indeed. But I had already a patch for that, just waiting the bug
>> reporter to test it:
>>
>> http://bugs.funtoo.org/browse/FL-534
>>
>> And the patch:
>> http://bugs.funtoo.org/secure/attachment/11098/dont-call-libc.diff
>
> In that patch, the new #ifndef is never used, as __NR_finit_module is
> defined a few lines up.
>
> This one looks better, but failes to compile:
> http://bugs.funtoo.org/secure/attachment/11099/0001-missing-Don-t-call-syscall-with-syscallno-1.patch
> libkmod/missing.h:27:17: error: '__NR_finit_module' undeclared (first use in this function)
>
> I've changed your patch a little (put the real call into the #else branch).
> With this version, I don't see the problem any more.
>
> ----
>
> From: Lucas De Marchi <lucas.de.marchi@gmail.com>
> Date: Thu, 2 May 2013 13:22:57 -0300
> Subject: [PATCH] missing: Don't call syscall() with syscallno == -1
>
> Reported-by: Jean-Francis Roy <jeanfrancis@funtoo.org>
> Reported-by: Jan Luebbe <jlu@pengutronix.de>
> ---
>  libkmod/missing.h |   10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libkmod/missing.h b/libkmod/missing.h
> index edb88b9..b31af84 100644
> --- a/libkmod/missing.h
> +++ b/libkmod/missing.h
> @@ -1,5 +1,6 @@
>  #pragma once
>
> +#include <errno.h>
>  #include <unistd.h>
>  #include <sys/syscall.h>
>
> @@ -15,13 +16,14 @@
>  # define MODULE_INIT_IGNORE_VERMAGIC 2
>  #endif
>
> -#ifndef __NR_finit_module
> -# define __NR_finit_module -1
> -#endif
> -
>  #ifndef HAVE_FINIT_MODULE
>  static inline int finit_module(int fd, const char *uargs, int flags)
>  {
> +#ifndef __NR_finit_module
> +       errno = ENOSYS;
> +       return -1;
> +#else
>         return syscall(__NR_finit_module, fd, uargs, flags);
> +#endif
>  }
>  #endif
>
> --

Thanks very much. Patch has been applied

Lucas De Marchi

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

* Re: [PATCH] libkmod: Avoid calling syscall() with -1
  2013-05-02 14:47 [PATCH] libkmod: Avoid calling syscall() with -1 Jan Luebbe
  2013-05-02 16:21 ` Lucas De Marchi
@ 2013-05-11  4:01 ` Lucas De Marchi
  1 sibling, 0 replies; 5+ messages in thread
From: Lucas De Marchi @ 2013-05-11  4:01 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: linux-modules, Chengwei Yang

Hi Jan,

On Thu, May 2, 2013 at 11:47 AM, Jan Luebbe <jlu@pengutronix.de> wrote:
> At least in qemu 1.4.1 for vexpress/arm-cortexa9, this resulted in an
> illegal instruction error. Solve that by returning an error when
> __NR_finit_module is -1.
> ---
>  libkmod/missing.h |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/libkmod/missing.h b/libkmod/missing.h
> index edb88b9..ac24a35 100644
> --- a/libkmod/missing.h
> +++ b/libkmod/missing.h
> @@ -20,8 +20,15 @@
>  #endif
>
>  #ifndef HAVE_FINIT_MODULE
> +#include <errno.h>
> +
>  static inline int finit_module(int fd, const char *uargs, int flags)
>  {
> -       return syscall(__NR_finit_module, fd, uargs, flags);
> +       if (__NR_finit_module == -1) {
> +               errno = ENOSYS;
> +               return -1;
> +       } else {
> +               return syscall(__NR_finit_module, fd, uargs, flags);
> +       }
>  }
>  #endif
> --

I changed my mind, reverted my change and applied yours instead
because we would have to do the same check inside testsuite, which is
currently failing for who doesn't have __NR_finit_module defined.


Thanks
Lucas De Marchi

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

end of thread, other threads:[~2013-05-11  4:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02 14:47 [PATCH] libkmod: Avoid calling syscall() with -1 Jan Luebbe
2013-05-02 16:21 ` Lucas De Marchi
2013-05-02 19:41   ` Jan Luebbe
2013-05-02 19:56     ` Lucas De Marchi
2013-05-11  4:01 ` Lucas De Marchi

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