From patchwork Fri Oct 20 12:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1852509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FIsP4WU2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SBkSF1pQRz23kP for ; Fri, 20 Oct 2023 23:30:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E0FE3858C27 for ; Fri, 20 Oct 2023 12:30:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F14333858D20 for ; Fri, 20 Oct 2023 12:29:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F14333858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F14333858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697804995; cv=none; b=x8MA3PJfMK7fyS6TUpWNCsuZTj0iTQJeUznb+AA4j0FcBTHKb2bp+SXJoYEzaVEWHYWfBUT14J8QhrgzkPEjx3TPMEf/uP6glVxTGmzWlPcRFGCFFEfhsXLYkkpftiYwuM28qxsiTtaZ7+UXzp2XKKqEhSI/uraOmbgTsEIQjlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697804995; c=relaxed/simple; bh=Dycsx0hpbqf5HZo15Id5fZnd8UUsKzWZlTKSO+NO8fI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jTDP8fBvGKURptiMEXrW3UixXKicWBT4MXde2KGvkHHmIaSvPNzvH/eONk2TWpFtG0N+BY8o7Rozv39ttswhpmNTT3mZtaEFrBweLCmtoiCQjE7jd5g3lVizgDGamNOWSncxTfOa5ddY2wjyYpCiLhuAO9Zl/IrCgB/Ad0k16Kw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697804993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Y+/aPCVcnKwty9UdhIoS3kO1pGru3z6HyjisOwndeuM=; b=FIsP4WU23x1ltV0+5znYIhxdSOIOPPnKw5irOePgZs7xbT27UUNCpvL/a+r9awG4lA0l29 X1o8zBLisgfiHofeYhmurskA+ijimuNHbEJUn57iC9lak3MnGZTUgOhp4NHXvj9uO9Mccm 1w5EADyArxDF2R7XELVyF3Q518fiM0o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-JviiI42_OF2b8BBPJWGxwQ-1; Fri, 20 Oct 2023 08:29:52 -0400 X-MC-Unique: JviiI42_OF2b8BBPJWGxwQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04AFA88B778 for ; Fri, 20 Oct 2023 12:29:52 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4DF28AF for ; Fri, 20 Oct 2023 12:29:51 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] elf: ldconfig should skip temporary files created by package managers Date: Fri, 20 Oct 2023 14:29:50 +0200 Message-ID: <87y1fxxyrl.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org This avoids crashes due to partially written files, after a package update is interrupted. Tested on x86_64-linux-gnu. Reviewed-by: Adhemerval Zanella --- NEWS | 4 +++- elf/ldconfig.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) base-commit: f5677d9cebb12edcd9301dbb5cf40f82618b46af diff --git a/NEWS b/NEWS index cc4b81f0ac..9432564444 100644 --- a/NEWS +++ b/NEWS @@ -40,7 +40,9 @@ Major new features: Deprecated and removed features, and other changes affecting compatibility: - [Add deprecations, removals and changes affecting compatibility here] +* The ldconfig program now skips file names containing ';' or ending in + ".tmp", to avoid examining temporary files created by the RPM and dpkg + package managers. Changes to build and runtime requirements: diff --git a/elf/ldconfig.c b/elf/ldconfig.c index d26eef1fb4..02387a169c 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -661,6 +661,31 @@ struct dlib_entry struct dlib_entry *next; }; +/* Skip some temporary DSO files. These files may be partially written + and lead to ldconfig crashes when examined. */ +static bool +skip_dso_based_on_name (const char *name, size_t len) +{ + /* Skip temporary files created by the prelink program. Files with + names like these are never really DSOs we want to look at. */ + if (len >= sizeof (".#prelink#") - 1) + { + if (strcmp (name + len - sizeof (".#prelink#") + 1, + ".#prelink#") == 0) + return true; + if (len >= sizeof (".#prelink#.XXXXXX") - 1 + && memcmp (name + len - sizeof (".#prelink#.XXXXXX") + + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0) + return true; + } + /* Skip temporary files created by RPM. */ + if (memchr (name, len, ';') != NULL) + return true; + /* Skip temporary files created by dpkg. */ + if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0) + return true; + return false; +} static void search_dir (const struct dir_entry *entry) @@ -711,18 +736,8 @@ search_dir (const struct dir_entry *entry) continue; size_t len = strlen (direntry->d_name); - /* Skip temporary files created by the prelink program. Files with - names like these are never really DSOs we want to look at. */ - if (len >= sizeof (".#prelink#") - 1) - { - if (strcmp (direntry->d_name + len - sizeof (".#prelink#") + 1, - ".#prelink#") == 0) - continue; - if (len >= sizeof (".#prelink#.XXXXXX") - 1 - && memcmp (direntry->d_name + len - sizeof (".#prelink#.XXXXXX") - + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0) - continue; - } + if (skip_dso_based_on_name (direntry->d_name, len)) + continue; if (asprintf (&file_name, "%s/%s", entry->path, direntry->d_name) < 0) error (EXIT_FAILURE, errno, _("Could not form library path")); if (opt_chroot != NULL)