Skip to contentSkip to conversation

Add prctl to change endian of a task

PATCH In review Anton Blanchard 5 participants 6 messages Apr 1, 2006 – Apr 6, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add prctl to change endian of a task

Add a prctl to change a tasks endian. While we only have powerpc code to implement this so far, it seems like something that warrants a generic interface (like setting floating point mode bits).

---

kernel/sys.c +13 -0
Index: build/kernel/sys.c
===================================================================
@@ -57,6 +57,12 @@
 #ifndef GET_FPEXC_CTL
 # define GET_FPEXC_CTL(a,b)	(-EINVAL)
 #endif
+#ifndef GET_ENDIAN
+# define GET_ENDIAN(a,b)	(-EINVAL)
+#endif
+#ifndef SET_ENDIAN
+# define SET_ENDIAN(a,b)	(-EINVAL)
+#endif
 
 /*
  * this is where the system-wide overflow UID and GID are defined, for
@@ -2057,6 +2063,13 @@ asmlinkage long sys_prctl(int option, un
 				return -EFAULT;
 			return 0;
 		}
+		case PR_GET_ENDIAN:
+			error = GET_ENDIAN(current, arg2);
+			break;
+		case PR_SET_ENDIAN:
+			error = SET_ENDIAN(current, arg2);
+			break;
+
 		default:
 			error = -EINVAL;
 			break;
include/linux/prctl.h +6 -0
Index: build/include/linux/prctl.h
===================================================================
@@ -52,4 +52,10 @@
 #define PR_SET_NAME    15		/* Set process name */
 #define PR_GET_NAME    16		/* Get process name */
 
+/* Get/set process endian */
+#define PR_GET_ENDIAN	19
+#define PR_SET_ENDIAN	20
+# define PR_ENDIAN_BIG		0
+# define PR_ENDIAN_LITTLE	1
+
 #endif /* _LINUX_PRCTL_H */
#1 lore raw

Hi Anton,

Quoted 3 lines · you

Add a prctl to change a tasks endian. While we only have powerpc code to implement this so far, it seems like something that warrants a generic interface (like setting floating point mode bits).

Most programmers (and thus programs) expect this to be a compile time decision.

What are the reasons of allowing to change it so dynamic at all?

What are the security implications of this?
My naive guess is, that it might defeat range checking of values in user space code.

What about limiting this to be called once per task or VM? This will prevent most abuse scenarios, I can think of.

Regards

Ingo Oeser

#2 lore raw
Quoted 2 lines · Ingo Oeser

What about limiting this to be called once per task or VM? This will prevent most abuse scenarios, I can think of.

Abuse is a possible problem but you can deal with that. If you don't inherit endian changes then the problem doesn't occur. If you must inherit them then drop the inheritance when an suid/sgid exec occurs as we do with some other properties.

Can you explain however why you can't do this simply by using a binary magic number in the executable to indicate which endian it is, or do you really need to flip it ?

Alan

#3 lore raw

Hi,

Quoted 4 lines

Abuse is a possible problem but you can deal with that. If you don't inherit endian changes then the problem doesn't occur. If you must inherit them then drop the inheritance when an suid/sgid exec occurs as we do with some other properties.

Yeah dropping it on exec makes sense to me.

Quoted 3 lines

Can you explain however why you can't do this simply by using a binary magic number in the executable to indicate which endian it is, or do you really need to flip it ?

The aim is not to implement little endian binaries but to assist running portions of code in little endian mode. The thought is we could hook up qemu to it and avoid having to byteswap.

While ppc has byteswap integer loads it does not have byteswap floating point loads and a byteswap involves loading into the integer unit, performing the byteswap, storing to a temporary location and loading into the floating point unit. Rather slow.

Anton

#4 lore raw

From: Anton Blanchard <[email protected]>
Date: Tue, 4 Apr 2006 08:36:20 +1000

Quoted 8 lines

The aim is not to implement little endian binaries but to assist running portions of code in little endian mode. The thought is we could hook up qemu to it and avoid having to byteswap.

While ppc has byteswap integer loads it does not have byteswap floating point loads and a byteswap involves loading into the integer unit, performing the byteswap, storing to a temporary location and loading into the floating point unit. Rather slow.

Doesn't PPC have a PTE bit that does endian swapping? Wouldn't that be easier to use for something like qemu?

#5 lore raw
Quoted 2 lines · David S. Miller

Doesn't PPC have a PTE bit that does endian swapping? Wouldn't that be easier to use for something like qemu?

Some embedded PPC chips do, but most PPCs don't.

Paul.