From patchwork Fri Jun 28 08:49:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1124050 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-103291-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="u3qP93DP"; 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 45Zr6Z5306z9s3C for ; Fri, 28 Jun 2019 18:49:26 +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:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=ozGBhrpK75xFijkP4IkHDK3VUR9BW AFk67/UObQPsIIGciUgdh9GCwGlKT/RFQK5gj0/fkFrqVGxwht1Jsd7UfN+kGiuK zUo6EPKZlmiPQfkzk1eeo3FtPhlXelS59d+ZqzQK4LlDAiMN4fPtHFOvkBk/h277 JaScGuUmtJfBkk= 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:subject:date:message-id:mime-version :content-type; s=default; bh=LSScySGGPOIkhEBwut1/M4xPrw4=; b=u3q P93DP3ZTpn7lbpYGgPrN3aM3DYwZ0Ip8zfzhwsuF+Qe3QjWMKBc3bCkX9M0o8edK DuxDuwjPdkE0Olmyc/MPOeGgGIbgm9GMRvZdmWWfOKv8ikGhXdt0Kftuu5thjoRW ULg81wfMzz0svFrfXEYlAJWnadSF9deuofcQJehU= Received: (qmail 95883 invoked by alias); 28 Jun 2019 08:49:20 -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 95703 invoked by uid 89); 28 Jun 2019 08:49:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] Linux: Use mmap instead of malloc in dirent/tst-getdents64 Date: Fri, 28 Jun 2019 10:49:16 +0200 Message-ID: <87a7e2p01f.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 malloc dirties the entire allocated memory region due to M_PERTURB in the test harness. 2019-06-28 Florian Weimer * sysdeps/unix/sysv/linux/tst-getdents64.c (large_buffer_checks): Use mmap instead of malloc. malloc with M_PERTURB writes to the entire allocated memory range. Reviewed-by: Adhemerval Zanella diff --git a/sysdeps/unix/sysv/linux/tst-getdents64.c b/sysdeps/unix/sysv/linux/tst-getdents64.c index 24e77e04d8..8a28e6c67c 100644 --- a/sysdeps/unix/sysv/linux/tst-getdents64.c +++ b/sysdeps/unix/sysv/linux/tst-getdents64.c @@ -27,6 +27,7 @@ #include #include #include +#include #include /* Called by large_buffer_checks below. */ @@ -53,8 +54,13 @@ large_buffer_checks (int fd) size_t large_buffer_size; if (!__builtin_add_overflow (UINT_MAX, 2, &large_buffer_size)) { - char *large_buffer = malloc (large_buffer_size); - if (large_buffer == NULL) + int flags = MAP_ANONYMOUS | MAP_PRIVATE; +#ifdef MAP_NORESERVE + flags |= MAP_NORESERVE; +#endif + void *large_buffer = mmap (NULL, large_buffer_size, + PROT_READ | PROT_WRITE, flags, -1, 0); + if (large_buffer == MAP_FAILED) printf ("warning: could not allocate %zu bytes of memory," " subtests skipped\n", large_buffer_size); else @@ -65,8 +71,8 @@ large_buffer_checks (int fd) large_buffer_check (fd, large_buffer, UINT_MAX); large_buffer_check (fd, large_buffer, (size_t) UINT_MAX + 1); large_buffer_check (fd, large_buffer, (size_t) UINT_MAX + 2); + xmunmap (large_buffer, large_buffer_size); } - free (large_buffer); } }