public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix FORTIFY_SOURCE false positive
@ 2023-10-02 15:53 Volker Weißmann
  2023-10-02 18:00 ` Siddhesh Poyarekar
  0 siblings, 1 reply; 6+ messages in thread
From: Volker Weißmann @ 2023-10-02 15:53 UTC (permalink / raw)
  To: libc-alpha; +Cc: Volker Weißmann

When -D_FORTIFY_SOURCE=2 was given during compilation,
sprintf and similar functions will check if their
first argument is in read-only memory and exit with
*** %n in writable segment detected ***
otherwise. To check if the memory is read-only, glibc
reads form the file "/proc/self/maps". If opening this
file fails due to too many open files (EMFILE), glibc
will now ignore this error.
---
 sysdeps/unix/sysv/linux/readonly-area.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/sysdeps/unix/sysv/linux/readonly-area.c b/sysdeps/unix/sysv/linux/readonly-area.c
index edc68873f6..629163461a 100644
--- a/sysdeps/unix/sysv/linux/readonly-area.c
+++ b/sysdeps/unix/sysv/linux/readonly-area.c
@@ -42,7 +42,15 @@ __readonly_area (const char *ptr, size_t size)
 	     to the /proc filesystem if it is set[ug]id.  There has
 	     been no willingness to change this in the kernel so
 	     far.  */
-	  || errno == EACCES)
+	  || errno == EACCES
+          /* Example code to trigger EMFILE:
+          while(1) {
+            FILE *file = fopen("/dev/zero", "r");
+            assert(file != NULL);
+          }
+          If your libc was compiled with -D_FORTIFY_SOURCE=2, we run
+          into this if clause here. */
+          || errno == EMFILE)
 	return 1;
       return -1;
     }
--
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-03 16:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-02 15:53 [PATCH] Fix FORTIFY_SOURCE false positive Volker Weißmann
2023-10-02 18:00 ` Siddhesh Poyarekar
2023-10-02 18:12   ` Adhemerval Zanella Netto
2023-10-02 18:20     ` Siddhesh Poyarekar
2023-10-03 13:22   ` Volker Weißmann
2023-10-03 16:47     ` Siddhesh Poyarekar

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).