mailing list of musl libc
 help / color / mirror / code / Atom feed
* isatty false positives and device state clobbering
@ 2015-01-31  3:29 Rich Felker
  2015-01-31  3:45 ` Solar Designer
  2015-01-31  4:01 ` Rich Felker
  0 siblings, 2 replies; 5+ messages in thread
From: Rich Felker @ 2015-01-31  3:29 UTC (permalink / raw)
  To: musl

As can be seen by strace, the TCGETS ioctl used by
isatty/fdopen/__stdout_write to determine whether a file descriptor is
a terminal is aliased by the SNDCTL_TMR_TIMEBASE ioctl for OSS sound
devices. This is an utterly stupid legacy mistake, but it means the
ioctl could spuriously succeed and change the state (time base) of a
midi sequencer device when it's intended just to query whether the
device is a terminal.

Even though it's unlikely to arise in practice, I'd like to find a
clean solution to the problem. I see two general approaches:

1. Use fstat first and blacklist the sound device major before using
   the ioctl, or even hard-code a list of tty majors and determine
   positive tty status by device number.

2. Find an ioctl that doesn't clash with OSS (or anything else, but
   OSS is the only driver I know with this bogus ioctl space collision
   with ttys) and that doesn't change the tty state, and use that
   instead.

I strongly prefer strategy 2; hard-coding device numbers seems really
backwards and precludes portability of source/binaries to platforms
that provide identical names and userspace API/ABI but different
device numbering.

OSS seems to use the range 0x5401 to 0x5408, so some possible
candidates for strategy 2 seem to be:

#define TIOCGPGRP       0x540F
#define TIOCOUTQ        0x5411
#define TIOCGWINSZ      0x5413
#define FIONREAD        0x541B

Perhaps TIOCGPGRP is best if it works for ttys that aren't the
controlling tty for a process group, since it corresponds to a
standard POSIX feature and would need to be present on any system
where the tcgetpgrp() is implemented via ioctl. The others are
nonstandard but widely supported extensions for querying terminal
buffer state and window size.

It's also worth checking whether these are defined differently on any
particular archs (e.g. mips, uhg) and whether the definitions there
might clash with OSS ioctl numbers, in which case selecting a
different one would be preferable.

Rich


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-31 17:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-31  3:29 isatty false positives and device state clobbering Rich Felker
2015-01-31  3:45 ` Solar Designer
2015-01-31  4:01 ` Rich Felker
2015-01-31 15:20   ` M Farkas-Dyck
2015-01-31 17:33   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).