[PATCH] Fix ioctl() wrappers for 64-bit systems
Nate Case
ncase at xes-inc.com
Fri Apr 11 17:41:28 UTC 2008
On Fri, 2008-04-11 at 02:14 +0200, Denys Vlasenko wrote:
> I want to understand the failure. Please apply this patch,
> run failing getty and let us know what did you see.
Here is the output with your debug patch applied:
# ./busybox getty -L ttyS0 115200 vt100
getty: getty_main: request 403c7413 argp 0xfffffafec30
getty: request 403c7413 argp 0xfffffafec30
xpedite8000 login: root
getty: termios_final: request 803c7414 argp 0xfffffafec30
getty: request 803c7414 argp 0xfffffafec30
getty: ttyS0: TCSETS: Invalid argument
>From this output, everything looks fine. It's the actual system call
that gets the bogus argument. I made a simple standalone test case that
demonstrates this same weird behavior:
---[snip]---
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <termios.h>
#include <errno.h>
#include <asm/ioctls.h>
void ioctl_wrapper(int fd, int request, void *argp)
{
printf("ioctl_wrapper: req = %x, argp = %p\n", request, argp);
if (ioctl(fd, request, argp) < 0) {
printf("ioctl_wrapper() failed!\n");
exit(-2);
}
printf("ioctl_wrapper() success!\n");
}
int main(void)
{
int res;
struct termios termios;
printf("main TCGETS: req = %x, argp = %p\n", TCGETS, &termios);
ioctl_wrapper(0, TCGETS, &termios);
printf("main TCSETS: req = %x, argp = %p\n", TCSETS, &termios);
ioctl_wrapper(0, TCSETS, &termios);
}
---[snip]---
Running on i386:
$ ./ioctl-bug
main TCGETS: req = 5401, argp = 0xbff9da84
ioctl_wrapper: req = 5401, argp = 0xbff9da84
ioctl_wrapper() success!
main TCSETS: req = 5402, argp = 0xbff9da84
ioctl_wrapper: req = 5402, argp = 0xbff9da84
ioctl_wrapper() success!
Running on ppc64:
$ ./ioctl-bug
main TCGETS: req = 403c7413, argp = 0xfffffebf640
ioctl_wrapper: req = 403c7413, argp = 0xfffffebf640
ioctl_wrapper() success!
main TCSETS: req = 803c7414, argp = 0xfffffebf640
ioctl_wrapper: req = 803c7414, argp = 0xfffffebf640
ioctl_wrapper() failed!
Running on AMD64:
$ ./ioctl-bug.amd64
main TCGETS: req = 5401, argp = 0x7fff956cd5d0
ioctl_wrapper: req = 5401, argp = 0x7fff956cd5d0
ioctl_wrapper() success!
main TCSETS: req = 5402, argp = 0x7fff956cd5d0
ioctl_wrapper: req = 5402, argp = 0x7fff956cd5d0
ioctl_wrapper() success!
So it doesn't appear to really affect all 64-bit systems since it worked
on x86-64. It's also interesting that it seems to specifically affect
TCSETS and not TCGETS.
- Nate Case <ncase at xes-inc.com>
More information about the busybox
mailing list