From patchwork Fri Jan 12 11:07:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 859762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-89137-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="e8EBJ/vQ"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 3zJ0N871hbz9t34 for ; Fri, 12 Jan 2018 22:08:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= KmXRaS4JvT3Ipl0bkJeYub5NvkLQjYWelYLVEsdLR2/DVB7tzhr/bMcfnFRccWag YIJsb36X7Q9AhiO1E0NbUSORZAIj3e8udb+8g/5XcZq8MQ0FyqcPahcE9fvC5vNU KYLaFuMQPFdOad7yw59WW49Ax+hkR9sqKsQ1kqoUA94= 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:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=eMUEPe eDijL1A4Z3bc/QA1rXxCU=; b=e8EBJ/vQ/ubekLuBR7E2hJtzrxK1ArvOxFnP06 VRwu/NgLWxOsvAduGhZ5hz3WhyMa95thGJsBdkScSaxig9dabjyhrC1o/NlDY/lI MD/lPs6DNBIsCiMLcyVZKwrWJ/cfC78deJ23do66Emq05P5jRgS8CCVGJB7QGjMm Ne3fU= Received: (qmail 31661 invoked by alias); 12 Jan 2018 11:08:02 -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 Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 31644 invoked by uid 89); 12 Jan 2018 11:08:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Date: Fri, 12 Jan 2018 12:07:57 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] ldconfig: Call fsync on temporary files before renaming them [BZ #20890] User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20180112110757.D4D2440172552@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) If the system crashes before the file data has been written to disk, the file system recovery upon the next mount may restore a partially rewritten temporary file under the non-temporary (final) name (after the rename operation). Some file systems perform an implicit fsync before renaming a file over another one, but XFS does not, for example. 2018-01-12 Florian Weimer [BZ #20890] * elf/cache.c (save_cache): Call fsync on temporary file before renaming it. (save_aux_cache): Likewise. Reviewed-by: Adhemerval Zanella diff --git a/elf/cache.c b/elf/cache.c index 1ec6ab36e7..2165f8d305 100644 --- a/elf/cache.c +++ b/elf/cache.c @@ -449,7 +449,8 @@ save_cache (const char *cache_name) } if (write (fd, strings, total_strlen) != (ssize_t) total_strlen - || close (fd)) + || fsync (fd) != 0 + || close (fd) != 0) error (EXIT_FAILURE, errno, _("Writing of cache data failed")); /* Make sure user can always read cache file */ @@ -812,7 +813,8 @@ save_aux_cache (const char *aux_cache_name) if (write (fd, file_entries, file_entries_size + total_strlen) != (ssize_t) (file_entries_size + total_strlen) - || close (fd)) + || fsync (fd) != 0 + || close (fd) != 0) { unlink (temp_name); goto out_fail;