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: f40dd6c8034b ("tty: switch ttyhook_register to use fget_cap_locked")
Differential Revision: https://reviews.freebsd.org/D34335
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);