linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add prctl to change endian of a task
@ 2006-04-01 22:29 Anton Blanchard
  2006-04-02 14:37 ` Ingo Oeser
  0 siblings, 1 reply; 6+ messages in thread
From: Anton Blanchard @ 2006-04-01 22:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm


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).

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: build/kernel/sys.c
===================================================================
--- build.orig/kernel/sys.c	2006-04-02 08:11:40.000000000 +1000
+++ build/kernel/sys.c	2006-04-02 08:13:13.000000000 +1000
@@ -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;
Index: build/include/linux/prctl.h
===================================================================
--- build.orig/include/linux/prctl.h	2006-04-02 08:11:40.000000000 +1000
+++ build/include/linux/prctl.h	2006-04-02 08:13:13.000000000 +1000
@@ -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 */

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

* Re: [PATCH] Add prctl to change endian of a task
  2006-04-01 22:29 [PATCH] Add prctl to change endian of a task Anton Blanchard
@ 2006-04-02 14:37 ` Ingo Oeser
  2006-04-02 14:56   ` Alan Cox
  0 siblings, 1 reply; 6+ messages in thread
From: Ingo Oeser @ 2006-04-02 14:37 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: linux-kernel, Andrew Morton

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

Hi Anton,

On Sunday, 2. April 2006 00:29, you wrote:
> 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

[-- Attachment #2: Type: application/pgp-signature, Size: 191 bytes --]

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

* Re: [PATCH] Add prctl to change endian of a task
  2006-04-02 14:37 ` Ingo Oeser
@ 2006-04-02 14:56   ` Alan Cox
  2006-04-03 22:36     ` Anton Blanchard
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2006-04-02 14:56 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: Anton Blanchard, linux-kernel, Andrew Morton

On Sul, 2006-04-02 at 16:37 +0200, Ingo Oeser wrote:
> 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


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

* Re: [PATCH] Add prctl to change endian of a task
  2006-04-02 14:56   ` Alan Cox
@ 2006-04-03 22:36     ` Anton Blanchard
  2006-04-03 22:40       ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Anton Blanchard @ 2006-04-03 22:36 UTC (permalink / raw)
  To: Alan Cox; +Cc: Ingo Oeser, linux-kernel, Andrew Morton

 
Hi,

> 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.

> 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

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

* Re: [PATCH] Add prctl to change endian of a task
  2006-04-03 22:36     ` Anton Blanchard
@ 2006-04-03 22:40       ` David S. Miller
  2006-04-06  5:13         ` Paul Mackerras
  0 siblings, 1 reply; 6+ messages in thread
From: David S. Miller @ 2006-04-03 22:40 UTC (permalink / raw)
  To: anton; +Cc: alan, ioe-lkml, linux-kernel, akpm

From: Anton Blanchard <anton@samba.org>
Date: Tue, 4 Apr 2006 08:36:20 +1000

> 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?

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

* Re: [PATCH] Add prctl to change endian of a task
  2006-04-03 22:40       ` David S. Miller
@ 2006-04-06  5:13         ` Paul Mackerras
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Mackerras @ 2006-04-06  5:13 UTC (permalink / raw)
  To: David S. Miller; +Cc: anton, alan, ioe-lkml, linux-kernel, akpm

David S. Miller writes:

> 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.

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

end of thread, other threads:[~2006-04-06  5:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-01 22:29 [PATCH] Add prctl to change endian of a task Anton Blanchard
2006-04-02 14:37 ` Ingo Oeser
2006-04-02 14:56   ` Alan Cox
2006-04-03 22:36     ` Anton Blanchard
2006-04-03 22:40       ` David S. Miller
2006-04-06  5:13         ` Paul Mackerras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).