Re: [PATCH] mm: Allow userland to request that the kernel clear memory on release

From: Matthew Wilcox
Date: Wed Apr 24 2019 - 15:28:15 EST

On Wed, Apr 24, 2019 at 12:14:40PM -0700, Matthew Garrett wrote:
> Unfortunately, if an application exits uncleanly, its secrets may still be
> present in RAM. This can't be easily fixed in userland (eg, if the OOM
> killer decides to kill a process holding secrets, we're not going to be able
> to avoid that), so this patch adds a new flag to madvise() to allow userland
> to request that the kernel clear the covered pages whenever the page
> reference count hits zero. Since vm_flags is already full on 32-bit, it
> will only work on 64-bit systems.

Your request seems reasonable to me.

> +++ b/include/linux/page-flags.h
> @@ -118,6 +118,7 @@ enum pageflags {
> PG_reclaim, /* To be reclaimed asap */
> PG_swapbacked, /* Page is backed by RAM/swap */
> PG_unevictable, /* Page is "unevictable" */
> + PG_wipeonrelease,

But you can't have a new PageFlag. Can you instead zero the memory in
unmap_single_vma() where we call uprobe_munmap() and untrack_pfn() today?