summaryrefslogtreecommitdiff
path: root/sys/src/9/port/alloc.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2023-04-08 20:30:47 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2023-04-08 20:30:47 +0000
commit60b1a2f82dc96b254d6dec1bfd1c14ca056c21dd (patch)
tree1de5c2c26d7f7d0a0def0bbe4c11971a12735730 /sys/src/9/port/alloc.c
parentbd43bd6f1ae1b1ec7ee6873d9fd6766b049802e9 (diff)
kernel: Clear secrets on reboot
The idea is that when we reboot, we zero out memory written by processes that have the private flag set (such as factotum and keyfs), and also clear the secrmem pool, which contains TLS keys and the state of the random number generator. This is so the newly booted kernel or firmware will not find these secret keys in memory.
Diffstat (limited to 'sys/src/9/port/alloc.c')
-rw-r--r--sys/src/9/port/alloc.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/sys/src/9/port/alloc.c b/sys/src/9/port/alloc.c
index 6c3519fdf..70ea42a15 100644
--- a/sys/src/9/port/alloc.c
+++ b/sys/src/9/port/alloc.c
@@ -171,7 +171,7 @@ mallocsummary(void)
/* non tracing
*
enum {
- Npadlong = 0,
+ Npadlong = 0,
MallocOffset = 0,
ReallocOffset = 0,
};
@@ -180,7 +180,7 @@ enum {
/* tracing */
enum {
- Npadlong = 2,
+ Npadlong = 2,
MallocOffset = 0,
ReallocOffset = 1
};
@@ -228,12 +228,14 @@ mallocz(ulong size, int clr)
void *v;
v = poolalloc(mainmem, size+Npadlong*sizeof(ulong));
- if(Npadlong && v != nil){
+ if(v == nil)
+ return nil;
+ if(Npadlong){
v = (ulong*)v+Npadlong;
setmalloctag(v, getcallerpc(&size));
setrealloctag(v, 0);
}
- if(clr && v != nil)
+ if(clr)
memset(v, 0, size);
return v;
}
@@ -244,13 +246,14 @@ mallocalign(ulong size, ulong align, long offset, ulong span)
void *v;
v = poolallocalign(mainmem, size+Npadlong*sizeof(ulong), align, offset-Npadlong*sizeof(ulong), span);
- if(Npadlong && v != nil){
+ if(v == nil)
+ return nil;
+ if(Npadlong){
v = (ulong*)v+Npadlong;
setmalloctag(v, getcallerpc(&size));
setrealloctag(v, 0);
}
- if(v)
- memset(v, 0, size);
+ memset(v, 0, size);
return v;
}
@@ -268,10 +271,10 @@ realloc(void *v, ulong size)
if(v != nil)
v = (ulong*)v-Npadlong;
- if(Npadlong !=0 && size != 0)
+ if(Npadlong && size != 0)
size += Npadlong*sizeof(ulong);
-
- if(nv = poolrealloc(mainmem, v, size)){
+ nv = poolrealloc(mainmem, v, size);
+ if(nv != nil){
nv = (ulong*)nv+Npadlong;
setrealloctag(nv, getcallerpc(&v));
if(v == nil)