From e9f581ba3182ba0eb9dd658fe9442aff2b2733a6 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Thu, 8 Nov 2012 03:17:41 +0000 Subject: [PATCH] Zero the newly allocated md(4) swap-backed page to prevent random kernel memory leakage to userspace. For the typical use, when a filesystem put on the md disk, the change only results in CPU and memory bandwidth spent to zero the page, since filsystems make sure that user never see unwritten content. But if md disk is used as raw device by userspace, the garbage is exposed. Reported by: Paul Schenkeveld MFC after: 2 weeks --- sys/dev/md/md.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index a86c26aa58f..443c127de75 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -677,6 +677,15 @@ mdstart_swap(struct md_s *sc, struct bio *bp) sched_unpin(); vm_page_wakeup(m); break; + } else if (rv == VM_PAGER_FAIL) { + /* + * Pager does not have the page. Zero + * the allocated page, and mark it as + * valid. Do not set dirty, the page + * can be recreated if thrown out. + */ + bzero((void *)sf_buf_kva(sf), PAGE_SIZE); + m->valid = VM_PAGE_BITS_ALL; } bcopy((void *)(sf_buf_kva(sf) + offs), p, len); cpu_flush_dcache(p, len);