Bug 168434 - RHEL4: login's timeout can fail - needs to call siginterrupt(SIGALRM,1)
RHEL4: login's timeout can fail - needs to call siginterrupt(SIGALRM,1)
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: util-linux (Show other bugs)
4.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Karel Zak
Ben Levenson
:
Depends On:
Blocks: 168429
  Show dependency treegraph
 
Reported: 2005-09-15 17:59 EDT by Jason Vas Dias
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version: RHBA-2006-0061
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-03-07 13:04:32 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jason Vas Dias 2005-09-15 17:59:03 EDT
Description of problem:

Login tries to set a timeout in main(), login.c, @ line 334:

    signal(SIGALRM, timedout);
    alarm((unsigned int)timeout);
    signal(SIGQUIT, SIG_IGN);
    signal(SIGINT, SIG_IGN);

If any restartable system call is entered, such system calls can block 
indefinitely and will NOT be interrupted by the SIGALRM .

Login needs to call:
    siginterrupt(SIGALRM,1);

In order for restartable system calls to be interrupted.

This problem turned out to be one root cause of mgetty bug 167830, where 
the login program was run for a terminal for which it did not have read
or write permission (another problem).

In that case, login hung until manually killed by the administrator in its
tcsetattr(...) call at login.c, line 460:	
   /* Kill processes left on this tty */
	tcsetattr(0,TCSAFLUSH,&ttt);

This may possibly be a kernel bug - instead of returning EIO / EPERM, the
kernel continously sends an infinite number of SIGTTOU signals to the process .

An 80MB strace log file was generated, consisting of >1,000,000 repetitions
of :
4964  11:00:18 ioctl(0, SNDCTL_TMR_CONTINUE or TCSETSF, {c_iflags=0x106,
c_oflags=0x1805, c_cflags=0x800000be, c_lflags=0x3b, c_line=0,
c_cc="\x03\x1c\x7f\x15\x04\x00\x01\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"})
= ? ERESTARTSYS (To be restarted)
4964  11:00:18 --- SIGTTOU (Stopped (tty output)) @ 0 (0) ---
4964  11:00:18 --- SIGTTOU (Stopped (tty output)) @ 0 (0) ---

Login's alarm signal handler DOES get the SIGALRM after the 60 second timeout,
and timedout() is called; but then timedout2 calls ioctl(0, TCSETA, &ti), which
also blocks, because the ioctl(0, TCSETSF...) of tcsetattr is in progress, and
the exit() call of timedout2 is never reached, and the tcsetattr call is
restarted. 

This whole situation could be avoided by calling :
    siginterrupt(SIGALRM,1)
immediately after the 
    signal(SIGALRM, timedout)

I can reproduce this problem at will on Rawhide and RHEL-4 .
 
Version-Release number of selected component (if applicable):
ALL - util-linux-2.13-0.3.pre2 (Rawhide)
      util-linux-2.12a (RHEL-4)

How reproducible:
100%

Steps to Reproduce:
Cause login to be enter any restartable system call which then blocks.

For instance: if login is exec'd with its stdin/stdout directed to a 
terminal for which it does not have read/write access, the tcsetattr
call will be restarted indefinitely.

Actual results:
Login hangs indefinitely

Expected results:
Any blocking system call should be interrupted by the login timeout.
Login should exit with an error.

Additional info:

mgetty configuration to reproduce this problem available upon request.
Comment 1 Karel Zak 2005-10-03 10:31:28 EDT
Jason, thanks for perfect description of problem! (also bug #168436)

It will be fixed it in FC5, FC4 and added to RHEL proposed list.
Comment 7 Red Hat Bugzilla 2006-03-07 13:04:32 EST
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2006-0061.html

Note You need to log in before you can comment on or make changes to this bug.