Skip to content

Commit ebd7ccf

Browse files
committed
fix(tty): pin PTY peer during slave open
Hold a strong reference to the PTY master before publishing an in-flight slave open. Without this pin, the last master close can drop the weak peer between begin_slave_open() and pty_common_open(), exposing an internal ENODEV race to userspace. Return EIO when the peer is already gone, matching Linux pts open semantics, while preserving the existing opening/active accounting that prevents premature devpts index reuse. Signed-off-by: longjin <longjin@dragonos.org>
1 parent 9af39f0 commit ebd7ccf

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

kernel/src/driver/tty/pty/unix98pty.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ impl TtyOperation for Unix98PtyDriverInner {
814814
if subtype == TtyDriverSubType::PtySlave {
815815
if let Some(hook_arc) = tty.private_fields() {
816816
if let Some(hook) = hook_arc.as_any().downcast_ref::<PtyDevPtsLink>() {
817+
// Pin the master before publishing this in-flight slave
818+
// open. The link is weak, so the last master file could
819+
// otherwise drop it between begin_slave_open() and
820+
// pty_common_open(), leaking ENODEV from the latter.
821+
// A concurrent master close is reported as EIO below,
822+
// matching Linux pts open semantics.
823+
let _master = tty.link().ok_or(SystemError::EIO)?;
817824
hook.begin_slave_open()?;
818825
return match PtyCommon::pty_common_open(tty) {
819826
Ok(()) => {

0 commit comments

Comments
 (0)