Skip to contentSkip to conversation

sys32_execve fix

PATCH Carsten Langgaard 3 participants 6 messages Jul 22, 2002 – Jul 23, 2002 MIPS

lore
Share & tools
lore
#0 lore raw

The following test fails on the 64-bit kernel:

#include <unistd.h>
#include <errno.h>

main(void)

{
        int ret;

        ret = execve("/bin/ls", NULL, NULL);
        printf("ret = %d, errno = %d\n", ret, errno);
}

The problem is that "nargs" in arch/mips64/kernel/linux32.c fails when argv is NULL, the patch below should fix the problem:

/Carsten

--

_    _ ____  ___   Carsten Langgaard   Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com

Index: arch/mips64/kernel/linux32.c
===================================================================
RCS file: /cvs/linux/arch/mips64/kernel/linux32.c,v retrieving revision 1.42.2.6

mips64/kernel/linux32.c +4 -2
diff -u -r1.42.2.6 linux32.c
@@ -411,12 +411,14 @@
 	int n, ret;
 
 	n = 0;
+	ptr = NULL;
 	do {
 		/* egcs is stupid */
 		if (!access_ok(VERIFY_READ, arg, sizeof (unsigned int)))
 			return -EFAULT;
-		if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
-			return ret;
+		if (arg)
+			if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
+				return ret;
 		if (ap)		/* no access_ok needed, we allocated */
 			if (IS_ERR(ret = __put_user(ptr, ap++)))
 				return ret;
#1 lore raw

I just found another problem in the linux32.c file.
I believe the "flock32" structure has been copied from other architecture, but we are little bit different, so it need a fix.
The patch below should fix that problem, please notice it also include the previous patch I send.

Maybe it would be even better to put the "flock32" structure definition in include/asm-mips64/fcntl.h instead.

/Carsten

Quoted 40 lines · Carsten Langgaard

The following test fails on the 64-bit kernel:

#include <unistd.h>
#include <errno.h>

main(void)

{
        int ret;

        ret = execve("/bin/ls", NULL, NULL);
        printf("ret = %d, errno = %d\n", ret, errno);
}

The problem is that "nargs" in arch/mips64/kernel/linux32.c fails when argv is NULL, the patch below should fix the problem:

/Carsten

--

_    _ ____  ___   Carsten Langgaard  Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556

Denmark http://www.mips.com

------------------------------------------------------------------------
Index: arch/mips64/kernel/linux32.c
===================================================================
RCS file: /cvs/linux/arch/mips64/kernel/linux32.c,v retrieving revision 1.42.2.6
diff -u -r1.42.2.6 linux32.c

mips64/kernel/linux32.c 2002/07/22 13:49:33 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +1 -0
@@ -411,12 +411,14 @@
        int n, ret;
 
        n = 0;
+       ptr = NULL;
        do {
                /* egcs is stupid */

mips64/kernel/linux32.c 2002/07/22 13:49:33 line 424

Quoted 10 lines
mips64/kernel/linux32.c 2002/07/22 13:49:33 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +3 -2
                if (!access_ok(VERIFY_READ, arg, sizeof (unsigned int)))
                        return -EFAULT;
-               if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
-                       return ret;
+               if (arg)
+                       if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
+                               return ret;
                if (ap)         /* no access_ok needed, we allocated */
                        if (IS_ERR(ret = __put_user(ptr, ap++)))
                                return ret;

--

_    _ ____  ___   Carsten Langgaard   Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com

Index: arch/mips64/kernel/linux32.c
===================================================================
RCS file: /cvs/linux/arch/mips64/kernel/linux32.c,v retrieving revision 1.42.2.6

mips64/kernel/linux32.c +6 -3
diff -u -r1.42.2.6 linux32.c
@@ -411,12 +411,14 @@
 	int n, ret;
 
 	n = 0;
+	ptr = NULL;
 	do {
 		/* egcs is stupid */
 		if (!access_ok(VERIFY_READ, arg, sizeof (unsigned int)))
 			return -EFAULT;
-		if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
-			return ret;
+		if (arg)
+			if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
+				return ret;
 		if (ap)		/* no access_ok needed, we allocated */
 			if (IS_ERR(ret = __put_user(ptr, ap++)))
 				return ret;
@@ -1406,8 +1408,9 @@
 	short l_whence;
 	__kernel_off_t32 l_start;
 	__kernel_off_t32 l_len;
+	int  l_sysid;
 	__kernel_pid_t32 l_pid;
-	short __unused;
+	int  pad[4];
 };
 
 static inline int get_flock(struct flock *kfl, struct flock32 *ufl)
#2 lore raw

Ralf, I can see you check in the fix Maciej suggested, thanks. But what about the flock32 structure, will you fix that too ?

/Carsten

Quoted 97 lines · Carsten Langgaard

I just found another problem in the linux32.c file.
I believe the "flock32" structure has been copied from other architecture, but we are little bit different, so it need a fix.
The patch below should fix that problem, please notice it also include the previous patch I send.

Maybe it would be even better to put the "flock32" structure definition in include/asm-mips64/fcntl.h instead.

/Carsten

Quoted 40 lines · Carsten Langgaard

The following test fails on the 64-bit kernel:

#include <unistd.h>
#include <errno.h>

main(void)

{
        int ret;

        ret = execve("/bin/ls", NULL, NULL);
        printf("ret = %d, errno = %d\n", ret, errno);
}

The problem is that "nargs" in arch/mips64/kernel/linux32.c fails when argv is NULL, the patch below should fix the problem:

/Carsten

--

_    _ ____  ___   Carsten Langgaard Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556

Denmark http://www.mips.com

------------------------------------------------------------------------
Index: arch/mips64/kernel/linux32.c
===================================================================
RCS file: /cvs/linux/arch/mips64/kernel/linux32.c,v retrieving revision 1.42.2.6
diff -u -r1.42.2.6 linux32.c

mips64/kernel/linux32.c 2002/07/22 13:49:33 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +1 -0
@@ -411,12 +411,14 @@
        int n, ret;
 
        n = 0;
+       ptr = NULL;
        do {
                /* egcs is stupid */

mips64/kernel/linux32.c 2002/07/22 13:49:33 line 424

Quoted 10 lines
mips64/kernel/linux32.c 2002/07/22 13:49:33 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +3 -2
                if (!access_ok(VERIFY_READ, arg, sizeof (unsigned int)))
                        return -EFAULT;
-               if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
-                       return ret;
+               if (arg)
+                       if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
+                               return ret;
                if (ap)         /* no access_ok needed, we allocated */
                        if (IS_ERR(ret = __put_user(ptr, ap++)))
                                return ret;

--

_    _ ____  ___   Carsten Langgaard  Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556

Denmark http://www.mips.com

------------------------------------------------------------------------
Index: arch/mips64/kernel/linux32.c
===================================================================
RCS file: /cvs/linux/arch/mips64/kernel/linux32.c,v retrieving revision 1.42.2.6
diff -u -r1.42.2.6 linux32.c

mips64/kernel/linux32.c 2002/07/22 14:40:04 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +4 -2
@@ -411,12 +411,14 @@
        int n, ret;
 
        n = 0;
+       ptr = NULL;
        do {
                /* egcs is stupid */
                if (!access_ok(VERIFY_READ, arg, sizeof (unsigned int)))
                        return -EFAULT;
-               if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
-                       return ret;
+               if (arg)
+                       if (IS_ERR(ret = __get_user((long)ptr,(int *)A(arg))))
+                               return ret;
                if (ap)         /* no access_ok needed, we allocated */
                        if (IS_ERR(ret = __put_user(ptr, ap++)))
                                return ret;

mips64/kernel/linux32.c 2002/07/22 14:40:04 line 1416

Quoted 10 lines
mips64/kernel/linux32.c 2002/07/22 14:40:04 renamed from mips64/kernel/linux32.c 2002/07/01 00:17:14 1.42.2.6 +2 -1
@@ -1406,8 +1408,9 @@
        short l_whence;
        __kernel_off_t32 l_start;
        __kernel_off_t32 l_len;
+       int  l_sysid;
        __kernel_pid_t32 l_pid;
-       short __unused;
+       int  pad[4];
 };
 
 static inline int get_flock(struct flock *kfl, struct flock32 *ufl)

--

_    _ ____  ___   Carsten Langgaard   Mailto:[email protected]
|\  /|||___)(___   MIPS Denmark        Direct: +45 4486 5527
| \/ |||    ____)  Lautrupvang 4B      Switch: +45 4486 5555
  TECHNOLOGIES     2750 Ballerup       Fax...: +45 4486 5556
                   Denmark             http://www.mips.com
#3 lore raw
Quoted 5 lines · Carsten Langgaard
Quoted 5 lines

The patch below should fix that problem, please notice it also include the previous patch I send.

Maybe it would be even better to put the "flock32" structure definition in include/asm-mips64/fcntl.h instead.

Yep, did that. The patch I'm actually going to check in has become quite a bit larger as I did the quite some cleanup to that file.

Ralf

#4 lore raw
In reply to Carsten Langgaard
Quoted 2 lines · Carsten Langgaard

The problem is that "nargs" in arch/mips64/kernel/linux32.c fails when argv is NULL, the patch below should fix the problem:

How about just:

	if (!arg)
		return 0;

at the top? Gcc should optimize it to a single branch, likely not taken, and a register move.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#5 lore raw
Quoted 10 lines · Maciej W. Rozycki
Quoted 2 lines

The problem is that "nargs" in arch/mips64/kernel/linux32.c fails when argv is NULL, the patch below should fix the problem:

How about just:

	if (!arg)
		return 0;

at the top? Gcc should optimize it to a single branch, likely not taken, and a register move.

Right. Coincidentally this is also what was done to the IA64 port where this code did originate.

Ralf