tty: fix a panic with INVARIANTS

watch'ing a tty triggers a refcount wraparound panic, take a reference
on fp after fget_cap_locked() to fix.

Reported by:    Michael Jung <mikej_at_paymentallianceintl.com>
Reviewed by:	hselasky, mjg
Fixes:          f40dd6c803 ("tty: switch ttyhook_register to use fget_cap_locked")
Differential Revision:	https://reviews.freebsd.org/D34335
This commit is contained in:
Robert Wing 2022-02-22 09:22:18 -09:00
parent 884ba43116
commit 0a2f498234

View File

@ -2083,6 +2083,8 @@ ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th,
FILEDESC_SLOCK(fdp);
error = fget_cap_locked(fdp, fd, cap_rights_init_one(&rights, CAP_TTYHOOK),
&fp, NULL);
if (error == 0 && !fhold(fp))
error = EBADF;
FILEDESC_SUNLOCK(fdp);
if (error != 0)
return (error);