Public bug reported:

When ssh-add is started without a controlling TTY
and with SIGTTOU/SIGTTIN set to SIG_IGN in the parent (e.g. a systemd
service unit, or a daemon that ignores job-control signals), readpassphrase()
spins with high CPU indefinitely and never prompts or exits.

Root cause: after installing its own handlers, readpassphrase() reads from
/dev/tty and receives SIGTTIN or SIGTTOU.  The handler sets signo[i]=1 and
the read returns EINTR.  readpassphrase then restores the original SIG_IGN
disposition and re-raises the signal via kill(getpid(), i).  Because the
disposition is now SIG_IGN the kill() is a no-op, but need_restart was
already set to 1, so execution does "goto restart".  The next iteration
re-opens /dev/tty, writes the prompt to stderr, hits SIGTTIN/SIGTTOU again,
and the loop repeats forever.

Fix: before setting need_restart for SIGTSTP/SIGTTIN/SIGTTOU, check
whether the saved (original) handler was SIG_IGN.  If it was, skip the
restart -- readpassphrase falls through and returns NULL, letting the
caller handle the error.

See AI-aided patch attached.

** Affects: openssh (Ubuntu)
     Importance: Undecided
         Status: New

** Patch added: "Fix: before setting need_restart for SIGTSTP/SIGTTIN/SIGTTOU, 
check whether the saved (original) handler was SIG_IGN.  If it was, skip the 
restart -- readpassphrase falls through and returns NULL, letting the caller 
handle the error."
   
https://bugs.launchpad.net/bugs/2157917/+attachment/5978457/+files/patch.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2157917

Title:
  readpassphrase() spins with high CPU indefinitely and never prompts or
  exits.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/2157917/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to