x32 mishandles various 64bit syscalls when tracing i386 32bit

Dmitry V. Levin ldv at altlinux.org
Thu May 2 01:27:15 UTC 2013


On Wed, May 01, 2013 at 08:36:22PM -0400, Mike Frysinger wrote:
> in writing a small testcase for stat64, i also poked some other funcs and they 
> fail too:
> 
> $ cat test.c
> #define _GNU_SOURCE
> #define _FILE_OFFSET_BITS 64
> #define _LARGEFILE_SOURCE
> #define _LARGEFILE64_SOURCE
> 
> #include <fcntl.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
> int main(int argc, char *argv[]) {
>         struct stat st;
>         truncate(argv[1], (unsigned long long)10 * 1024 * 1024 * 1024);
>         ftruncate(-1, (unsigned long long)10 * 1024 * 1024 * 1024);
>         stat(argv[1], &st);
>         printf("%llu\n", (unsigned long long)st.st_size);
>         readahead(-1, st.st_size, 1);
>         return 0;
> }
> 
> $ gcc test.c -m32 -o a.out32 -Wall 
> $ ./strace  -v ./a.out32 f
> ...
> [ Process PID=3083 runs in 32 bit mode. ]
> ...
> truncate64("f", 2147483648)             = 0
> ftruncate64(-1, 2147483648)             = -1 EBADF (Bad file descriptor)
> readahead(-1, 4289292220, 2)            = -1 EBADF (Bad file descriptor)
> ...
> 
> but if i use strace compiled for x86_64 (64bit), it decodes fine.

This patch should fix readahead and other cases where printllval is used
for decoding.  I'm not sure about a proper fix for truncate64/ftruncate64,
maybe removing odd redirections from linux/x32/syscallent1.h would be
enough?

diff --git a/util.c b/util.c
index 4e21d9f..e00c9a6 100644
--- a/util.c
+++ b/util.c
@@ -208,7 +208,15 @@ printllval(struct tcb *tcp, const char *format, int arg_no)
 	 */
 	tprintf(format, tcp->u_arg[arg_no]);
 	arg_no++;
-#elif defined LINUX_MIPSN32 || defined X32
+#elif defined X32
+	if (current_personality == 0) {
+		tprintf(format, tcp->ext_arg[arg_no]);
+		arg_no++;
+	} else {
+		tprintf(format, LONG_LONG(tcp->u_arg[arg_no], tcp->u_arg[arg_no + 1]));
+		arg_no += 2;
+	}
+#elif defined LINUX_MIPSN32
 	tprintf(format, tcp->ext_arg[arg_no]);
 	arg_no++;
 #else


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20130502/6720df29/attachment.bin>


More information about the Strace-devel mailing list