Bug 2777 - sshd crashes when getpwnam result is returned by libnss_systemd
Summary: sshd crashes when getpwnam result is returned by libnss_systemd
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 7.5p1
Hardware: ix86 Linux
: P5 trivial
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_7_7
  Show dependency treegraph
 
Reported: 2017-09-14 02:19 AEST by loqs
Modified: 2018-04-06 12:26 AEST (History)
2 users (show)

See Also:


Attachments
keep scrubbed copy of passwd struct (987 bytes, patch)
2018-01-05 14:58 AEDT, Damien Miller
dtucker: ok+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description loqs 2017-09-14 02:19:40 AEST
Downstream bug report https://bugs.archlinux.org/task/55570?project=1
https://github.com/openssh/openssh-portable/blob/d38f05dbdd291212bc95ea80648b72b7177e9f4e/sshd.c#L1643
If the result of this getpwnam called is supplied by libnss_systemd then the structure and all strings pointed to within the structure will be in a read only memory section.
https://github.com/openssh/openssh-portable/blob/d38f05dbdd291212bc95ea80648b72b7177e9f4e/sshd.c#L1648
explicit_bzero will then segfault attempting to write to that read only section.
POSIX.1-2008 http://pubs.opengroup.org/onlinepubs/9699919799/ forbids modifying the structure returned by getpwnam or the strings it points to.
Perhaps switch the call to getpwnam_r?
Comment 1 Damien Miller 2018-01-05 14:58:27 AEDT
Created attachment 3110 [details]
keep scrubbed copy of passwd struct

We can use the existing pwcopy() function to make a local, mutable copy and hope the system endpwent() does the right thing and scrubs the last returned passwd entry from memory.
Comment 2 Damien Miller 2018-01-23 16:03:56 AEDT
Fix committed, this will be in OpenSSH 7.7.
Comment 3 Damien Miller 2018-04-06 12:26:51 AEST
Close all resolved bugs after release of OpenSSH 7.7.