summaryrefslogtreecommitdiff
path: root/sys/kern/tty_pty.c
AgeCommit message (Collapse)Author
2024-11-05remove VATTR_NULL() define, directly call vattr_null()Jonathan Gray
There used to be a predefined null vattr for !DIAGNOSTIC but that was removed in vnode.h rev 1.84 in 2007. ok semarie@ miod@
2022-09-02openpty() family of functions use /dev/ptm PTMGET to open a master+slave fdTheo de Raadt
pair, and also provides their names. Internally, 3 NDINIT+namei operations access /dev/[tp]ty[p-zP-T][0-9a-zA-Z], of these 2 followed unveil restrictions. I argue if you unveil /dev/ptm, (and not the 372 other nodes), you still want openpty() to provide you with working fd's, and the names, which the caller will probably never open manually, because the fd's are given. So change all NDINIT to use KERNELPATH, bypassing unveil. ok semarie
2022-07-02Remove unused device poll functions.Visa Hankala
Also remove unneeded includes of <sys/poll.h> and <sys/select.h>. Some addenda from jsg@. OK miod@ mpi@
2021-12-15Adjust pty and tty event filtersVisa Hankala
* Implement EVFILT_EXCEPT for ttys for HUP condition detection. This filter is used when pollfd.events has no read/write events. * Add HUP condition detection to filt_ptcwrite() and filt_ttywrite() to reflect ptcpoll() and ttpoll(). Only poll(2) and select(2) can utilize the code; kevent(2) should behave as before with EVFILT_WRITE. * Clear EV_EOF and __EV_HUP if the EOF/HUP condition ends. OK mpi@
2021-12-13Revise EVFILT_EXCEPT filtersVisa Hankala
Restrict the circumstances where EVFILT_EXCEPT filters trigger: * when out-of-band data is present and NOTE_OOB is requested. * when the channel is fully closed and consumer is poll(2). This should clarify the logic and suppress events that kqueue-based poll(2) does not except. OK mpi@
2021-10-24use NULL not 0 for pointer values in kernJonathan Gray
ok semarie@
2021-10-22Make EVFILT_EXCEPT handling separate from the read filter.Martin Pieuchot
This is a change of behavior and events wont be generated if there is something to read on the fd. Only EV_EOF or NOTE_OOB will now be reported. While here a new filter for FIFOs supporting EV_EOF and __EV_HUP. ok visa@
2021-02-08Do not hold onto the fdplock longer then needed. Release the lock afterClaudio Jeker
the initial falloc() calls and then regrab it for the fdinsert() or fdremove() calls respectiviely. Also move closef() outside of the lock. This replaces the previously reverted lock order change that was reverted. OK mvs@ visa@
2021-02-04Revert previous commit. The vnode returned by ptm_vn_open() is open andClaudio Jeker
can not simply be vrele()-ed on error. The code currently depends on closef() to do the cleanup. Reported-by: syzbot+b0e18235e96adf81883d@syzkaller.appspotmail.com
2021-02-04Prevent a lock order issue by shuffling code around. Instead of allocatingClaudio Jeker
the file descriptors early do it late. This way the fdplock is not held during the VFS operations. OK mvs@
2020-12-25Refactor klist insertion and removalVisa Hankala
Rename klist_{insert,remove}() to klist_{insert,remove}_locked(). These functions assume that the caller has locked the klist. The current state of locking remains intact because the kernel lock is still used with all klists. Add new functions klist_insert() and klist_remove() that lock the klist internally. This allows some code simplification. OK mpi@
2020-09-09Introduce a helper to check if a signal is ignored or masked by a thread.Martin Pieuchot
ok claudio@, pirofti@
2020-07-20Sigh. Only the ptyc case should tsleep in ttyretype, since others canTheo de Raadt
arrive in the wrong context. Found by jcs.
2020-07-14A pty write containing VDISCARD, VREPRINT, or various retyping cases ofTheo de Raadt
VERASE would perform (sometimes irrelevant) compute in the kernel which can be heavy (especially with our insufficient tty subsystem locking). Use tsleep_nsec for 1 tick in such circumstances to yield cpu, and also bring interruptability to ptcwrite() https://syzkaller.appspot.com/bug?extid=462539bc18fef8fc26cc ok kettenis millert, discussions with greg and anton
2020-06-22Extend kqueue interface with EVFILT_EXCEPT filter.Martin Pieuchot
This filter, already implemented in macOS and Dragonfly BSD, returns exceptional conditions like the reception of out-of-band data. The functionnality is similar to poll(2)'s POLLPRI & POLLRDBAND and it can be used by the kqfilter-based poll & select implementation. ok millert@ on a previous version, ok visa@
2020-06-15Set __EV_HUP when the conditions matching poll(2)'s POLLUP are found.Martin Pieuchot
This is only done in poll-compatibility mode, when __EV_POLL is set. ok visa@, millert@
2020-05-21Add missing ICANON check in filt_ptcwrite().Martin Pieuchot
ok millert@, visa@
2020-04-07Abstract the head of knote lists. This allows extending the lists,Visa Hankala
for example, with locking assertions. OK mpi@, anton@
2020-02-20Replace field f_isfd with field f_flags in struct filterops to allowVisa Hankala
adding more filter properties without cluttering the struct. OK mpi@, anton@
2020-01-11Convert infinite sleeps to tsleep_nsec(9).Martin Pieuchot
ok bluhm@
2019-12-31Use C99 designated initializers with struct filterops. In addition,Visa Hankala
make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
2019-07-19ttysleep(): drop unused timeout parametercheloha
All callers sleep indefinitely. With help from visa@. ok visa@, ratchov@, kn@
2019-03-11Bring back revision 1.91 now that vmd has been fixed, repeating theanton
previous commit message: When closing the slave end of a pty, generate an EOF event to any kqueue consumer of the master end. This behavior is equivalent to how pipes already behave with kqueue. Also, FreeBSD and NetBSD behaves the same way. ok deraadt@ millert@ visa@
2019-03-06Revert revision 1.91. It results in significant log spam whenTheo Buehler
running vmd, as observed by mlarkin and myself. discussed with anton and mlarkin
2019-03-04When closing the slave end of a pty, generate an EOF event to any kqueueanton
consumer of the master end. This behavior is equivalent to how pipes already behave with kqueue. Also, FreeBSD and NetBSD behaves the same way. ok deraadt@ millert@
2018-08-30Remove dead code related to tty allocation for ptys. Back in revision 1.17 ofanton
kern/tty_pty.c, allocation of ptys was made dynamic with the introduction of check_pty(). Every time a new struct pty is allocated its corresponding struct tty is also allocated. It's therefore no longer necessary to ensure that a pty has a tty allocated after calling check_pty(). ok deraadt@ millert@ mpi@ visa@
2018-08-29Initialize device numbers for newly allocated ptys. Prevents a panic caused byanton
the following: a new pty is allocated in which the kernel console output is redirected to, poll(2):ing from /dev/console at this point would be delegated to the device with the major number taken from the pty due to the earlier redirection. Since the pty does not have its correct device major assigned, the wrong device ends up being used. ok deraadt@ millert@
2018-08-05Decouple unveil from the pledge flags, by adding dedicated unveil flagsBob Beck
to the namei args. This fixes a bug where chmod would be allowed when with only READ. This also allows some further cleanup of some awkward things like PLEDGE_STAT that will follow Lots of assistence from semarie@ - thanks! ok semarie@
2018-06-18Put file descriptors on shared data structures when they are completelyMartin Pieuchot
setup, take 3. LARVAL fd still exist, but they are no longer marked with a flag and no longer reachable via `fd_ofiles[]' or the global linked list. This allows us to simplifies a lot code grabbing new references to fds. All of this is now possible because dup2(2) refuses to clone LARVAL fds. Note that the `fdplock' could now be release in all open(2)-like syscalls, just like it is done in accept(2). With inputs from Mathieu Masson, visa@, guenther@ and art@ Previous version ok bluhm@, ok visa@, sthen@
2018-06-05Revert introduction of fdinsert(), a sanitify check triggers whenMartin Pieuchot
closing a LARVAL file. Found the hardway by sthen@.
2018-06-02Put file descriptors on shared data structures when they are completelyMartin Pieuchot
setup. LARVAL fd still exist, but they are no longer marked with a flag and no longer reachable via `fd_ofiles[]'. This allows us to simplifies a lot code grabbing new references to fds. All of this is now possible because dup2(2) refuses to clone LARVAL fds. Note that the `fdplock' could now be release in all open(2)-like syscalls, just like it is done in accept(2). With inputs from Mathieu -, visa@, guenther@ and art@ ok visa@, bluhm@
2018-04-28Clean up the parameters of VOP_LOCK() and VOP_UNLOCK(). It is alwaysVisa Hankala
curproc that does the locking or unlocking, so the proc parameter is pointless and can be dropped. OK mpi@, deraadt@
2018-02-19Remove almost unused `flags' argument of suser().Martin Pieuchot
The account flag `ASU' will no longer be set but that makes suser() mpsafe since it no longer mess with a per-process field. No objection from millert@, ok tedu@, bluhm@
2018-01-08Translate the TIOCSBRK & TIOCCBRK ioctl(2)s issued on a pty(4) slave toMartin Pieuchot
corresponding user mode ioctls. If the master part of the pseudo terminal previously enabled TIOCUCNTL, it will now receive the TIOCUCNTL_{S,C}BRK commands. This allows to send BREAKS commands over a pty(4) independently of the serial terminal emulator used. Guidance and ok nicm@, ok ccardenas@, looks ok to deraadt@
2018-01-02Stop assuming <sys/file.h> will pull in fcntl.h when _KERNEL is defined.Philip Guenther
ok millert@ sthen@
2017-07-04some of this code was written in an era when spaces cost extra.Ted Unangst
add a little breathing room.
2017-02-11Add a flags argument to falloc() that lets it optionally set thePhilip Guenther
close-on-exec flag on the newly allocated fd. Make falloc()'s return arguments non-optional: assert that they're not NULL. ok mpi@ millert@
2016-05-24Remove two sysctls which were introduced only for development of theTheo de Raadt
ptm/pty subsystem, and got left behind. ok beck
2016-03-19Remove the unused flags argument from VOP_UNLOCK().natano
torture tested on amd64, i386 and macppc ok beck mpi stefan "the change looks right" deraadt
2016-01-28Convert to uiomove. Diff from Martin Natano.Stefan Kempf
2016-01-14Increase buffer sizes and watermarks for tty and pppStefan Fritsch
Use 115200 the default speed for buffer sizing in ttymalloc(). A lot of devices call ttymalloc(0) so this affects quite a few of them. Increases the buffer size for 9600 < baud <= 115200 from 1k to 4k. Make ppp use the lo/hi watermarks from the tty layer which are adjusted according to speed + buffer size. The previous fixed values of 100 and 400 were way too small Make pty call ttymalloc() with baud == 1000000, which is the common value used in the tree for "fast". ok deraadt@
2015-12-05remove stale lint annotationsTed Unangst
2015-11-02move the pledgenote annotation from `struct proc' to `struct nameidata'Sebastien Marie
pledgenote is used for annotate the policy for a namei context. So make it tracking the nameidata. It is expected for the caller to explicitly define the policy. It is a kernel bug to not do so. ok deraadt@
2015-10-28There are three situations where pty ioctl's result in a NDINIT.Theo de Raadt
NDINIT should be preceded by setting pledgenote to indicate what the operation is for.
2015-09-28easy size for free(); ok beckTheo de Raadt
2015-02-10First step towards making uiomove() take a size_t size argument:Miod Vallat
- rename uiomove() to uiomovei() and update all its users. - introduce uiomove(), which is similar to uiomovei() but with a size_t. - rewrite uiomovei() as an uiomove() wrapper. ok kettenis@
2014-11-18Nuke yet more obvious #include duplications.Kenneth R Westerback
ok miod@
2014-07-13use mallocarray where arguments are multipled. ok deraadtTed Unangst
2014-07-12add a size argument to free. will be used soon, but for now default to 0.Ted Unangst
after discussions with beck deraadt kettenis.
2014-07-09use explicit_bzero for stack and freed variablesTed Unangst