Skip to contentSkip to conversation

Regarding select() on PPC

PATCH In review Sadashiiv, Halesh 5 participants 18 messages Sep 23, 2008 – Oct 13, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines

-----Original Message-----
From: Benjamin Herrenschmidt [mailto:[email protected]]
Sent: Tuesday, September 23, 2008 12:00 PM
To: Arnd Bergmann
Cc: [email protected]; Sadashiiv, Halesh
Subject: Re: Regarding select() on PPC

Quoted 7 lines
Quoted 4 lines · Arnd Bergmann

No, sorry, I don't have a git history that I can search for that. I have a strong guess that it would be the end of the last century though, probably before 2.3.48, since the comment in there already refers to legacy binaries.

Yeah, I'm keen to rip it out.

Means argument checking in ppc_select() can be removed?? Than shall I post patch to [email protected]

Quoted 4 lines

Ben.

-------------------------------------------------------------------
This email is confidential and intended only for the use of the = individual or entity named above and may contain information that is = privileged. If you are not the intended recipient, you are notified that = any dissemination, distribution or copying of this email is strictly = prohibited. If you have received this email in error, please notify us = immediately by return email or telephone and destroy the original = message. - This mail is sent via Sony Asia Pacific Mail Gateway.
-------------------------------------------------------------------

#1 lore raw
Quoted 14 lines · Halesh
Quoted 14 lines

-----Original Message-----
From: Benjamin Herrenschmidt [mailto:[email protected]]
Sent: Tuesday, September 23, 2008 12:00 PM
To: Arnd Bergmann
Cc: [email protected]; Sadashiiv, Halesh
Subject: Re: Regarding select() on PPC

Quoted 4 lines · Arnd Bergmann

No, sorry, I don't have a git history that I can search for that. I have a strong guess that it would be the end of the last century though, probably before 2.3.48, since the comment in there already refers to legacy binaries.

Quoted 4 lines
Quoted 1 line

Yeah, I'm keen to rip it out.

Means argument checking in ppc_select() can be removed?? Than shall I post patch to [email protected]

ppc_select can probably be removed alltogether and ppc32_select too

Ben.

#2 lore raw
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 3 lines

Means argument checking in ppc_select() can be removed?? Than shall I post patch to [email protected]

ppc_select can probably be removed alltogether and ppc32_select too

I think ppc32_select needs to stay. It never did the hack for supporting the old_select calling conventions, but it does the sign extension for the 32 bit arguments, which I think you still want.

In any way, both the 32 bit emulation and the native ppc32 code path should do the same thing, which currently they don't.

	Arnd <><
#3 lore raw
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 3 lines

Means argument checking in ppc_select() can be removed?? Than shall I post patch to [email protected]

ppc_select can probably be removed alltogether and ppc32_select too

I think ppc32_select needs to stay. It never did the hack for supporting the old_select calling conventions, but it does the sign extension for the 32 bit arguments, which I think you still want.

Why do we want it ?

It's an int, it's zero extended, but that should still be a valid signed 32 bits int in compat_sys_select() or do I miss something ?

Ben.

Quoted 4 lines

In any way, both the 32 bit emulation and the native ppc32 code path should do the same thing, which currently they don't.

	Arnd <><
#4 lore raw
Quoted 4 lines · Benjamin Herrenschmidt

Why do we want it ?

It's an int, it's zero extended, but that should still be a valid signed 32 bits int in compat_sys_select() or do I miss something ?

IIRC, the calling conventions on 64 bit ppc assume that a signed int argument is sign-extended into a 64 bit register. The compat syscall entry point does not know which registers are signed or unsigned, so it will always to zero-extend, making the register contain an undefined bit pattern (e.g. 0x00000000fffffffe), which may be interpreted as being a positive number. An explicit cast as it is done in ppc32_select turns this into a well-defined 32-bit number stored in a 64-bit register (e.g. 0xfffffffffffffffe).

	Arnd <><
#5 lore raw
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Benjamin Herrenschmidt

Why do we want it ?

It's an int, it's zero extended, but that should still be a valid signed 32 bits int in compat_sys_select() or do I miss something ?

Quoted 8 lines

IIRC, the calling conventions on 64 bit ppc assume that a signed int argument is sign-extended into a 64 bit register. The compat syscall entry point does not know which registers are signed or unsigned, so it will always to zero-extend, making the register contain an undefined bit pattern (e.g. 0x00000000fffffffe), which may be interpreted as being a positive number. An explicit cast as it is done in ppc32_select turns this into a well-defined 32-bit number stored in a 64-bit register (e.g. 0xfffffffffffffffe).

If that is true, then _any_ syscall that takes an int value must have a ppc specific sign-extending compat wrapper, are you sure that is the case ?

Ben.

#6 lore raw
Quoted 4 lines

If that is true, then _any_ syscall that takes an int value must have a ppc specific sign-extending compat wrapper, are you sure that is the case ?

Ok, so that's crap that has been bitrotting. We -do- need to sign extend everywhere and it looks like we forgot to do it on anything recent, like signalfd4...

Ben.

#7 lore raw

PATCH 1/1 remove bogus ppc_select syscall

In reply to Arnd Bergmann

The ppc_select function was introduced in linux-2.3.48 in order to support code confusing the legacy select() calling convention with the standard one. Even 11 years ago, all correctly built code should not have done this and could have easily been phased out. Nothing that was compiled later should actually try to use the old_select interface, and it would have been broken already on all ppc64 kernels with the syscall emulation layer.

This patch brings the 32 bit compat ABI and the native 32 bit ABI for powerpc into a consistent state, by removing support for both the old_select system call number and the handler for it.

The bug report triggering this came from Halesh Sadashiiv <[email protected]>, who discovered that the 32 bit implementation of ppc_select would in case of a negative number
of file descriptors incorrectly return -EFAULT instead of -EINVAL.
There seems to be no way to fix this problem in a way that would
keep broken pre-1997 binaries running.

Cc Halesh Sadashiiv <[email protected]>

---

Halesh, please test this patch to make sure it fixes the problem you reported. I do not have a ppc32 machine I can try this on.

arch/powerpc/include/asm/unistd.h +1 -1
index e07d0c7..46107cc 100644
@@ -92,7 +92,7 @@
 #define __NR_settimeofday       79
 #define __NR_getgroups          80
 #define __NR_setgroups          81
-#define __NR_select             82
+/* Number 82 was the old (pre-1.3.x) select */
 #define __NR_symlink            83
 #define __NR_oldlstat           84
 #define __NR_readlink           85
arch/powerpc/include/asm/systbl.h +2 -2
index f6cc7a4..5a69b32 100644
@@ -85,7 +85,7 @@ COMPAT_SYS_SPU(gettimeofday)
 COMPAT_SYS_SPU(settimeofday)
 COMPAT_SYS_SPU(getgroups)
 COMPAT_SYS_SPU(setgroups)
-SYSX(sys_ni_syscall,sys_ni_syscall,ppc_select)
+SYSCALL(sys_ni_syscall)
 SYSCALL_SPU(symlink)
 OLDSYS(lstat)
 COMPAT_SYS_SPU(readlink)
@@ -145,7 +145,7 @@ SYSCALL_SPU(setfsuid)
 SYSCALL_SPU(setfsgid)
 SYSCALL_SPU(llseek)
 COMPAT_SYS_SPU(getdents)
-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)
 SYSCALL_SPU(flock)
 SYSCALL_SPU(msync)
 COMPAT_SYS_SPU(readv)
arch/powerpc/kernel/syscalls.c +0 -25
index c04832c..c2e6a74 100644
@@ -183,31 +183,6 @@ unsigned long sys_mmap(unsigned long addr, size_t len,
 	return do_mmap2(addr, len, prot, flags, fd, offset, PAGE_SHIFT);
 }
 
-#ifdef CONFIG_PPC32
-/*
- * Due to some executables calling the wrong select we sometimes
- * get wrong args.  This determines how the args are being passed
- * (a single ptr to them all args passed) then calls
- * sys_select() with the appropriate args. -- Cort
- */
-int
-ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
-{
-	if ( (unsigned long)n >= 4096 )
-	{
-		unsigned long __user *buffer = (unsigned long __user *)n;
-		if (!access_ok(VERIFY_READ, buffer, 5*sizeof(unsigned long))
-		    || __get_user(n, buffer)
-		    || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
-		    || __get_user(outp, ((fd_set  __user * __user *)(buffer+2)))
-		    || __get_user(exp, ((fd_set  __user * __user *)(buffer+3)))
-		    || __get_user(tvp, ((struct timeval  __user * __user *)(buffer+4))))
-			return -EFAULT;
-	}
-	return sys_select(n, inp, outp, exp, tvp);
-}
-#endif
-
 #ifdef CONFIG_PPC64
 long ppc64_personality(unsigned long personality)
 {
#8 lore raw

Re: [PATCH] remove bogus ppc_select syscall

arch/powerpc/include/asm/systbl.h COMPAT_SYS_SPU(gettimeofday) · line 88

Quoted 10 lines · Arnd Bergmann
arch/powerpc/include/asm/systbl.h +1 -1
index f6cc7a4..5a69b32 100644
@@ -85,7 +85,7 @@ COMPAT_SYS_SPU(gettimeofday)
 COMPAT_SYS_SPU(settimeofday)
 COMPAT_SYS_SPU(getgroups)
 COMPAT_SYS_SPU(setgroups)
-SYSX(sys_ni_syscall,sys_ni_syscall,ppc_select)
+SYSCALL(sys_ni_syscall)

I don't see any reason to remove the old select syscall on 32-bit kernels. I think this hunk below is the only part of the patch that we actually need:

arch/powerpc/include/asm/systbl.h SYSCALL_SPU(setfsuid) · line 148

Quoted 6 lines
arch/powerpc/include/asm/systbl.h +1 -1
@@ -145,7 +145,7 @@ SYSCALL_SPU(setfsuid)
 SYSCALL_SPU(setfsgid)
 SYSCALL_SPU(llseek)
 COMPAT_SYS_SPU(getdents)
-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)

Paul.

#9 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 1 line · Paul Mackerras

arch/powerpc/include/a=

Quoted 1 line
arch/powerpc/include/a= renamed from arch/powerpc/include/asm/systbl.h +0 -0

sm/systbl.h

Quoted 4 lines
Quoted 4 lines

index f6cc7a4..5a69b32 100644

arch/powerpc/include/asm/systbl.h +0 -0
@@ -85,7 +85,7 @@ COMPAT_SYS_SPU(gettimeofday)
Quoted 8 lines

arch/powerpc/include/asm/systbl.h COMPAT_SYS_SPU(gettimeofday) · line 88

Quoted 5 lines
arch/powerpc/include/asm/systbl.h +1 -1
 =A0COMPAT_SYS_SPU(settimeofday)
 =A0COMPAT_SYS_SPU(getgroups)
 =A0COMPAT_SYS_SPU(setgroups)
-SYSX(sys_ni_syscall,sys_ni_syscall,ppc_select)
+SYSCALL(sys_ni_syscall)

=20
I don't see any reason to remove the old select syscall on 32-bit kernels. =A0

Well, the point I made earlier ist that the native ppc32 path should behave the same way as the compat ppc32 path. If we keep ppc_select in one way or another, we should also have a compat wrapper for that, right?

	Arnd <><
#10 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 4 lines · Arnd Bergmann

Well, the point I made earlier ist that the native ppc32 path should behave the same way as the compat ppc32 path. If we keep ppc_select in one way or another, we should also have a compat wrapper for that, right?

No - we have other old system calls that don't exist at all on a 64-bit kernel but do on a 32-bit kernel. We decided a long time ago that there was no point supporting really ancient 32-bit userland code on a 64-bit kernel. That doesn't mean we need to rip out the support from the 32-bit kernel.

Paul.

#11 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 6 lines · Paul Mackerras

Arnd Bergmann writes:
=20

Quoted 4 lines

Well, the point I made earlier ist that the native ppc32 path should behave the same way as the compat ppc32 path. If we keep ppc_select in one way or another, we should also have a compat wrapper for that, right?

Quoted 6 lines

=20
No - we have other old system calls that don't exist at all on a 64-bit kernel but do on a 32-bit kernel. =A0We decided a long time ago that there was no point supporting really ancient 32-bit userland code on a 64-bit kernel. =A0That doesn't mean we need to rip out the support from the 32-bit kernel.

Ok, that makes sense, thanks for the clarification.

	Arnd <><
#12 lore raw

Re: [PATCH] remove bogus ppc_select syscall

In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

The ppc_select function was introduced in linux-2.3.48 in order to support code confusing the legacy select() calling convention with the standard one. Even 11 years ago, all correctly built code should not have done this and could have easily been phased out. Nothing that was compiled later should actually try to use the old_select interface, and it would have been broken already on all ppc64 kernels with the syscall emulation layer.

This patch brings the 32 bit compat ABI and the native 32 bit ABI for powerpc into a consistent state, by removing support for both the old_select system call number and the handler for it.

.../...

It's me or the patch is whitespaces damaged ?

Cheers,
Ben.

#13 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Arnd Bergmann

The ppc_select function was introduced in linux-2.3.48 in order to support code confusing the legacy select() calling convention with the standard one. Even 11 years ago, all correctly built code should not have done this and could have easily been phased out. Nothing that was compiled later should actually try to use the old_select interface, and it would have been broken already on all ppc64 kernels with the syscall emulation layer.

Quoted 7 lines
Quoted 3 lines

This patch brings the 32 bit compat ABI and the native 32 bit ABI for powerpc into a consistent state, by removing support for both the old_select system call number and the handler for it.

.../...

It's me or the patch is whitespaces damaged ?

Please don't apply Arnd's patch. As I said, all we need is this one-line change in arch/powerpc/include/asm/systbl.h:

-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)

Paul.

Acked-by
#14 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 7 lines · Paul Mackerras

Please don't apply Arnd's patch. =A0As I said, all we need is this one-line change in arch/powerpc/include/asm/systbl.h:
=20

arch/powerpc/include/asm/systbl.h +1 -1
-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)

=20
Paul.

=46WIW,

#15 lore raw

Re: [PATCH] remove bogus ppc_select syscall

In reply to Paul Mackerras

arch/powerpc/include/asm/systbl.h SYSCALL_SPU(setfsuid) · line 148

Quoted 7 lines · Paul Mackerras
Quoted 1 line

It's me or the patch is whitespaces damaged ?

Please don't apply Arnd's patch. As I said, all we need is this one-line change in arch/powerpc/include/asm/systbl.h:

arch/powerpc/include/asm/systbl.h +1 -1
-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)

Ok, so you want to keep compat with the old stuff. Note that we still have this weird thing that on 64-bit kernels, we don't provide this.

Ben.

#16 lore raw

Re: [PATCH] remove bogus ppc_select syscall

Quoted 6 lines · Benjamin Herrenschmidt

arch/powerpc/include/asm/systbl.h SYSCALL_SPU(setfsuid) · line 148

Quoted 3 lines
arch/powerpc/include/asm/systbl.h +1 -1
-SYSX_SPU(sys_select,ppc32_select,ppc_select)
+SYSX_SPU(sys_select,ppc32_select,sys_select)

Ok, so you want to keep compat with the old stuff. Note that we still have this weird thing that on 64-bit kernels, we don't provide this.

This change makes the funny wrapper only active for the "old" select number on native ppc32, which is not active on ppc64 or compat32, while any programs using the "new" select number, i.e. any binay you will ever encounter in practice, now gets the standard semantics.

	Arnd <><