summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2019-03-01 01:46:19 +0000
committercheloha <cheloha@cvs.openbsd.org>2019-03-01 01:46:19 +0000
commit80cad7565b9d3cc50a9b929d69accb0dd87aa21b (patch)
tree1c9f1831bab930ca0ce7cfeac586e16c8c549d52 /sys
parent303ee37d16acf9d12fc5477975e7fd1144458f2f (diff)
New mmap(2) flag: MAP_CONCEAL.
MAP_CONCEAL'd memory is not written to disk in the event of a core dump. It may grow other qualities in the future. Wanted by libressl, probably useful elsewhere, too. Prompted by deraadt@, concept from deraadt@/kettenis@. With input from deraadt@, cjeker@, kettenis@, otto@, bcook@, matthew@, guenther@, djm@, and tedu@. ok otto@ deraadt@
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/mman.h5
-rw-r--r--sys/uvm/uvm.h4
-rw-r--r--sys/uvm/uvm_extern.h5
-rw-r--r--sys/uvm/uvm_map.c6
-rw-r--r--sys/uvm/uvm_mmap.c7
-rw-r--r--sys/uvm/uvm_unix.c6
6 files changed, 24 insertions, 9 deletions
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
index a75b2069ba5..47972b5ea88 100644
--- a/sys/sys/mman.h
+++ b/sys/sys/mman.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mman.h,v 1.33 2019/01/11 18:46:30 deraadt Exp $ */
+/* $OpenBSD: mman.h,v 1.34 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */
/*-
@@ -60,8 +60,9 @@
#define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */
#define __MAP_NOFAULT 0x2000
#define MAP_STACK 0x4000 /* mapping is used for a stack */
+#define MAP_CONCEAL 0x8000 /* omit from dumps */
-#define MAP_FLAGMASK 0x7ff7
+#define MAP_FLAGMASK 0xfff7
#ifndef _KERNEL
/*
diff --git a/sys/uvm/uvm.h b/sys/uvm/uvm.h
index 7a93862dd97..c895eb5ea1d 100644
--- a/sys/uvm/uvm.h
+++ b/sys/uvm/uvm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm.h,v 1.63 2018/10/31 08:50:25 kettenis Exp $ */
+/* $OpenBSD: uvm.h,v 1.64 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: uvm.h,v 1.24 2000/11/27 08:40:02 chs Exp $ */
/*
@@ -90,6 +90,7 @@ struct uvm {
#define UVM_ET_NOFAULT 0x0020 /* don't fault */
#define UVM_ET_STACK 0x0040 /* this is a stack */
#define UVM_ET_WC 0x0080 /* write combining */
+#define UVM_ET_CONCEAL 0x0100 /* omit from dumps */
#define UVM_ET_FREEMAPPED 0x8000 /* map entry is on free list (DEBUG) */
#define UVM_ET_ISOBJ(E) (((E)->etype & UVM_ET_OBJ) != 0)
@@ -100,6 +101,7 @@ struct uvm {
#define UVM_ET_ISNOFAULT(E) (((E)->etype & UVM_ET_NOFAULT) != 0)
#define UVM_ET_ISSTACK(E) (((E)->etype & UVM_ET_STACK) != 0)
#define UVM_ET_ISWC(E) (((E)->etype & UVM_ET_WC) != 0)
+#define UVM_ET_ISCONCEAL(E) (((E)->etype & UVM_ET_CONCEAL) != 0)
#ifdef _KERNEL
diff --git a/sys/uvm/uvm_extern.h b/sys/uvm/uvm_extern.h
index a473f251229..24ddcd98ccd 100644
--- a/sys/uvm/uvm_extern.h
+++ b/sys/uvm/uvm_extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_extern.h,v 1.144 2018/10/31 08:50:25 kettenis Exp $ */
+/* $OpenBSD: uvm_extern.h,v 1.145 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: uvm_extern.h,v 1.57 2001/03/09 01:02:12 chs Exp $ */
/*
@@ -112,7 +112,8 @@ typedef int vm_prot_t;
#define UVM_FLAG_NOFAULT 0x0800000 /* don't fault */
#define UVM_FLAG_UNMAP 0x1000000 /* unmap to make space */
#define UVM_FLAG_STACK 0x2000000 /* page may contain a stack */
-#define UVM_FLAG_WC 0x4000000 /* write combining */
+#define UVM_FLAG_WC 0x4000000 /* write combining */
+#define UVM_FLAG_CONCEAL 0x8000000 /* omit from dumps */
/* macros to extract info */
#define UVM_PROTECTION(X) ((X) & PROT_MASK)
diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c
index fcb6e16b43f..ac9309edc89 100644
--- a/sys/uvm/uvm_map.c
+++ b/sys/uvm/uvm_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_map.c,v 1.241 2019/02/15 16:46:59 deraadt Exp $ */
+/* $OpenBSD: uvm_map.c,v 1.242 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */
/*
@@ -1081,6 +1081,8 @@ uvm_mapanon(struct vm_map *map, vaddr_t *addr, vsize_t sz,
if ((flags & UVM_FLAG_OVERLAY) == 0)
entry->etype |= UVM_ET_NEEDSCOPY;
}
+ if (flags & UVM_FLAG_CONCEAL)
+ entry->etype |= UVM_ET_CONCEAL;
if (flags & UVM_FLAG_OVERLAY) {
KERNEL_LOCK();
entry->aref.ar_pageoff = 0;
@@ -1350,6 +1352,8 @@ uvm_map(struct vm_map *map, vaddr_t *addr, vsize_t sz,
if ((flags & UVM_FLAG_OVERLAY) == 0)
entry->etype |= UVM_ET_NEEDSCOPY;
}
+ if (flags & UVM_FLAG_CONCEAL)
+ entry->etype |= UVM_ET_CONCEAL;
if (flags & UVM_FLAG_OVERLAY) {
entry->aref.ar_pageoff = 0;
entry->aref.ar_amap = amap_alloc(sz, M_WAITOK, 0);
diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c
index 48d23f3880c..b667730e388 100644
--- a/sys/uvm/uvm_mmap.c
+++ b/sys/uvm/uvm_mmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_mmap.c,v 1.153 2019/01/11 18:46:30 deraadt Exp $ */
+/* $OpenBSD: uvm_mmap.c,v 1.154 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */
/*
@@ -284,7 +284,6 @@ sys_mmap(struct proc *p, void *v, register_t *retval)
return (EINVAL);
if (vm_min_address > 0 && addr < vm_min_address)
return (EINVAL);
-
}
/* check for file mappings (i.e. not anonymous) and verify file. */
@@ -911,6 +910,8 @@ uvm_mmapanon(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot,
uvmflag |= UVM_FLAG_OVERLAY;
if (flags & MAP_STACK)
uvmflag |= UVM_FLAG_STACK;
+ if (flags & MAP_CONCEAL)
+ uvmflag |= UVM_FLAG_CONCEAL;
/* set up mapping flags */
uvmflag = UVM_MAPFLAG(prot, maxprot,
@@ -1019,6 +1020,8 @@ uvm_mmapfile(vm_map_t map, vaddr_t *addr, vsize_t size, vm_prot_t prot,
uvmflag |= (UVM_FLAG_NOFAULT | UVM_FLAG_OVERLAY);
if (flags & MAP_STACK)
uvmflag |= UVM_FLAG_STACK;
+ if (flags & MAP_CONCEAL)
+ uvmflag |= UVM_FLAG_CONCEAL;
/* set up mapping flags */
uvmflag = UVM_MAPFLAG(prot, maxprot,
diff --git a/sys/uvm/uvm_unix.c b/sys/uvm/uvm_unix.c
index 0a6c89c5390..4618ce03559 100644
--- a/sys/uvm/uvm_unix.c
+++ b/sys/uvm/uvm_unix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_unix.c,v 1.64 2017/03/09 20:27:41 guenther Exp $ */
+/* $OpenBSD: uvm_unix.c,v 1.65 2019/03/01 01:46:18 cheloha Exp $ */
/* $NetBSD: uvm_unix.c,v 1.18 2000/09/13 15:00:25 thorpej Exp $ */
/*
@@ -227,6 +227,10 @@ uvm_should_coredump(struct proc *p, struct vm_map_entry *entry)
if ((entry->protection & PROT_READ) == 0)
return 0;
+ /* Skip ranges excluded from coredumps. */
+ if (UVM_ET_ISCONCEAL(entry))
+ return 0;
+
/* Don't dump mmaped devices. */
if (entry->object.uvm_obj != NULL &&
UVM_OBJ_IS_DEVICE(entry->object.uvm_obj))