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: 25363 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. 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;