public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: <libc-alpha@sourceware.org>
Subject: Correct access attribute on memfrob (bug 28475)
Date: Tue, 19 Oct 2021 17:24:48 +0000	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2110191724140.10354@digraph.polyomino.org.uk> (raw)

As noted in bug 28475, the access attribute on memfrob in <string.h>
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

-- 
Joseph S. Myers
joseph@codesourcery.com

             reply	other threads:[~2021-10-19 17:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 17:24 Joseph Myers [this message]
2021-10-19 19:48 ` Florian Weimer
2021-10-19 20:56   ` [PATCH v2] " Joseph Myers
2021-10-20  7:33     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.22.394.2110191724140.10354@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).