]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Correct access attribute on memfrob (bug 28475)
authorJoseph Myers <joseph@codesourcery.com>
Wed, 20 Oct 2021 13:38:50 +0000 (13:38 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Wed, 20 Oct 2021 13:38:50 +0000 (13:38 +0000)
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, change the first memfrob
call in those tests to use explicit_bzero instead, as suggested by
Florian in
<https://sourceware.org/pipermail/libc-alpha/2021-October/132119.html>,
to avoid the use of uninitialized memory.

Tested for x86_64, and with build-many-glibcs.py (GCC mainline) for
s390x-linux-gnu-O3.

elf/tst-execstack-needed.c
elf/tst-execstack-prog.c
elf/tst-execstack.c
string/string.h

index 8b794a3d474de25040d585fcd89cd3f4fd9256b5..85078e40efbdeafd56381f4c3ebe0e6b1d7a6cd9 100644 (file)
@@ -26,7 +26,7 @@ static void
 deeper (void (*f) (void))
 {
   char stack[1100 * 1024];
-  memfrob (stack, sizeof stack);
+  explicit_bzero (stack, sizeof stack);
   (*f) ();
   memfrob (stack, sizeof stack);
 }
index 86631533722a315b3ab1af954b4f56d6a196556b..1b34bb5597906868ae096472efecbfa38c9b2565 100644 (file)
@@ -25,7 +25,7 @@ static void
 deeper (void (*f) (void))
 {
   char stack[1100 * 1024];
-  memfrob (stack, sizeof stack);
+  explicit_bzero (stack, sizeof stack);
   (*f) ();
   memfrob (stack, sizeof stack);
 }
index 114f341d76cec77ca473b638d34f9f654b922dbc..7e898b4f58f94e3d7a30bffc51f3ce6453298707 100644 (file)
@@ -227,7 +227,7 @@ static void
 deeper (void (*f) (void))
 {
   char stack[1100 * 1024];
-  memfrob (stack, sizeof stack);
+  explicit_bzero (stack, sizeof stack);
   (*f) ();
   memfrob (stack, sizeof stack);
 }
index 8dcafb4ac495285316359a1b8f1e784521672a54..b1b083edce6d27543cfb87de41d8239ccb929da7 100644 (file)
@@ -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