From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by sourceware.org (Postfix) with ESMTPS id E32BE3858408 for ; Mon, 1 Apr 2024 12:16:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E32BE3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E32BE3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.178 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711973816; cv=none; b=ebJ37GEWcRxTCMk/YXlRsGu+a4qo+JgPzVlW9NwE5t0dtXJWIvRKOm0QM3g5XJFeU1HWnbg1lmdGNJ0v+t6yA754AeGpI+W2vYf02InOZvufmegMCQhoFVRfjBwxvQ7CiKYCbHfzN4AKVTvfd7RJNTqFB4W1i8O/XyB9ELYt++I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711973816; c=relaxed/simple; bh=ZSpkChBoVWxSBUjx9s9KV9YgOcsMXJgeZ1X1tkysYyo=; h=MIME-Version:From:Date:Message-ID:Subject:To; b=bdvGl656qcsawBpekUQjRhNegmRhwM3WwKjaY1Iqo+adEqQNYnbIcuc4ev+pQkqq0TI85qGLF7VYEVQtslxV2AMxVTHwxnYNfiBCBFfw0FIdbX8x+tqI1I6sY/5FaRYm+jvh1pF6DRVvD/ffk0ilF828rG884iyHwv2e8SDCe74= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-6146858b425so11277367b3.3 for ; Mon, 01 Apr 2024 05:16:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711973812; x=1712578612; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZSpkChBoVWxSBUjx9s9KV9YgOcsMXJgeZ1X1tkysYyo=; b=eA2T62tMeNPuy/U8vGQcLTrb9fNOyd/sLHddimWDehYEiNZdhTjEkrxMjWJ6EG+57H Mvh9tRZHFU7l6gAKofWkkT6i5lqOTreJUNVqnalEde3a1LaRkmyYbaOS97PXKKHTc3ad XrfsjipTGX/uCt1AJhqseKqUrePspco8soYnGzLSw1SQveq5ZgoQLNAtauwW2xIc80h7 oWboBhSnPWZkQfLsjMeTksSy1wCmfnaVmX2YpGZ9t04ExFHneXmS6QYHE2OQSZTzGKCb KL5tcaHi9yEZQs21iMt9/aAs3jInTMNGpZzOgz6Gi2p6ynQNwAUBEiEYXXAYyEeMCifO 5Ksw== X-Forwarded-Encrypted: i=1; AJvYcCVTS15wAaEFIG3QF8kWgptxqn8ekrF+HfFrnFglVsTpthAD7SqlS4VpuBFk79c3zhs8KKo0hhDnYubDy7mclnow+LmH9JPsug== X-Gm-Message-State: AOJu0YzCsufwxivL2eeXMyTIi23e9BqyH9XeFAIaR97fksWbQvae7+ZP kV18C4RmkD1qOyUcm9dTadPm2oIHYG9nrTB3bzY7ZkRLSurc0CRHXv9U5Yg9s0w= X-Google-Smtp-Source: AGHT+IFZr0O3eXKLpcO4I0bpRtNpWGXI0ZjzCxzPv4Ytd/yZHUOfbQxdt9u17OjBBXJyEat/sLV2qg== X-Received: by 2002:a81:fe0a:0:b0:614:699c:4824 with SMTP id j10-20020a81fe0a000000b00614699c4824mr5876064ywn.31.1711973811812; Mon, 01 Apr 2024 05:16:51 -0700 (PDT) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com. [209.85.219.182]) by smtp.gmail.com with ESMTPSA id p9-20020a81ca09000000b006147c7f4377sm1208517ywi.18.2024.04.01.05.16.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Apr 2024 05:16:51 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-ddda842c399so2645982276.3 for ; Mon, 01 Apr 2024 05:16:51 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXNBoEcx+E0I7i7VHxuLtESsfPdOrwxj54u0ECtUEpGQz3mY7gmrljOprFgcJqXr6M9EWCe9Eq7lCbn+aSwMhmIYQ0hcBIJMA== X-Received: by 2002:a25:83c5:0:b0:dcc:ae3:d8a0 with SMTP id v5-20020a2583c5000000b00dcc0ae3d8a0mr7740246ybm.48.1711973811381; Mon, 01 Apr 2024 05:16:51 -0700 (PDT) MIME-Version: 1.0 References: <877chhe80o.fsf@gentoo.org> In-Reply-To: From: Luca Boccassi Date: Mon, 1 Apr 2024 12:16:40 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Remove dependency on libjansson To: Rui Ueyama Cc: Sam James , Fangrui Song , Binutils Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 1 Apr 2024 at 12:44, Rui Ueyama wrote: > > On Mon, Apr 1, 2024 at 7:38=E2=80=AFPM Luca Boccassi w= rote: > > > > On Mon, 1 Apr 2024 at 10:50, Sam James wrote: > > > > > > Fangrui Song writes: > > > > > > > On Sun, Mar 31, 2024 at 8:31=E2=80=AFPM Rui Ueyama wrote: > > > >> > > > >> Hi, > > > >> > > > >> The recent xz incident demonstrated that supply chain attacks are = a > > > >> real threat, and dependence on third-party libraries can have > > > >> significant consequences. > > > >> > > > >> In the wake of the incident, I propose we remove the dependency on > > > >> libjansson from GNU ld. > > > >> > > > >> First of all, why does GNU ld depend on libjansson which is a JSON > > > >> parsing library? GNU ld gained the `--package-metadata` option in = May > > > >> 2022 to embed a JSON string into a .note section for package > > > >> management for Fedora and other Linux distributions. At the same t= ime, > > > >> the dependency on libjansson, a library for parsing JSON-format > > > >> strings, was introduced to validate an argument for that option. I= f an > > > >> argument is not a valid JSON string, ld reports an error. If the > > > >> library is unavailable, or if `--disable-jansson` was passed to th= e > > > >> configure script, the library will not be linked and the error che= ck > > > >> will be disabled. By default, the library will be linked if it exi= sts. > > > >> > > > >> I opposed adding an extra dependency to GNU ld just for string > > > >> verification purposes because it didn't seem worth adding extra > > > >> dependency to the linker. LLVM lld and the mold linker also suppor= t > > > >> the option, but they do not verify if the argument is a valid JSON > > > >> string -- they simply treat it as an opaque string. If libjansson = is > > > >> unavailable, even GNU ld doesn't verify arguments. Therefore, the > > > >> verification is not trustworthy, and the reader must be prepared f= or a > > > >> malformed JSON string when reading a .note section. Moreover, > > > >> verifying a string is straightforward without the feature; you can > > > >> simply `echo` the string to pipe it to `jq` for verification befor= e > > > >> passing it to GNU ld. > > > >> > > > >> I just checked /usr/bin/ld on Ubuntu 24.04, which is set to be > > > >> released this month, and the dependency on libjansson was indeed > > > >> present. > > > >> > > > >> How much risk does it pose? Probably not much, as long as the libr= ary > > > >> is maintained properly. However, the stakes are high; if someone t= akes > > > >> control of the library and introduces malicious code, they could > > > >> execute a Ken Thompson-style supply chain attack. Since GNU ld is = used > > > >> to build essentially everything, the attacker could in theory gain= the > > > >> power to not just contaminate a specific program such as openssh, = but > > > >> every executable in an official Linux distribution image. I think = the > > > >> risk is not worth taking. I believe we just should remove the stri= ng > > > >> verification code and the dependency on the library from GNU ld. > > > >> > > > >> Rui Ueyama > > > > > > > > Thanks for bringing this up again. I support removing the json depe= ndency. > > > > > > > > I lightly expressed my concern > > > > https://sourceware.org/pipermail/binutils/2022-May/120846.html and > > > > there might be others unsure about the dependency as well. > > > > > > I'd like to hear bluca's take before making up my mind. Note that it'= s > > > also automagic right now IIRC (enabled if installed, not opt-in). > > > > > > But my take on it so far is that it doesn't sound worth it. > > > > $ apt-cache rdepends libjansson4 | wc -l > > 310 > > > > Sorry, but this looks to me like a knee-jerk reaction that misses the > > wood for the trees. The xz issue is that an extremely complex and > > sophisticated social engineering attack was planned and executed over > > multiple years. If it hadn't been on xz, it would have been on another > > project. Dropping dependencies left and right without thinking will > > not stop the next attack, as there is no shortage of overworked > > maintainers to try and abuse. In fact, avoiding common libraries and > > everyone reimplementing the wheel _increases_ the attack > > opportunities. > > > > The reason for this integration is that finding issues at build time > > is cheaper than finding them at runtime or release time. We rely on > > this in Fedora, Debian and Ubuntu to ensure valid data is written (in > > all packages in the former, in an increasing set of opt-ins in the > > latters) - in fact, validating input _before_ shipping binaries > > _improves_ security, rather than decreasing it, given the payload is > > parsed by a privileged component. > > > > So if it was removed upstream, we'd just have to patch it back in > > downstream in each interested distro - which if you recall, was > > exactly how sshd was exploited, due to the lack of an upstream common > > implementation. This is opt-in, so distributions that are not > > interested can just avoid enabling it, with no extra effort required. > > So please, leave it as-is. Thank you. > > I'd like to say that that's not an instinctive reaction to the xz > incident, as I expressed a concern when the dependency was being > introduced. I also want to say that I'm not trying to drop > dependencies left and right without thinking. Well, the email did start with: > The recent xz incident demonstrated that supply chain attacks are a real = threat, and dependence on third-party libraries can have significant conseq= uences. so it should be understandable why that's the impression it gave me. This feature has been present in binutils for 2 years now, and AFAIK caused zero issues so far (probably going to jinx it with this comment, but still). > I understand that the error check would be sometimes useful, but I'd > like to propose reevaluating its cost and benefit. IIUC, the > --package-metadata option is, as its name suggests, used by packaging > tools such as dpkg-dev or rpmbuild. My understanding is that this > option is not intended to be used directly by developers at large, but > rather, the JSON string is generated by a very limited set of > packaging tools from package description files and passed to the > linker. If that's the case, the string format check itself is an extra > measure to catch rare string construction bugs, given that JSON > strings are machine-generated and not manually crafted. The metadata comes from each package, so it is very much possible for errors to appear in one build but not another. And they would be hard to spot and expensive to fix, as they'd likely only be found when things go really wrong and the data is needed at runtime, or worse. > While we may still do extra checks for catching possible tooling bugs, > I wonder how difficult it would be to assign this additional > verification to jq or a similar tool instead of the linker. IIRC, dpkg > comes with a tool to scan all executables in a directory to find > packaging errors. Isn't it a better place to run the extra format > check? Would it be too complex to output the .note section contents > after linking and pipe them to jq to confirm the embedded string is a > valid JSON string? There's no such thing in dpkg. You might be thinking of Lintian, but that's an entirely separate tool, that is optional, runs long after the package is published and distributed, and is only seldomly checked (most maintainers just ignore it as it's informational only), and doesn't stop bad builds from being generated and released. It's also package-format-specific, so again every distribution would have to reimplement exactly the same check in different ways, which is just duplication of work for no gain. The intention here was to have bad input fail the build immediately, with no extra effort required from distributions or packagers, and it works very well for that. This is akin to suggesting that compilers shoudn't output warnings, but the job should just be left to static analyzers. The earlier problems are detected, the cheaper they are to fix, and the less impact they have. This is one of the few truisms of engineering.