summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Garrett <matthewgarrett@google.com>2019-04-19 13:08:32 -0700
committerJason Francis <jason@cycles.network>2021-04-17 19:29:42 -0400
commit6622ebb310c488a614627d56e931de802e2c3b55 (patch)
tree7491e40537929fdd094da9fcf037d40e49509b63
parent3ad56a762f42306e24f02337a38eebdfed636bc9 (diff)
downloadgtk+-6622ebb310c488a614627d56e931de802e2c3b55.tar.gz
gtksecurememory: Request that secure memory not be dumped to disk
Linux 3.4 added support for the MADV_DONTDUMP option to madvise(), which requests that the covered memory not be included in coredumps. It makes sense to use this to prevent cases where application crashes could result in secrets being persisted to disk or included in dumps that are uploaded to remote servers for analysis. I've avoided making this fatal since there's a chance this code could be built on systems that have MADV_DONTDUMP but run on systems that don't.
-rw-r--r--gtk/gtksecurememory.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gtk/gtksecurememory.c b/gtk/gtksecurememory.c
index 35a6f6b875..6dff307e65 100644
--- a/gtk/gtksecurememory.c
+++ b/gtk/gtksecurememory.c
@@ -943,6 +943,19 @@ sec_acquire_pages (size_t *sz,
DEBUG_ALLOC ("gtk-secure-memory: new block ", *sz);
+#if defined(MADV_DONTDUMP)
+ if (madvise (pages, *sz, MADV_DONTDUMP) < 0) {
+ if (show_warning && gtk_secure_warnings) {
+ /*
+ * Not fatal - this was added in Linux 3.4 and older
+ * kernels will legitimately fail this at runtime
+ */
+ fprintf (stderr, "couldn't MADV_DONTDUMP %lu bytes of memory (%s): %s\n",
+ (unsigned long)*sz, during_tag, strerror (errno));
+ }
+ }
+#endif
+
show_warning = 1;
return pages;