From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 89A0C20248 for ; Thu, 18 Apr 2019 12:02:02 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; q=dns; s=default; b=FdOws oyKB1ScbaJfz/PUujexQ9i48TOPtfE+qLDAomTi48atclRJtu6eOhRtyVPbAZxGX N7stxxVPm5K4T7i2ObwpqMRL4qtITwSnGdBzdKDIiQyD/gwDuM1VvmMy5HhvifVT biZm9ngVHNZZkG0ULvFq+p6SpCMqe8UHOOS65o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; s=default; bh=cEkqvwe+HYB hi1fDpO3F7xlvvyY=; b=kd82xOeBHXe8FBgVVmtS/H6lbqwZIrxoQ4rvacEJL9A Y5gXSrqhRVCrRw5TzRN0pA3k7cOAa4HD4jRRLXznOl3N2nIAMkc8ZuHs4nAwE/9f Ijq2Jt8UFIVoUuSQr4Ey80CiI/8q1KF+nS95nB0rqDfODTVDUWG2DA27c+gkkGTg = Received: (qmail 61465 invoked by alias); 18 Apr 2019 12:02:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 61450 invoked by uid 89); 18 Apr 2019 12:01:59 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mx1.redhat.com From: Florian Weimer To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] Avoid concurrency problem in ldconfig (bug 23973) References: Date: Thu, 18 Apr 2019 14:01:55 +0200 In-Reply-To: (Andreas Schwab's message of "Thu, 14 Feb 2019 17:51:22 +0100") Message-ID: <87bm13y11o.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain * Andreas Schwab: > Use a unique name for the temporary file when updating the ld.so cache, so > that two concurrent runs of ldconfig don't write to the same file. > > * elf/cache.c (save_cache): Use unique temporary name. > (save_aux_cache): Likewise. The downside of this change is that if ldconfig is interrupted, the temporary file never goes away. Ideally, we would use O_TMPFILE if supported by the (file) system, but that can get quite involved. > diff --git a/elf/cache.c b/elf/cache.c > index b8e9e6ccc3..ec7d94b0bc 100644 > --- a/elf/cache.c > +++ b/elf/cache.c > @@ -427,12 +427,12 @@ save_cache (const char *cache_name) > /* Write out the cache. */ > > /* Write cache first to a temporary file and rename it later. */ > - char *temp_name = xmalloc (strlen (cache_name) + 2); > - sprintf (temp_name, "%s~", cache_name); > + char *temp_name; > + if (asprintf (&temp_name, "%s.XXXXXX", cache_name) < 0) > + error (EXIT_FAILURE, errno, _("Can't allocate temporary name for cache file")); > > /* Create file. */ > - int fd = open (temp_name, O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, > - S_IRUSR|S_IWUSR); > + int fd = mkostemp (temp_name, O_NOFOLLOW); I think you can use mkstemp because O_NOFOLLOW is implied by its use of O_EXCL. > + int fd = mkostemp (temp_name, O_NOFOLLOW); Likewise. Thanks, Florian