diff options
author | Emmanuele Bassi <ebassi@gmail.com> | 2021-04-17 23:46:38 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2021-04-17 23:46:38 +0000 |
commit | dbe4543969115223b9bc6eb64aea96c8b295abcc (patch) | |
tree | 849b2968ff098197938b3bff5a0cd8e75cbda201 | |
parent | 1530c90e3742b7517d30475f5ad58bd82136e545 (diff) | |
parent | b27ec5ebde495e3d83d63a87a32d136c5f22fa37 (diff) | |
download | gtk+-dbe4543969115223b9bc6eb64aea96c8b295abcc.tar.gz |
Merge branch 'gtksecurememory-updates' into 'master'
gtksecurememory: Request that secure memory not be dumped to disk
See merge request GNOME/gtk!3452
-rw-r--r-- | config.h.meson | 3 | ||||
-rw-r--r-- | gtk/gtksecurememory.c | 13 | ||||
-rw-r--r-- | meson.build | 5 |
3 files changed, 20 insertions, 1 deletions
diff --git a/config.h.meson b/config.h.meson index fc2dd0b3d2..bc1d778f2c 100644 --- a/config.h.meson +++ b/config.h.meson @@ -76,6 +76,9 @@ /* Define to 1 if you have a working `mmap' system call. */ #mesondefine HAVE_MMAP +/* Define to 1 if you have a working `madvise' system call. */ +#mesondefine HAVE_MADVISE + /* Define to 1 if you have the `posix_fallocate' function. */ #mesondefine HAVE_POSIX_FALLOCATE diff --git a/gtk/gtksecurememory.c b/gtk/gtksecurememory.c index 35a6f6b875..a7aa34c447 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(HAVE_MADVISE) && 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; diff --git a/meson.build b/meson.build index eb012b549e..35803e6161 100644 --- a/meson.build +++ b/meson.build @@ -220,10 +220,13 @@ if cc.compiles(uint128_t_src, name : '__uint128_t available') cdata.set('HAVE_UINT128_T', 1) endif -# Check for mlock +# Check for mlock and madvise if cc.has_function('mlock', prefix: '#include <sys/mman.h>') cdata.set('HAVE_MLOCK', 1) endif +if cc.has_function('madvise', prefix: '#include <sys/mman.h>') + cdata.set('HAVE_MADVISE', 1) +endif # Disable deprecation checks for all libraries we depend on on stable branches. # This is so newer versions of those libraries don't cause more warnings with |