From patchwork Thu May 16 21:49:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 1100743 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-102072-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="m49LycZV"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dQLKlU7E"; 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 454lSW4KByz9s4Y for ; Fri, 17 May 2019 07:49:31 +1000 (AEST) 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:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=ERVFJn48DRXZsf93T3sJckudWlqFgypDGQ5o5uIsiq+Xj3mzDAect M5sco1sZK54bv0QTHe4d7xsA1EKx3cv2AE0thHNoSyXMEVKMtKJbXJOXv2nrbJny fe0QBPM8QhWwIrQ9t+Zuigx4U4Kqe6HcXCk3wXDbnoOSZ9luYVjNyA= 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:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=oBrINYfTGksSJStRAVaAig3jJZE=; b=m49LycZVJY6ZcRxuCL4z6NBg6JLK 3hvIizf+DwwJpDoHsSSiCn/47HGPIvep+UAjpS86NDv71SkNmOI9Mw1oRzzGFyVr fQL1jtoIR72oeUqCMUcCd3fgbe3axg4PYmRfMRwBFN3p1ZqRzcWoL5+1EHYODlUa zniu2RUX8MWxO4I= Received: (qmail 76568 invoked by alias); 16 May 2019 21:49:25 -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 76464 invoked by uid 89); 16 May 2019 21:49:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wr1-f65.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8v/YwJnEVOII7AOIzvfKqVirj1sYdKRFfjMKqtrPY3A=; b=dQLKlU7EhMFai1JXN81VwrUZv//5L8UX8T1AQGSRqd5HCTqGNW3R2iR5kJvzrLq59z HB/61HKPh5DPMru6j0P54QfX3+A99vr7sOFqilmoYo89cr0gDr3olV7dpGgZQbOhtnX7 ESr/6MxV/LgEqgX3CvuwFhsNCK52IOgK6012cvW0U99E/oUCV9NjzgEZncj7dQ7/zSre 9LMQboCWS486yEFBuR2N5ULyXEqjq1KNiIHvmBaKn6V4gRjopXoEgx8SFkeboUfZINf7 5awsCN/TY4IsXehNwxzaNhWmw3d5f/VyN/Pr3fgsKM73paNBkBKRmmHzTy+gP+ytRiV5 5E3g== From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: libc-alpha@sourceware.org, mcermak@redhat.com Cc: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Subject: [PATCH v5] elf: Add tst-ldconfig-bad-aux-cache test [BZ #18093] Date: Thu, 16 May 2019 23:49:03 +0200 Message-Id: <20190516214903.11884-1-ahajkova@redhat.com> MIME-Version: 1.0 From: Alexandra Hájková This test corrupts /var/cache/ldconfig/aux-cache and executes ldconfig to check it will not segfault using the corrupted aux_cache. The test uses the test-in-container framework. Verified no regressions on x86_64. 2019-05-16 Alexandra Hajkova * elf/Makefile (test-container): Add tst-ldconfig-bad-aux-cache. * elf/tst-ldconfig-bad-aux-cache.c: New file. * elf/tst-ldconfig_aux-cache.root: New directory. * elf/tst-ldconfig-bad-aux-cache.root/postclean.req: New file v5 - don't use fixed buffer size --- elf/Makefile | 3 + elf/tst-ldconfig-bad-aux-cache.c | 124 ++++++++++++++++++ .../postclean.req | 0 3 files changed, 127 insertions(+) create mode 100644 elf/tst-ldconfig-bad-aux-cache.c create mode 100644 elf/tst-ldconfig-bad-aux-cache.root/postclean.req diff --git a/elf/Makefile b/elf/Makefile index 4895489208..08e2f999bf 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -156,6 +156,9 @@ tests-static-internal := tst-tls1-static tst-tls2-static \ CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o tst-tls1-static-non-pie-no-pie = yes +tests-container = \ + tst-ldconfig-bad-aux-cache + tests := tst-tls9 tst-leaks1 \ tst-array1 tst-array2 tst-array3 tst-array4 tst-array5 \ tst-auxv diff --git a/elf/tst-ldconfig-bad-aux-cache.c b/elf/tst-ldconfig-bad-aux-cache.c new file mode 100644 index 0000000000..00a3df320f --- /dev/null +++ b/elf/tst-ldconfig-bad-aux-cache.c @@ -0,0 +1,124 @@ +/* Test ldconfig does not segfault when aux-cache is corrupted (Bug 18093). + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +/* This test does the following: + Run ldconfig to create the caches. + Corrupt the caches. + Run ldconfig again. + At each step we verify that ldconfig does not crash. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +static int +display_info (const char *fpath, const struct stat *sb, + int tflag, struct FTW *ftwbuf) +{ + printf ("%-3s %2d %7jd %-40s %d %s\n", + (tflag == FTW_D) ? "d" : (tflag == FTW_DNR) ? "dnr" : + (tflag == FTW_DP) ? "dp" : (tflag == FTW_F) ? "f" : + (tflag == FTW_NS) ? "ns" : (tflag == FTW_SL) ? "sl" : + (tflag == FTW_SLN) ? "sln" : "???", + ftwbuf->level, (intmax_t) sb->st_size, + fpath, ftwbuf->base, fpath + ftwbuf->base); + /* To tell nftw to continue. */ + return 0; +} + +/* Run ldconfig with a corrupt aux-cache, in particular we test for size + truncation that might happen if a previous ldconfig run failed or if + there were storage or power issues while we were writing the file. + We want ldconfig not to crash, and it should be able to do so by + computing the expected size of the file (bug 18093). */ +static int +do_test (void) +{ + char *prog = xasprintf ("%s/ldconfig", support_install_rootsbindir); + char *const args[] = { prog, NULL }; + const char *path = "/var/cache/ldconfig/aux-cache"; + struct stat64 fs; + long int size, new_size, i; + int status; + pid_t pid; + + /* Create the needed directories. */ + xmkdirp ("/var/cache/ldconfig", 0777); + + pid = xfork (); + /* Run ldconfig fist to generate the aux-cache. */ + if (pid == 0) + { + execv (args[0], args); + _exit (1); + } + else + { + xwaitpid (pid, &status, 0); + if (!(WIFEXITED (status))) + FAIL_EXIT1 ("ldconfig was aborted"); + xstat (path, &fs); + + size = fs.st_size; + /* Run 3 tests, each truncating aux-cache shorter and shorter. */ + for (i = 3; i > 0; i--) + { + new_size = size * i / 4; + if (truncate (path, new_size)) + { + FAIL_EXIT1 ("truncation failed: %m"); + } + if (nftw (path, display_info, 1000, 0) == -1) + { + FAIL_EXIT1 ("nftw failed."); + } + + pid = xfork (); + /* Verify that ldconfig can run with a truncated + aux-cache and doesn't crash. */ + if (pid == 0) + { + execv (args[0], args); + _exit (1); + } + else + { + xwaitpid (pid, &status, 0); + if (!(WIFEXITED (status))) + FAIL_EXIT1 ("ldconfig exited with non-zero status"); + } + + } + } + + free (prog); + return 0; +} + +#include diff --git a/elf/tst-ldconfig-bad-aux-cache.root/postclean.req b/elf/tst-ldconfig-bad-aux-cache.root/postclean.req new file mode 100644 index 0000000000..e69de29bb2