[Bug 1597] New: During ssh login, the motd may not appear

bugzilla-daemon at bugzilla.mindrot.org bugzilla-daemon at bugzilla.mindrot.org
Thu May 14 05:58:12 EST 2009


https://bugzilla.mindrot.org/show_bug.cgi?id=1597

           Summary: During ssh login, the motd may not appear
           Product: Portable OpenSSH
           Version: 5.2p1
          Platform: ix86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: sshd
        AssignedTo: unassigned-bugs at mindrot.org
        ReportedBy: john.ata at baesystems.com


Created an attachment (id=1637)
 --> (http://bugzilla.mindrot.org/attachment.cgi?id=1637)
Flushed pending output  such as motd before execv of shell

In do_login (session.c), the routine do_motd() is called that writes to
the stdout stream.  Apparently, it may have been assumed that stdout
was line buffered because it was a pseudo terminal.  Even though stdio
is indeed a terminal, this may not be the correct assumption.  The
following sequence of events can occur:

1) Forked child "rexecs" sshd in main() with stdout pointing to a
non-tty device (accepted socket).
2) Because the stdout stream is not a terminal, the libc startup code
run immediately in the execed process will cause the stdout stream to
be fully buffered.
3) After some processing, do_exec_pty (session.c) is called which dup2
the the psedudo tty to fd 1.  The stdio buffering mode for the stdout
stream is not affected and is still fully buffered even though it is
now a terminal.
4) Process calls do_motd and calls fputs to the stdout stream for the
motd.  The data is now buffered but is not displayed even though it is
a terminal.
5) Process execs the shell.  Since the stdout stream is now a terminal,
the startup code in libc will cause the stdout stream to be line
buffered.  From this point forward, everything is ok.  However, the
buffered data from the motd will will lost.

Suggest a fflush(NULL) be called before the execv of the shell or
alternatively after do_motd writes to stdout.  Attached patch does the
former.

-- 
Configure bugmail: https://bugzilla.mindrot.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching the assignee of the bug.


More information about the openssh-bugs mailing list