Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 29 Mar 2024 22:46:15 +0100
From: Solar Designer <solar@...nwall.com>
To: oss-security@...ts.openwall.com
Subject: Re: backdoor in upstream xz/liblzma leading to ssh server compromise

On Fri, Mar 29, 2024 at 12:19:26PM -0700, Andres Freund wrote:
> On 2024-03-29 19:44:05 +0100, Matthias Weckbecker wrote:
> > I've attached a yara rule to detect the *.o droplet you attached in the
> > email (liblzma_la-crc64-fast.o.gz).
> 
> Unfortunately xz 5.61 added further obfuscations, making it harder to
> detect. Should have made it clearer that the attached .o was from 5.60. Among
> others 5.61 removed the two symbols you're checking against here.  That's why
> Vegard's script looks for a specific instructions sequence, but obviously is
> also more obscure :/

Andres, maybe you (or Florian or someone else) can post the .o file from
5.61 as well (gzipped just like the previous one, please)?

On Fri, Mar 29, 2024 at 08:51:26AM -0700, Andres Freund wrote:
> openssh does not directly use liblzma. However debian and several other
> distributions patch openssh to support systemd notification, and libsystemd
> does depend on lzma.

It is indeed a security risk that sshd on major distros brings in so
many libraries.  For example, on RHEL 9.x and its rebuilds, "ldd sshd"
is 28 lines.  In the Rocky Linux SIG/Security override package, we've so
far reduced this to 13 lines, which is still a lot:

https://sig-security.rocky.page/packages/openssh

For systemd notification, I patched it (half a year ago, so not in
response to these new findings) to dlopen() libsystemd into a new sshd
child process that's briefly spawned on sshd service startup or restart,
notifies systemd, and exits.  I could probably also drop privileges in
that child process, but so far I didn't bother.  I just didn't want
those libraries to stay in the process address space after startup.

Luckily, RHEL is not affected by the xz backdoor anyway, but if it were
I think these changes would just happen to have prevented the backdoor
from working.  Indeed, it's still bad code that could run as root (and
even if not in sshd, then in other services that use libsystemd), so it
could have as well e.g. modified sshd on disk, but its current way of
dynamically plugging into sshd authentication wouldn't work.

I've attached the patch, which applies on top of Red Hat's patches.  If
using it in a package, explicit dependency on libsystemd (or the package
that provides it) should be added to the (sub)package with sshd, e.g.:

Requires: systemd-libs

That's because the package manager would no longer automatically detect
the dependency, which is now a soft one.

I took this approach back then in order not to drop functionality, but
I'd re-think it now.  Perhaps systemd notification isn't worth even the
reduced risk, and should be dropped completely.  For the latter, an edit
to the systemd unit file is needed, changing "Type=notify" to
"Type=simple", which should fit "sshd -D".

Not only Red Hat'ish distros, but also Debian and Ubuntu are similar in
this respect, and I think should want to make similar changes.

Alexander

View attachment "openssh-8.7p1-rocky-systemd.patch" of type "text/plain" (2053 bytes)

Powered by blists - more mailing lists

Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.