Hello Thorsten,

Am 24.03.19 um 01:46 schrieb Thorsten Glaser:
> Bernhard Übelacker dixit:
> 
>> Now I wonder if a x32 binary doing a syscall getrusage to a 64bit
>> kernel is supposed to supply memory like "long" would be 8 bytes?
> 
> The x32 kernel is amd64, it’s just a userspace ABI, with a
> separate entry point in the kernel (OR’d a high bit in the
> syscall number).
> 
> long and pointer are 4 bytes, time_t is 8 bytes though.

I see that the syscall number gets modified to become 0x40000062.

But the syscall modifies 144 bytes, more than just the size of
variable ru1 of 88 bytes.

This 144 bytes is the size I could observe within amd64 userland.

Found also this bug at bugzilla.kernel.org [1].
That makes me _belive_ mksh/dietlibc should pick up
a definition of "struct rusage" of size 144.

Attached patch contains simple tests that fail also with a stack
smashing in the dietlibc test suite, when using 32-bit long.
Also contained a change to the struct definition to use 64-bit integer.
With that neither the test nor mksh fails like before.

Kind regards,
Bernhard

[1] https://bugzilla.kernel.org/show_bug.cgi?id=66701







benutzer@debian:~$ LANG=C strace /usr/lib/diet/bin/mksh
execve("/usr/lib/diet/bin/mksh", ["/usr/lib/diet/bin/mksh"], 0xffb969d0 /* 19 
vars */) = 0
arch_prctl(ARCH_SET_FS, 0xff9e3700)     = 0
getpid()                                = 1187
geteuid()                               = 1000
getpgid(0)                              = 1184
getppid()                               = 1184
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf777d000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf777c000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf777b000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf777a000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7779000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7778000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7777000
rt_sigaction(SIGINT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
rt_sigaction(SIGHUP, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGHUP, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7776000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7775000
open("/dev/tty", O_RDWR)                = 3
fcntl(3, F_DUPFD, 10)                   = 10
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
close(3)                                = 0
ioctl(10, TIOCGWINSZ, {ws_row=59, ws_col=179, ws_xpixel=0, ws_ypixel=0}) = 0
stat("/home/benutzer", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7774000
getuid()                                = 1000
getgid()                                = 1000
getegid()                               = 1000
fstat(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0), ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
fstat(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0), ...}) = 0
fcntl(0, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7773000
rt_sigaction(SIGTTOU, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
ioctl(10, TIOCGPGRP, [1184])            = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
setpgid(0, 1187)                        = 0
ioctl(10, TIOCSPGRP, [1187])            = 0
ioctl(10, TCGETS, {B38400 opost isig icanon echo ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7771000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf7770000
rt_sigaction(SIGWINCH, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGWINCH, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
open("/home/benutzer/.mkshrc", O_RDONLY) = -1 ENOENT (No such file or directory)
rt_sigaction(SIGALRM, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGALRM, {sa_handler=0x411800, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x425d60}, NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xf776e000
ioctl(10, TIOCGWINSZ, {ws_row=59, ws_col=179, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -echo ...}) = 0
write(2, "$ ", 2$ )                       = 2
read(0, "l", 1)                         = 1
write(2, "l", 1l)                        = 1
read(0, "s", 1)                         = 1
write(2, "s", 1s)                        = 1
read(0, " ", 1)                         = 1
write(2, " ", 1 )                        = 1
read(0, "n", 1)                         = 1
write(2, "n", 1n)                        = 1
read(0, "o", 1)                         = 1
write(2, "o", 1o)                        = 1
read(0, "t", 1)                         = 1
write(2, "t", 1t)                        = 1
read(0, "e", 1)                         = 1
write(2, "e", 1e)                        = 1
read(0, "x", 1)                         = 1
write(2, "x", 1x)                        = 1
read(0, "i", 1)                         = 1
write(2, "i", 1i)                        = 1
read(0, "s", 1)                         = 1
write(2, "s", 1s)                        = 1
read(0, "t", 1)                         = 1
write(2, "t", 1t)                        = 1
read(0, "i", 1)                         = 1
write(2, "i", 1i)                        = 1
read(0, "n", 1)                         = 1
write(2, "n", 1n)                        = 1
read(0, "g", 1)                         = 1
write(2, "g", 1g)                        = 1
read(0, "\r", 1)                        = 1
write(2, "\r\n", 2
)                     = 2
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
stat("/usr/local/bin/ls", 0xff9e31b8)   = -1 ENOENT (No such file or directory)
stat("/usr/bin/ls", {st_mode=S_IFREG|0755, st_size=129616, ...}) = 0
access("/usr/bin/ls", X_OK)             = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
fork()                                  = 1188
setpgid(1188, 1188)                     = 0
ioctl(10, TIOCSPGRP, [1188])            = 0
rt_sigsuspend([], 8ls: cannot access 'notexisting': No such file or directory
)                    = ? ERESTARTNOHAND (To be restarted if no handler)
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1188, si_uid=1000, 
si_status=2, si_utime=0, si_stime=0} ---
getrusage(RUSAGE_CHILDREN, {ru_utime={tv_sec=0, tv_usec=0}, ru_stime={tv_sec=0, 
tv_usec=0}, ...}) = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 2}], WNOHANG|WSTOPPED, NULL) = 
1188
getrusage(RUSAGE_CHILDREN, {ru_utime={tv_sec=0, tv_usec=0}, ru_stime={tv_sec=0, 
tv_usec=0}, ...}) = 0
wait4(-1, 0xff9e2c6c, WNOHANG|WSTOPPED, NULL) = -1 ECHILD (No child processes)
write(2, "smashed stack detected, program "..., 44smashed stack detected, 
program terminated.
) = 44
exit(127)                               = ?
+++ exited with 127 +++













(gdb) ptype ru1
type = struct rusage {
    struct timeval ru_utime;
    struct timeval ru_stime;
    long ru_maxrss;
    long ru_ixrss;
    long ru_idrss;
    long ru_isrss;
    long ru_minflt;
    long ru_majflt;
    long ru_nswap;
    long ru_inblock;
    long ru_oublock;
    long ru_msgsnd;
    long ru_msgrcv;
    long ru_nsignals;
    long ru_nvcsw;
    long ru_nivcsw;
}
(gdb) ptype struct timeval
type = struct timeval {
    time_t tv_sec;
    suseconds_t tv_usec;
}
(gdb) ptype time_t
type = long long
(gdb) ptype suseconds_t
type = long
(gdb) print sizeof(ru1.ru_utime)
$10 = 16
(gdb) print sizeof(ru1.ru_utime.tv_sec)
$11 = 8
(gdb) print sizeof(ru1.ru_utime.tv_usec)
$12 = 4



set width 0
set pagination off
directory /tmp/source/mksh/orig/mksh-57/debian/upstream
b getrusage
display/i $pc
cont
cont




benutzer@debian:~$ gdb -q --pid $(pidof mksh)
Attaching to process 851
Reading symbols from /usr/lib/diet/bin/mksh...Reading symbols from 
/usr/lib/debug/.build-id/fc/c29d2d80c071be01063254db1a2ee14ae20fa4.debug...done.
done.
0x004253e0 in __unified_syscall ()
(gdb) set width 0
(gdb) set pagination off
(gdb) directory /tmp/source/mksh/try1/mksh-57/debian/upstream
Warning: /tmp/source/mksh/try1/mksh-57/debian/upstream: Datei oder Verzeichnis 
nicht gefunden.
Source directories searched: 
/tmp/source/mksh/try1/mksh-57/debian/upstream:$cdir:$cwd
(gdb) b getrusage
Breakpoint 1 at 0x42546a
(gdb) cont
Continuing.
[Detaching after fork from child process 858]

Breakpoint 1, 0x0042546a in getrusage ()
(gdb) cont
Continuing.

Breakpoint 1, 0x0042546a in getrusage ()
(gdb) display/i $pc
1: x/i $pc
=> 0x42546a <getrusage>:        mov    $0x62,%al
(gdb) stepi
0x0042546c in getrusage ()
1: x/i $pc
=> 0x42546c <getrusage+2>:      jmpq   0x4253d1 <__unified_syscall>
(gdb) 
0x004253d1 in __unified_syscall ()
1: x/i $pc
=> 0x4253d1 <__unified_syscall>:        mov    $0x0,%ah
(gdb) 
0x004253d3 in __unified_syscall ()
1: x/i $pc
=> 0x4253d3 <__unified_syscall+2>:      movzwl %ax,%eax
(gdb) 
0x004253d6 in __unified_syscall ()
1: x/i $pc
=> 0x4253d6 <__unified_syscall+5>:      or     $0x40000000,%eax
(gdb) 
0x004253db in __unified_syscall ()
1: x/i $pc
=> 0x4253db <__unified_syscall+10>:     mov    %rcx,%r10
(gdb) 
0x004253de in __unified_syscall ()
1: x/i $pc
=> 0x4253de <__unified_syscall+13>:     syscall 
(gdb) print/x $eax
$1 = 0x40000062
(gdb) up
#1  0x004138aa in j_sigchld (sig=<optimized out>) at ../../jobs.c:1369
1369    ../../jobs.c: Datei oder Verzeichnis nicht gefunden.
(gdb) print &ru1
$2 = (struct rusage *) 0xffbf78d0
(gdb) down
#0  0x004253de in __unified_syscall ()
(gdb) x/150xb 0xffbf78d0
0xffbf78d0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78d8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7900:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7908:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7910:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7918:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7920:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7928:     0x00    0x00    0x00    0x00    0x60    0x7f    0xc1    0xfe
0xffbf7930:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7938:     0xfc    0xff    0xff    0xff    0xff    0xff    0xff    0xff
0xffbf7940:     0x02    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7948:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7950:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7958:     0x01    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7960:     0x0c    0xc4    0x7d    0xf7    0x00    0x00
(gdb) print *(char*)0xffbf795f
$3 = 0 '\000'
(gdb) set *(char*)0xffbf795f = 0xaa
(gdb) x/150xb 0xffbf78d0           
0xffbf78d0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78d8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7900:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7908:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7910:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7918:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7920:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7928:     0x00    0x00    0x00    0x00    0x60    0x7f    0xc1    0xfe
0xffbf7930:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7938:     0xfc    0xff    0xff    0xff    0xff    0xff    0xff    0xff
0xffbf7940:     0x02    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7948:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7950:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7958:     0x01    0x00    0x00    0x00    0x00    0x00    0x00    0xaa
0xffbf7960:     0x0c    0xc4    0x7d    0xf7    0x00    0x00
(gdb) disassemble $pc-0x20,$pc+0x10
Dump of assembler code from 0x4253be to 0x4253ee:
   0x004253be <c_typeset+1516>: or     (%rax),%al
   0x004253c0 <c_typeset+1518>: add    %al,0x5d5b38c4(%rbx)
   0x004253c6 <c_typeset+1524>: pop    %r12
   0x004253c8 <c_typeset+1526>: pop    %r13
   0x004253ca <c_typeset+1528>: pop    %r14
   0x004253cc <c_typeset+1530>: pop    %r15
   0x004253ce <c_typeset+1532>: retq   
   0x004253cf <exit+0>: mov    $0x3c,%al
   0x004253d1 <__unified_syscall+0>:    mov    $0x0,%ah
   0x004253d3 <__unified_syscall+2>:    movzwl %ax,%eax
   0x004253d6 <__unified_syscall+5>:    or     $0x40000000,%eax
   0x004253db <__unified_syscall+10>:   mov    %rcx,%r10
=> 0x004253de <__unified_syscall+13>:   syscall 
   0x004253e0 <__unified_syscall+15>:   cmp    $0xffffffffffffff7c,%rax
   0x004253e6 <__unified_syscall+21>:   jbe    0x4253f7 <__unified_syscall+38>
   0x004253e8 <__unified_syscall+23>:   neg    %eax
   0x004253ea <__unified_syscall+25>:   push   %rax
   0x004253eb <__unified_syscall+26>:   callq  0x425834 <__errno_location>
End of assembler dump.
(gdb) stepi
0x004253e0 in __unified_syscall ()
1: x/i $pc
=> 0x4253e0 <__unified_syscall+15>:     cmp    $0xffffffffffffff7c,%rax
(gdb) x/150xb 0xffbf78d0
0xffbf78d0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78d8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e0:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78e8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f0:     0x38    0x07    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf78f8:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7900:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7908:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7910:     0x56    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7918:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7920:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7928:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7930:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7938:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7940:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7948:     0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7950:     0x03    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0xffbf7958:     0x01    0x00    0x00    0x00    0x00    0x00    0x00    0x00    
         <<<<<<<<<<<< 
0xffbf7960:     0x0c    0xc4    0x7d    0xf7    0x00    0x00


--> syscall wrote up to 0xffbf795f -> 0xffbf78d0 + 144 -> like long would be 64 
bit




wget 
http://192.168.178.25:9999/debian-9-stretch-deb.debian.org/pool/main/l/linux/linux-image-4.9.0-8-amd64_4.9.144-3_amd64.deb
-> Already the case with Stretch kernel amd64 + Buster userland x32



benutzer@debian:~$ grep -i -E "rusage.*98" /usr/include -Rn
/usr/include/x86_64-linux-gnux32/asm/unistd_x32.h:91:#define __NR_getrusage 
(__X32_SYSCALL_BIT + 98)
/usr/include/x86_64-linux-gnux32/asm/unistd_64.h:102:#define __NR_getrusage 98
benutzer@debian:~$ grep -i -E "__X32_SYSCALL_BIT" /usr/include -Rn              
                        
/usr/include/x86_64-linux-gnux32/asm/unistd.h:6:#define __X32_SYSCALL_BIT       
0x40000000
...




https://bugzilla.kernel.org/show_bug.cgi?id=66701




##############



apt install strace git dh-exec

mkdir /tmp/source/dietlibc/orig -p
cd    /tmp/source/dietlibc/orig
apt source dietlibc
cd

cd /tmp/source/dietlibc
cp orig try1 -a
cd try1/dietlibc-0.34~cvs20160606
git init
git add .
git config user.name "..."
git config user.email "..."
git commit -m "Initial commit"
# changes
dpkg-buildpackage -b

dpkg -i /tmp/source/dietlibc/try1/dietlibc-dev_0.34~cvs20160606-10_x32.deb

dpkg -i /tmp/source/mksh/try1/mksh_57-1_x32.deb 
/tmp/source/mksh/try1/mksh-dbgsym_57-1_x32.deb


From bb9b66b56163b868b857eeb925d4bcbdf76926ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= <bernha...@mailbox.org>
Date: Sun, 24 Mar 2019 13:33:00 +0100
Subject: [PATCH] Use 64-bit long for structs rusage and rlimit on x32, add
 simple tests for getrusage and getrlimit.

https://bugs.debian.org/925359
---
 debian/unittests/getrlimit.c | 18 ++++++++++++++++++
 debian/unittests/getrusage.c | 18 ++++++++++++++++++
 debian/unittests/suite.sh    |  2 ++
 include/sys/resource.h       | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)
 create mode 100644 debian/unittests/getrlimit.c
 create mode 100644 debian/unittests/getrusage.c

diff --git a/debian/unittests/getrlimit.c b/debian/unittests/getrlimit.c
new file mode 100644
index 0000000..7bb6728
--- /dev/null
+++ b/debian/unittests/getrlimit.c
@@ -0,0 +1,18 @@
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <stdio.h>
+#include <errno.h>
+
+int main()
+{
+  int r;
+  struct rlimit rl;
+
+  r = getrlimit(RLIMIT_STACK, &rl);
+  if (r != 0) {
+    fprintf(stderr, "error: getrusage(RUSAGE_SELF) didn't succeed: %d\n", errno);
+    return 1;
+  }
+
+  return 0;
+}
diff --git a/debian/unittests/getrusage.c b/debian/unittests/getrusage.c
new file mode 100644
index 0000000..927ab8e
--- /dev/null
+++ b/debian/unittests/getrusage.c
@@ -0,0 +1,18 @@
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <stdio.h>
+#include <errno.h>
+
+int main()
+{
+  int r;
+  struct rusage ru;
+
+  r = getrusage(RUSAGE_SELF, &ru);
+  if (r != 0) {
+    fprintf(stderr, "error: getrusage(RUSAGE_SELF) didn't succeed: %d\n", errno);
+    return 1;
+  }
+
+  return 0;
+}
diff --git a/debian/unittests/suite.sh b/debian/unittests/suite.sh
index abbf6c1..30f9182 100755
--- a/debian/unittests/suite.sh
+++ b/debian/unittests/suite.sh
@@ -17,6 +17,8 @@ debian/unittests/atexit.c
 debian/unittests/fopen.c
 debian/unittests/socketfns.c
 debian/unittests/pselect.c
+debian/unittests/getrusage.c
+debian/unittests/getrlimit.c
 test/alarm.c
 test/bsearch.c
 test/byteswap.c
diff --git a/include/sys/resource.h b/include/sys/resource.h
index b05b78f..bae131e 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -10,6 +10,37 @@ __BEGIN_DECLS
 #define RUSAGE_CHILDREN	(-1)
 #define RUSAGE_BOTH	(-2)		/* sys_wait4() uses this */
 
+
+#if defined( __x86_64__ ) && defined( __ILP32__ )
+
+/* for X32 */
+
+struct	rusage {
+  struct timeval ru_utime;	/* user time used */
+  struct timeval ru_stime;	/* system time used */
+  int64_t ru_maxrss;		/* maximum resident set size */
+  int64_t ru_ixrss;		/* integral shared memory size */
+  int64_t ru_idrss;		/* integral unshared data size */
+  int64_t ru_isrss;		/* integral unshared stack size */
+  int64_t ru_minflt;		/* page reclaims */
+  int64_t ru_majflt;		/* page faults */
+  int64_t ru_nswap;		/* swaps */
+  int64_t ru_inblock;		/* block input operations */
+  int64_t ru_oublock;		/* block output operations */
+  int64_t ru_msgsnd;		/* messages sent */
+  int64_t ru_msgrcv;		/* messages received */
+  int64_t ru_nsignals;		/* signals received */
+  int64_t ru_nvcsw;		/* voluntary context switches */
+  int64_t ru_nivcsw;		/* involuntary " */
+};
+
+struct rlimit {
+  uint64_t rlim_cur;
+  uint64_t rlim_max;
+};
+
+#else
+
 struct	rusage {
   struct timeval ru_utime;	/* user time used */
   struct timeval ru_stime;	/* system time used */
@@ -34,6 +65,8 @@ struct rlimit {
   unsigned long	rlim_max;
 };
 
+#endif
+
 #define PRIO_MIN	(-20)
 #define PRIO_MAX	20
 
-- 
2.20.1

Reply via email to