2005-05-09 21:47:21

by Yoav Zach

[permalink] [raw]
Subject: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3

In ia64 kernel, the O_LARGEFILE flag is forced when
opening a file. This is problematic for execution of
32 bit processes, which are not largefile aware, either
by SW emulation or by HW execution.
For such processes, the problem is two-fold:
1) When trying to open a file that is larger than 4G
the operation should fail, but it's not
2) Writing to offset larger than 4G should fail, but
it's not

The proposed patch takes advantage of the way 32 bit
processes are identified in ia64 systems. Such
processes have PER_LINUX32 for their personality. With
the patch, the ia64 kernel will not enforce the O_LARGEFILE
flag if the current process has PER_LINUX32 set.
The behavior for all other architectures remains unchanged.

The patch is against 2.6.12-rc3.

Signed-off-by: Yoav Zach <[email protected]>
Acked-by: Tony Luck <[email protected]>
============================================================================================
diff -r -U 3 -p -N linux-2.6.12-rc3/fs/open.c linux/fs/open.c
--- linux-2.6.12-rc3/fs/open.c 2005-04-21 03:03:15.000000000 +0300
+++ linux/fs/open.c 2005-05-09 23:50:08.000000000 +0300
@@ -21,6 +21,7 @@
#include <linux/vfs.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
+#include <linux/personality.h>
#include <linux/pagemap.h>
#include <linux/syscalls.h>

@@ -935,9 +936,9 @@ asmlinkage long sys_open(const char __us
char * tmp;
int fd, error;

-#if BITS_PER_LONG != 32
- flags |= O_LARGEFILE;
-#endif
+ if (force_o_largefile())
+ flags |= O_LARGEFILE;
+
tmp = getname(filename);
fd = PTR_ERR(tmp);
if (!IS_ERR(tmp)) {
diff -r -U 3 -p -N linux-2.6.12-rc3/include/asm-ia64/fcntl.h linux/include/asm-ia64/fcntl.h
--- linux-2.6.12-rc3/include/asm-ia64/fcntl.h 2005-04-21 03:03:16.000000000 +0300
+++ linux/include/asm-ia64/fcntl.h 2005-05-09 23:51:53.000000000 +0300
@@ -81,4 +81,6 @@ struct flock {

#define F_LINUX_SPECIFIC_BASE 1024

+#define force_o_largefile() ( ! (current->personality & PER_LINUX32) )
+
#endif /* _ASM_IA64_FCNTL_H */
diff -r -U 3 -p -N linux-2.6.12-rc3/include/linux/fcntl.h linux/include/linux/fcntl.h
--- linux-2.6.12-rc3/include/linux/fcntl.h 2005-04-21 03:03:16.000000000 +0300
+++ linux/include/linux/fcntl.h 2005-05-09 23:51:46.000000000 +0300
@@ -25,6 +25,10 @@

#ifdef __KERNEL__

+#ifndef force_o_largefile
+#define force_o_largefile() (BITS_PER_LONG != 32)
+#endif
+
#if BITS_PER_LONG == 32
#define IS_GETLK32(cmd) ((cmd) == F_GETLK)
#define IS_SETLK32(cmd) ((cmd) == F_SETLK)
============================================================================================


Thanks,
Yoav.


Yoav Zach
IA-32 Execution Layer
Performance Tools Lab
Intel Corp.




__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail


2005-05-10 01:45:34

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3

Yoav Zach wrote:
> In ia64 kernel, the O_LARGEFILE flag is forced when
> opening a file. This is problematic for execution of
> 32 bit processes, which are not largefile aware, either
> by SW emulation or by HW execution.
> For such processes, the problem is two-fold:
> 1) When trying to open a file that is larger than 4G
> the operation should fail, but it's not
> 2) Writing to offset larger than 4G should fail, but
> it's not

O_LARGEFILE works great on my 32-bit platform.

Is this an ABI bug? O_LARGEFILE should be OK for 32-bit processes.

Jeff



2005-05-10 05:16:08

by Luck, Tony

[permalink] [raw]
Subject: Re: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3

Jeff Garzik wrote:
> O_LARGEFILE works great on my 32-bit platform.
>
> Is this an ABI bug? O_LARGEFILE should be OK for 32-bit processes.

That's fine if the 32-bit process wants to have O_LARGEFILE ... but not
all of them do ... some 32-bit binaries are compiled without O_LARGEFILE
support, and will be surprised to have it given to them.

This is particularly an issue on ia64, where 32-bit processes may be
emulated in s/w ... by a 64-bit process.

-Tony

2005-05-10 06:51:08

by Anton Blanchard

[permalink] [raw]
Subject: Re: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3


Hi,

> In ia64 kernel, the O_LARGEFILE flag is forced when
> opening a file. This is problematic for execution of
> 32 bit processes, which are not largefile aware, either
> by SW emulation or by HW execution.
> For such processes, the problem is two-fold:
> 1) When trying to open a file that is larger than 4G
> the operation should fail, but it's not
> 2) Writing to offset larger than 4G should fail, but
> it's not
>
> The proposed patch takes advantage of the way 32 bit
> processes are identified in ia64 systems. Such
> processes have PER_LINUX32 for their personality. With
> the patch, the ia64 kernel will not enforce the O_LARGEFILE
> flag if the current process has PER_LINUX32 set.
> The behavior for all other architectures remains unchanged.

A 32 bit application should not be using the native open routine.

Sounds like you have a 64bit emulator running 32bit applications. The
other 64bit architectures need to be audited to make sure the
PER_LINUX32 flag is safe to use here.

Anton

2005-05-10 16:15:26

by Luck, Tony

[permalink] [raw]
Subject: Re: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3

Anton Blanchard wrote:
> A 32 bit application should not be using the native open routine.
>
> Sounds like you have a 64bit emulator running 32bit applications. The
> other 64bit architectures need to be audited to make sure the
> PER_LINUX32 flag is safe to use here.

Yes, this issue happens when using an emulator to "run" the 32-bit
application.

Yoav's patch leaves it to each architecture to decide how to
identify the emulated case. ia64 has been using PER_LINUX32
for this. If other 64-bit architectures ever need to do the
same thing, they can provide their own force_o_largefile()
macro. Right now, I don't think that any of them need this
because they aren't using emulators for 32-bit.

-Tony

2005-05-10 21:47:38

by Zach, Yoav

[permalink] [raw]
Subject: RE: [PATCH]: Don't force O_LARGEFILE for 32 bit processes on ia64 - 2.6.12-rc3



>-----Original Message-----
>From: David S. Miller [mailto:[email protected]]
>Sent: Tuesday, May 10, 2005 21:47
>To: [email protected]
>Cc: [email protected]; [email protected];
>[email protected]; Zach, Yoav
>Subject: Re: [PATCH]: Don't force O_LARGEFILE for 32 bit
>processes on ia64 - 2.6.12-rc3
>
>
>I really think these "emulators" should execute the compat
>syscalls and not the native 64-bit ones. That is where
>all of these problems come from.
>

Compat syscalls are not accessible to userland. Changing that
will be a major change, with impacts on security and all. I'm
not sure it worth the effort.

>And yes, as Anton stated, you need to audit every platform's
>compat layer to make sure this PER_LINUX32 thing doesn't break
>anything for them.
>

The patch has no impact at all on any arch other than ia64.

Thanks,
Yoav.