From patchwork Tue Oct 19 17:24:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 46406 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F2E43857C6E for ; Tue, 19 Oct 2021 17:25:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 731C53858D39 for ; Tue, 19 Oct 2021 17:24:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 731C53858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: FxCxEYbMFLoCh751Ry+MskrnLjpkm+/kxecyOqcvG9F+k4+SY76ljXzfoHQ1L0vo4JOnYgsFeC afJ7dAXp6jUHZHnbGmpZCl6ic62H+eVqXwabvuCNt7ZK9o3NFcAhgvA41kKTJksgUciFzQLinN rCpdFPVtjgEC0PXMxlV+nIieQnFhGxETYPAQyLw/+07NHGYicFSmjms13QO7L8w0A0rZedJFUN aE55295dp8aaDlFxF8zcE15nCayMUbu2t3b8yfWoFQHKxflWzHR28uaj3SWPpEeeBND+DrfS9Q 3INbRZKo0sdkBdZYn47M+dK3 X-IronPort-AV: E=Sophos;i="5.87,164,1631606400"; d="scan'208";a="69849150" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Oct 2021 09:24:53 -0800 IronPort-SDR: vpHoOhwkOXIT8EErNeJHzVS7GF++OyiW7MJ5+pdnZf+fk9H/jpegbm87gy55F8OC1sa0V3UEum HtA8yavUugulrIBz2Ad/qDTvlVMTHk/i4anO8D4Y6KUpOPYizRzd+F2KhZol4fkXU47NUsY37A 64R7Ix8DDamjgnOlX580DyVlVSmdnIz0R0fowDaoTEXWxV/besfC8qgLQQW93mfpab+6mDEXXF 47Fi3sGhjhPXDYtjyQYL8mVYQ8Sw77Jzzc2XxnjT1Nj61/QrzUfynJxuY3DbSh0UPjb2NDQbQC Kco= Date: Tue, 19 Oct 2021 17:24:48 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Correct access attribute on memfrob (bug 28475) Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3123.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" As noted in bug 28475, the access attribute on memfrob in is incorrect: the function both reads and writes the memory pointed to by its argument, so it needs to use __read_write__, not __write_only__. This incorrect attribute results in a build failure for accessing uninitialized memory for s390x-linux-gnu-O3 with build-many-glibcs.py using GCC mainline. Correct the attribute. Fixing this shows up that some calls to memfrob in elf/ tests are reading uninitialized memory; I'm not entirely sure of the purpose of those calls, but guess they are about ensuring that the stack space is indeed allocated at that point in the function, and so it matters that they are calling a function whose semantics are unknown to the compiler. Thus, add a memset call before the memfrob call in those tests to avoid the use of uninitialized memory. Tested for x86_64, and with build-many-glibcs.py (GCC mainline) for s390x-linux-gnu-O3. diff --git a/elf/tst-execstack-needed.c b/elf/tst-execstack-needed.c index 8b794a3d47..a42597a4c1 100644 --- a/elf/tst-execstack-needed.c +++ b/elf/tst-execstack-needed.c @@ -26,6 +26,7 @@ static void deeper (void (*f) (void)) { char stack[1100 * 1024]; + memset (stack, 123, sizeof stack); memfrob (stack, sizeof stack); (*f) (); memfrob (stack, sizeof stack); diff --git a/elf/tst-execstack-prog.c b/elf/tst-execstack-prog.c index 8663153372..40d4d00858 100644 --- a/elf/tst-execstack-prog.c +++ b/elf/tst-execstack-prog.c @@ -25,6 +25,7 @@ static void deeper (void (*f) (void)) { char stack[1100 * 1024]; + memset (stack, 123, sizeof stack); memfrob (stack, sizeof stack); (*f) (); memfrob (stack, sizeof stack); diff --git a/elf/tst-execstack.c b/elf/tst-execstack.c index 114f341d76..f9a6509be0 100644 --- a/elf/tst-execstack.c +++ b/elf/tst-execstack.c @@ -227,6 +227,7 @@ static void deeper (void (*f) (void)) { char stack[1100 * 1024]; + memset (stack, 123, sizeof stack); memfrob (stack, sizeof stack); (*f) (); memfrob (stack, sizeof stack); diff --git a/string/string.h b/string/string.h index 04e1b7067d..201d7e31c8 100644 --- a/string/string.h +++ b/string/string.h @@ -495,7 +495,7 @@ extern char *strfry (char *__string) __THROW __nonnull ((1)); /* Frobnicate N bytes of S. */ extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1)) - __attr_access ((__write_only__, 1, 2)); + __attr_access ((__read_write__, 1, 2)); # ifndef basename /* Return the file name within directory of FILENAME. We don't