lsds / sgx-lkl-musl

Modified musl libc for SGX-LKL
Other
13 stars 9 forks source link

check for read/readv if file descriptor is actually a terminal #4

Open Mic92 opened 5 years ago

Mic92 commented 5 years ago

There is a shortcut, which delegates read/readv of the file descriptor 0 (usually stdin) to a host read/readv:

https://github.com/lsds/sgx-lkl-musl/blob/0408574aa0bc73be809171bf15bf4e37b8639425/src/internal/syscall.h#L182

This becomes a problem if some program has used dup2 to alter the file descriptor association. This is the case for dd. The fix is not so obvious but maybe there is a way to check if fd 0 is actually the host tty.

Mic92 commented 5 years ago

Here is the corresponding busybox implementation: https://git.busybox.net/busybox/tree/coreutils/dd.c?id=65741d004ee91c5a710559ae4f1664f25009255e#n447